ABCPdf - Image not a suitable format
In the end, my goal is to send a raw image data from the front-end, then split that image into however many pages, and lastly send that pdf back to the front-end for download.
But every time I use the theDoc.addImageFile(), it tells me that the "Image is not in a suitable format". I'm using this as reference: https://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/addimagefile.htm
To troubleshoot, I thought that the image might not be rendering correctly, so I added a File.WriteAllBytes to view the rendered image and it was exactly what I wanted, but still not adding to the PDF. I also tried sending the actual path of a previously rendered image thinking that the new image might not have been fully created yet, but it also gave me the same error. Lastly, I thought PNGs might be problematic and changed to JPG but it did not work.
Here is the code:
[HttpPost]
public IActionResult PrintToPDF(string imageString)
{
// Converts dataUri to bytes
var base64Data = Regex.Match(imageString, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;
var binData = Convert.FromBase64String(base64Data);
/* Ultimately will be removed, but used for debugging image */
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string imgName= "Test.jpg";
string filename = Path.Combine(path, imgName);
System.IO.File.WriteAllBytes(filename, binData);
/***********************************************************/
using (Doc theDoc = new Doc())
{
// Using explicit path
theDoc.AddImageFile(@"C:UsersUserDocumentsTest.jpg", 1);
// Using variable
//theDoc.AddImageFile(filename, 1);
// What I really want
//theDoc.AddImageFile(binData , 1);
theDoc.Page = theDoc.AddPage();
theDoc.AddText("Thanks");
Response.Headers.Clear();
Response.Headers.Add("content-disposition", "attachment; filename=test.pdf");
return new FileStreamResult(theDoc.GetStream(), "application/pdf");
}
}
image asp.net-core abcpdf
add a comment |
In the end, my goal is to send a raw image data from the front-end, then split that image into however many pages, and lastly send that pdf back to the front-end for download.
But every time I use the theDoc.addImageFile(), it tells me that the "Image is not in a suitable format". I'm using this as reference: https://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/addimagefile.htm
To troubleshoot, I thought that the image might not be rendering correctly, so I added a File.WriteAllBytes to view the rendered image and it was exactly what I wanted, but still not adding to the PDF. I also tried sending the actual path of a previously rendered image thinking that the new image might not have been fully created yet, but it also gave me the same error. Lastly, I thought PNGs might be problematic and changed to JPG but it did not work.
Here is the code:
[HttpPost]
public IActionResult PrintToPDF(string imageString)
{
// Converts dataUri to bytes
var base64Data = Regex.Match(imageString, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;
var binData = Convert.FromBase64String(base64Data);
/* Ultimately will be removed, but used for debugging image */
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string imgName= "Test.jpg";
string filename = Path.Combine(path, imgName);
System.IO.File.WriteAllBytes(filename, binData);
/***********************************************************/
using (Doc theDoc = new Doc())
{
// Using explicit path
theDoc.AddImageFile(@"C:UsersUserDocumentsTest.jpg", 1);
// Using variable
//theDoc.AddImageFile(filename, 1);
// What I really want
//theDoc.AddImageFile(binData , 1);
theDoc.Page = theDoc.AddPage();
theDoc.AddText("Thanks");
Response.Headers.Clear();
Response.Headers.Add("content-disposition", "attachment; filename=test.pdf");
return new FileStreamResult(theDoc.GetStream(), "application/pdf");
}
}
image asp.net-core abcpdf
What version of ABCpdf are you using?
– PGTips
Dec 4 '18 at 11:05
@PGTips we've since been using DinkToPDF to render PDFs but looking at my commits, we were using ABCpdfCORE Ver. 11.2.3
– Paul_LayLow
Dec 4 '18 at 14:56
add a comment |
In the end, my goal is to send a raw image data from the front-end, then split that image into however many pages, and lastly send that pdf back to the front-end for download.
But every time I use the theDoc.addImageFile(), it tells me that the "Image is not in a suitable format". I'm using this as reference: https://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/addimagefile.htm
To troubleshoot, I thought that the image might not be rendering correctly, so I added a File.WriteAllBytes to view the rendered image and it was exactly what I wanted, but still not adding to the PDF. I also tried sending the actual path of a previously rendered image thinking that the new image might not have been fully created yet, but it also gave me the same error. Lastly, I thought PNGs might be problematic and changed to JPG but it did not work.
Here is the code:
[HttpPost]
public IActionResult PrintToPDF(string imageString)
{
// Converts dataUri to bytes
var base64Data = Regex.Match(imageString, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;
var binData = Convert.FromBase64String(base64Data);
/* Ultimately will be removed, but used for debugging image */
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string imgName= "Test.jpg";
string filename = Path.Combine(path, imgName);
System.IO.File.WriteAllBytes(filename, binData);
/***********************************************************/
using (Doc theDoc = new Doc())
{
// Using explicit path
theDoc.AddImageFile(@"C:UsersUserDocumentsTest.jpg", 1);
// Using variable
//theDoc.AddImageFile(filename, 1);
// What I really want
//theDoc.AddImageFile(binData , 1);
theDoc.Page = theDoc.AddPage();
theDoc.AddText("Thanks");
Response.Headers.Clear();
Response.Headers.Add("content-disposition", "attachment; filename=test.pdf");
return new FileStreamResult(theDoc.GetStream(), "application/pdf");
}
}
image asp.net-core abcpdf
In the end, my goal is to send a raw image data from the front-end, then split that image into however many pages, and lastly send that pdf back to the front-end for download.
But every time I use the theDoc.addImageFile(), it tells me that the "Image is not in a suitable format". I'm using this as reference: https://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/addimagefile.htm
To troubleshoot, I thought that the image might not be rendering correctly, so I added a File.WriteAllBytes to view the rendered image and it was exactly what I wanted, but still not adding to the PDF. I also tried sending the actual path of a previously rendered image thinking that the new image might not have been fully created yet, but it also gave me the same error. Lastly, I thought PNGs might be problematic and changed to JPG but it did not work.
Here is the code:
[HttpPost]
public IActionResult PrintToPDF(string imageString)
{
// Converts dataUri to bytes
var base64Data = Regex.Match(imageString, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;
var binData = Convert.FromBase64String(base64Data);
/* Ultimately will be removed, but used for debugging image */
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string imgName= "Test.jpg";
string filename = Path.Combine(path, imgName);
System.IO.File.WriteAllBytes(filename, binData);
/***********************************************************/
using (Doc theDoc = new Doc())
{
// Using explicit path
theDoc.AddImageFile(@"C:UsersUserDocumentsTest.jpg", 1);
// Using variable
//theDoc.AddImageFile(filename, 1);
// What I really want
//theDoc.AddImageFile(binData , 1);
theDoc.Page = theDoc.AddPage();
theDoc.AddText("Thanks");
Response.Headers.Clear();
Response.Headers.Add("content-disposition", "attachment; filename=test.pdf");
return new FileStreamResult(theDoc.GetStream(), "application/pdf");
}
}
image asp.net-core abcpdf
image asp.net-core abcpdf
asked Nov 18 '18 at 19:43
Paul_LayLowPaul_LayLow
275
275
What version of ABCpdf are you using?
– PGTips
Dec 4 '18 at 11:05
@PGTips we've since been using DinkToPDF to render PDFs but looking at my commits, we were using ABCpdfCORE Ver. 11.2.3
– Paul_LayLow
Dec 4 '18 at 14:56
add a comment |
What version of ABCpdf are you using?
– PGTips
Dec 4 '18 at 11:05
@PGTips we've since been using DinkToPDF to render PDFs but looking at my commits, we were using ABCpdfCORE Ver. 11.2.3
– Paul_LayLow
Dec 4 '18 at 14:56
What version of ABCpdf are you using?
– PGTips
Dec 4 '18 at 11:05
What version of ABCpdf are you using?
– PGTips
Dec 4 '18 at 11:05
@PGTips we've since been using DinkToPDF to render PDFs but looking at my commits, we were using ABCpdfCORE Ver. 11.2.3
– Paul_LayLow
Dec 4 '18 at 14:56
@PGTips we've since been using DinkToPDF to render PDFs but looking at my commits, we were using ABCpdfCORE Ver. 11.2.3
– Paul_LayLow
Dec 4 '18 at 14:56
add a comment |
1 Answer
1
active
oldest
votes
Try something like this (not tested, but cleaned up from my own code):
public int AddImageFile(Doc doc, byte data, int insertBeforePageID)
{
int pageid;
using (var img = new XImage())
{
img.SetData(data);
doc.Page = doc.AddPage(insertBeforePageID);
pageid = doc.Page;
doc.AddImage(img);
img.Clear();
}
return pageid;
}
Wasn't able to test this since we opted for a different solution (DinkToPDF). I'll see if I can revert back to that branch sometime. But from what I've tried, wrapping the image into ausingblock is something I haven't tried so maybe this will work.
– Paul_LayLow
Dec 4 '18 at 14:39
I think the bigger thing is to use an XImage() to add it to the doc. I use this code to convert TIFF scans to PDFs.
– Moose
Dec 5 '18 at 15:49
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364777%2fabcpdf-image-not-a-suitable-format%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try something like this (not tested, but cleaned up from my own code):
public int AddImageFile(Doc doc, byte data, int insertBeforePageID)
{
int pageid;
using (var img = new XImage())
{
img.SetData(data);
doc.Page = doc.AddPage(insertBeforePageID);
pageid = doc.Page;
doc.AddImage(img);
img.Clear();
}
return pageid;
}
Wasn't able to test this since we opted for a different solution (DinkToPDF). I'll see if I can revert back to that branch sometime. But from what I've tried, wrapping the image into ausingblock is something I haven't tried so maybe this will work.
– Paul_LayLow
Dec 4 '18 at 14:39
I think the bigger thing is to use an XImage() to add it to the doc. I use this code to convert TIFF scans to PDFs.
– Moose
Dec 5 '18 at 15:49
add a comment |
Try something like this (not tested, but cleaned up from my own code):
public int AddImageFile(Doc doc, byte data, int insertBeforePageID)
{
int pageid;
using (var img = new XImage())
{
img.SetData(data);
doc.Page = doc.AddPage(insertBeforePageID);
pageid = doc.Page;
doc.AddImage(img);
img.Clear();
}
return pageid;
}
Wasn't able to test this since we opted for a different solution (DinkToPDF). I'll see if I can revert back to that branch sometime. But from what I've tried, wrapping the image into ausingblock is something I haven't tried so maybe this will work.
– Paul_LayLow
Dec 4 '18 at 14:39
I think the bigger thing is to use an XImage() to add it to the doc. I use this code to convert TIFF scans to PDFs.
– Moose
Dec 5 '18 at 15:49
add a comment |
Try something like this (not tested, but cleaned up from my own code):
public int AddImageFile(Doc doc, byte data, int insertBeforePageID)
{
int pageid;
using (var img = new XImage())
{
img.SetData(data);
doc.Page = doc.AddPage(insertBeforePageID);
pageid = doc.Page;
doc.AddImage(img);
img.Clear();
}
return pageid;
}
Try something like this (not tested, but cleaned up from my own code):
public int AddImageFile(Doc doc, byte data, int insertBeforePageID)
{
int pageid;
using (var img = new XImage())
{
img.SetData(data);
doc.Page = doc.AddPage(insertBeforePageID);
pageid = doc.Page;
doc.AddImage(img);
img.Clear();
}
return pageid;
}
answered Nov 30 '18 at 15:31
MooseMoose
4,58922845
4,58922845
Wasn't able to test this since we opted for a different solution (DinkToPDF). I'll see if I can revert back to that branch sometime. But from what I've tried, wrapping the image into ausingblock is something I haven't tried so maybe this will work.
– Paul_LayLow
Dec 4 '18 at 14:39
I think the bigger thing is to use an XImage() to add it to the doc. I use this code to convert TIFF scans to PDFs.
– Moose
Dec 5 '18 at 15:49
add a comment |
Wasn't able to test this since we opted for a different solution (DinkToPDF). I'll see if I can revert back to that branch sometime. But from what I've tried, wrapping the image into ausingblock is something I haven't tried so maybe this will work.
– Paul_LayLow
Dec 4 '18 at 14:39
I think the bigger thing is to use an XImage() to add it to the doc. I use this code to convert TIFF scans to PDFs.
– Moose
Dec 5 '18 at 15:49
Wasn't able to test this since we opted for a different solution (DinkToPDF). I'll see if I can revert back to that branch sometime. But from what I've tried, wrapping the image into a
using block is something I haven't tried so maybe this will work.– Paul_LayLow
Dec 4 '18 at 14:39
Wasn't able to test this since we opted for a different solution (DinkToPDF). I'll see if I can revert back to that branch sometime. But from what I've tried, wrapping the image into a
using block is something I haven't tried so maybe this will work.– Paul_LayLow
Dec 4 '18 at 14:39
I think the bigger thing is to use an XImage() to add it to the doc. I use this code to convert TIFF scans to PDFs.
– Moose
Dec 5 '18 at 15:49
I think the bigger thing is to use an XImage() to add it to the doc. I use this code to convert TIFF scans to PDFs.
– Moose
Dec 5 '18 at 15:49
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364777%2fabcpdf-image-not-a-suitable-format%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What version of ABCpdf are you using?
– PGTips
Dec 4 '18 at 11:05
@PGTips we've since been using DinkToPDF to render PDFs but looking at my commits, we were using ABCpdfCORE Ver. 11.2.3
– Paul_LayLow
Dec 4 '18 at 14:56