Posts tonen met het label PDF. Alle posts tonen
Posts tonen met het label PDF. Alle posts tonen

woensdag 20 januari 2010

Convert images to pdf

Using the Open Source library PDFsharp converting images to a PDF document becomes child's play. Just create the document, add a page, import an image and save the document to disk.

Plus PDFsharp comes with a license free of any restrictions so you can reuse it in any program for whatever purpose you like!

                OpenFileDialog openFile = new OpenFileDialog();
if (openFile.ShowDialog().Value)
{
PdfDocument pdfDoc = new PdfDocument();
pdfDoc.Pages.Add(new PdfPage());
XGraphics xGraphics = XGraphics.FromPdfPage(pdfDoc.Pages[0]);
XImage xImage = XImage.FromFile(openFile.FileName);

xGraphics.DrawImage(xImage, 0, 0);
pdfDoc.Save(@"C:\test.pdf");
pdfDoc.Close();
}