Active8 months ago
I would like to convert from an image (like jpg or png) to PDF. JPG to PDF Convertor in C#. Ask Question Asked 9 years, 11 months ago. Active 3 years ago. Viewed 54k times 19. I would like to convert from an image (like jpg or png) to PDF. I have used PDFSharp but the pdf is distort. However, we notice that the PdfSharp.Xps.XpsConverter.Convert from Xps to PDF, the images inside wpf control lost. Does anyone use PdfSharp library without losing image controls? Does anyone has idea how to export WPF control which includes images into PDF format?
How to export a PDF page as an image using PDFsharp .NET library, for pixel level manipulation?
For example, something like, System.Drawing.BitMap.GetPixel()
I am trying to find out empty area (all white, or of any colour) inside a PDF document, to write some graphics / image.
09, June 2010:
I have tried this, but it is not working.
Why the following code is not working as expected?
Bitmap.GetPixel always returns 0.
Vive la déraison16.3k22 gold badges5656 silver badges119119 bronze badges
vi.su.vi.su.30522 gold badges66 silver badges1919 bronze badges
1 Answer
The answer can be found in the PDFsharp FAQ list:http://www.pdfsharp.net/wiki/PDFsharpFAQ.ashx#Can_PDFsharp_show_PDF_files_Print_PDF_files_Create_images_from_PDF_files_3
PDFsharp creates PDF files, but it cannot render them.
The call
does not initialize any bits of the bitmap and does not copy anything from the Graphics object except for the DPI setting of the Graphics object. Graphics objects draw things, but they do not remember what they have drawn and they cannot re-create the drawings in a call to
new Bitmap(...)
. This does not work with the Graphics class from Microsoft, this does not work with the XGraphics class from PDFsharp either.The XGraphics class from PDFsharp can be used to draw on PDF pages and it can be used to draw on bitmaps, on a printer, or on the screen - it can draw on PDF pages and on any DC you can get from Windows. Same goes for MigraDoc.
So if you want to create PDF files and bitmaps with the same contents, PDFsharp and MigraDoc can help.
So if you want to create PDF files and bitmaps with the same contents, PDFsharp and MigraDoc can help.
But PDFsharp does not provide any way to render a PDF page to a bitmap.
Vive la déraisonVive la déraison16.3k22 gold badges5656 silver badges119119 bronze badges
Not the answer you're looking for? Browse other questions tagged .netimagepdfbitmappdfsharp or ask your own question.
Active3 years ago
I would like to convert from an image (like jpg or png) to PDF.
I've checked out ImageMagickNET, but it is far too complex for my needs.
What other .NET solutions or code are there for converting an image to a PDF?
p.campbell70.9k5656 gold badges226226 silver badges303303 bronze badges
CoppermillCoppermill3,1901313 gold badges5656 silver badges8989 bronze badges
7 Answers
iTextSharp does it pretty cleanly and is open source. Also, it has a very good accompanying book by the author which I recommend if you end up doing more interesting things like managing forms. For normal usage, there are plenty resources on mailing lists and newsgroups for samples of how to do common things.
EDIT: as alluded to in @Chirag's comment, @Darin's answer has code that definitely compiles with current versions.
Community♦
Ruben BartelinkRuben Bartelink46.3k1717 gold badges149149 silver badges206206 bronze badges
Darin DimitrovDarin Dimitrov879k233233 gold badges30763076 silver badges27922792 bronze badges
One we've had great luck with is PDFSharp (we use it for TIFF and Text to PDF conversion for hundreds of medical claims every day).
Bob PalmerBob Palmer4,22622 gold badges2323 silver badges3131 bronze badges
Such task can be easily done with help of Docotic.Pdf library.
Here is a sample that creates PDF from given images (not only JPGs, actually):
Disclaimer: I work for the vendor of the library.
BobrovskyBobrovsky9,0221818 gold badges6363 silver badges113113 bronze badges
not sure if you're looking for just free / open source solutions or considering commercial ones as well. But if you're including commercial solutions, there's a toolkit called EasyPDF SDK that offers an API for converting images (plus a number of other file types) to PDF. It supports C# and can be found here:
The C# code would look as follows:
To be fully transparent, I should disclaim that I do work for the makers of EasyPDF SDK (hence my handle), so this suggestion is not without some personal bias :) But feel free to check out the eval version if you're interested. Cheers!
![Pdfsharp convert pdf page to image Pdfsharp convert pdf page to image](https://i.stack.imgur.com/IUzGP.png)
yu-chen-pdfonline-comyu-chen-pdfonline-com
Many diff tools out there. One I use is PrimoPDF (FREE) http://www.primopdf.com/ you go to print the file and you print it to pdf format onto your drive. works on Windows
HarryHarry
protected by Bo PerssonAug 30 '11 at 20:11
Pdfsharp Convert Pdf Page To Image
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?