iTextSharp 4.1.6 display Image from Byte[] - c#

I am currently developing a web application where i have to generate a PDF with an image in it. I have to use iTextSharp 4.1.6 because it is the last LGPL version. The previous version of our app used v5.5.11.
The image is dynamically created at runtime as byte[]. This would work fine in iTextSharp 5.5.11. However, with 4.1.6 it doesn't display the image in the PDF file.
When i use a hardcoded path as image source instead of the byte[], it displays the image just like i want.
//This works
Image qrCode = Image.GetInstance(#"C:\Users\Me\Pictures\asdf.jpg");
//This doesn´t
Image qrCode = Image.GetInstance(QRGenerator.GenerateQRCode(ticketUrl));
Thank you in advance for your help.

Related

IText7 - IText7 is Not Properly Drawing SVG Documents

Project Information : .NETCore v3.1 - IText7 v7.1.11
We have a PDF Document builder library created by IText7 nuget package, where we can dynamically building large PDF files for our customers.
Normally we are working with .jpg format but a new feature is added to our online side which is we have started to work with also interactive SVG files with hotspots integrated to our UI.
So, when our application builds a PDF Document it also needs to import those SVG files, we can use it by:
var image = SvgConverter.ConvertToImage(
new FileStream(imagePath, FileMode.Open, FileAccess.Read), pdfDocument);
The Original File (I can't upload a SVG so I am uploading as jpg but this is not important because I just want to show the line thickness):
Output is shown below, as you can see on the left side the lines become very thick and parts are not shown as expected.
Steps:
SvgConverter.DrawOnCanvas(svgStream, pdfCanvas);
SvgConverter.DrawOnDocument(svgStream, pdfDocument);
SvgConverter.DrawOnPage(svgStream, pdfPage);
SvgConverter.ConvertToXObject(svgStream, pdfDocument);
SvgConverter.ConvertToImage(svgStream, pdfDocument);
I have tried them all but results are same for all.
Questions:
PDF and SVG files are vectors, so can't we use them as integrated through IText, why should we need to convert it to a Raster? Why do we need a converter?
Is there a way to decrease thickness or a way to not to lose image quality?
Thank you for your time!
When you invoke SvgConverter.ConvertToImage or SvgConverter.ConvertToXObject, your SVG is not converted into a raster image - it still remains a vector image. So you can use the integrated SVG converter workflow and you are in fact using it with the SvgConverter. The converter is needed to process SVG file format into more PDF-specific structures, so it performs some conversion because PDF does not support SVG directly. This is not vector -> raster conversion though.
Regarding the problem with the line thickness, first think you should do is to try with the latest version - as far as I see you are trying with 7.1.11 while it's dated back to around a year and 7.1.15 is out already. If the problem persists then it's a bug in the SVG support in iText and you can try to minimize the SVG file to see if there is a workaround to achieve proper conversion until the bug is fixed for your case and/or report the problem to iText (StackOverflow is not the right place to report bugs).

Is there a way to convert morris.js charts to image?

I have used morris.js charts. Now I want to be able to export all of my page HTML to PDF, which includes these morris.js charts. I am using iTextSharp for PDF export, but it does not recognize SVG elements.
SVG is not supported by iText 5.
SVG support is under development for iText 7. It will not be backported to iText 5.
Meanwhile you can use Batik to convert SVG to PNG, and then put the PNG image in your PDF. Awkward, I know, but it's your best option for now.

Crop PDF using iTextSharp

How can I crop a PDF using iTextsharp in C#?? How do I modify the CropBoxSize parameters to create a new cropped pdf file?
you can take a look at my project http://pdfebookcutter.codeplex.com/

Image Quirk with PDF generated by WKHtmlToPDF

Using WKHtmlToPDF to generate PDFs for my company's web-based mapping service.
Essentially, I take a template HTML file, inject an image into a div, save the HTML to disk and use WKHtmlToPDF to render to PDF.
Now, on most templates it works a treat. On one particular one though, where the image should be (int the pdf) is a grey area. HOWEVER, if I right click on the grey area, and select "Save Image As...", the saved image is correct.
Linked are the created PDF and the HTML on which it is based. Help required most urgently, and hints appreciated.
Zip File Containing HTML and PDF
I was having an issue where a particular image was not being printed to the PDF. Other images on the same page were. The src of the missing image is from a CDN, but had no extension, i.e. src="\\path/to/image?param". Using the aforementioned -n switch (disable Javascript), the image shows up in the resulting PDF. Thanks Jordaan.
Don't know WHY this worked, but adding the "--disable-smart-shrinking" option, and/or removing the "-n"(Disable Javascript) option, fixed it.

barcode in PDF to Code39 conversion in C#?

I have a PDF file which contains just 1 Page. I have a barcode at the end of the page.
How do I extract the barcode number from the PDF in C#
I have seen a post to convert barcode Image to Code 39 but how do we do it from PDF, Please help
barcode image to Code39 conversion in C#?
Thanks
Your best bet is to get a PDF library that can extract images from the pages. We use Aspose.PDF and Aspose.PDF.Kit, which are both excellent products.
http://www.aspose.com
This page shows a code example of how to extract an image from a PDF document:
http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/extract-image-from-pdf-document.html
They also have a Barcode library, and one of the things it can do is read barcodes from multi-page tiff images. You could convert the pages of your PDF to TIFF and then use the barcode library to read the barcodes:
http://www.aspose.com/documentation/.net-components/aspose.barcode-for-.net/how-to-read-barcode-from-multipage-tiff-images.html
You can use iTextSharp library to convert the PDF to an image and then a barcode reading library such as IBScanner to extract the barcode(s) from the image.

Categories

Resources