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.
Related
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).
In my application, option is there to upload multiple attachments, that can be png, jpg, doc or .xlsx and its working fine using .Net MVC.
Now I want to merge all these attachments into a single PDF. Is that possible using .net MVC?
Yes, you can use: pdfsharp.
PDFsharp is a .NET library for processing PDF file. You create PDF pages using drawing routines known from GDI+. Almost anything that can be done with GDI+ will also work with PDFsharp. Only basic text layout is supported by PDFsharp, and page breaks are not created automatically. The same drawing routines can be used for screen, PDF, or meta files
I want to perform OCR on png and pdf files.I am able to get Tesseract 3.0.2 .net wrapper work for png files but I can't find any class in it for PDf files.So, does it work for the pdf files.If not then please let me know any other open source library for scanning pdfs. My requirement is scanning diagrams in a pdf for specific circles, and creating hyperlinks for those circles.
No, it doesn't. You'll have to extract the images from the pdf first. This can be done using pdfimages pdfimages.exe -j your.pdf or gs as suggested by Zakk Diaz.
I need to create a software which will create print previews of the documents of following formats: the MS Office documents (.doc(x), .ppt(x), .xls(x)), images, .txt files and PDF files. I have made a working prototype using XPS files. So basically I do the following: I convert the office files to .xps using Office Automation and then I render the .xps documents to images. I simply create XPS files from images and .txt by adding text or an image to FlowDocument, then rendering it. But I have found out that there is no way to convert PDF to XPS fast (A document which has 600 pages takes more than 2 minutes to convert and this is totally not suitable). So I am stuck at this point. It seems that I should start over again, using the different file format. Should I rewrite my program using PDF, for example, or is there any other way to accomplish my task? And if I should use PDF, could you, please, suggest me a good PDF C# library to render previews of pages as fast as possible? I tried using Websupergoo's ABCPdf, but it is too slow, because it does not allow me to render the previews to System.Windows.Media.Imaging.BitmapSource, only System.Drawing.Bitmap, so I have to convert Bitmap to BitmapSource and it takes up a lot of time.
Thanks in advance.
Use Ghostscipt to convert PDF to images. Though, I don't know why you wouldn't just use the PDF. I have used GhostScript for a number of PDF/Image manipulation tasks.
http://www.wibit.net/blog/integrating_ghostscript_c
Ghostscript will output any PDF to images to the settings you specify. I think you can use it as a DLL or as a commandline process.
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.