Ketan Dubey
Ketan Dubey

Reputation: 430

How to convert and save a Print Document to a PDF

I have a Print Document called Report, which I'm generating in my code behind (C#) and printing it, in my WPF application.

Now I would want to save this Report as a PDF for future printing or any other use.

I've read about PDFSharp and XPS, but unsure, if they will help here, as my document is printed directly, and not being saved as a XPS. How do I achieve this?

Upvotes: 0

Views: 2215

Answers (1)

Joris Schellekens
Joris Schellekens

Reputation: 9057

Have a look at iText7. It's a powerful suite for generating, editing and working with pdf documents.

You can easily generate documents using iText. I'll show an example in java, but the c# code is exactly the same (aside from system IO).

File outputFile = new File("output.pdf");
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outputFile));
Document layoutDocument = new Document(pdfDocument);

layoutDocument.add(new Paragraph("Lorem Ipsum Dolor Sit Amet"));

layoutDocument.close();
pdfDocument.close();

Check out other tutorials on the website http://developers.itextpdf.com/examples-itext7

Upvotes: 1

Related Questions