'How to generate a PDF? [closed]
For my Microsoft Surface application I'd like to generate a PDF including some images. How should I start to do that?
EDIT: I don't want to convert a text or html document, but I want to create a pdf from scratch.
Solution 1:[1]
PDFsharp is nice, free, relatively easy to use and compatible with WPF
Solution 2:[2]
Two basic options:
- use a PDF specific library, like iText in @Kent's answer
- install a PDF printer and use any reporting/printing code.
Option 1) will be the most flexible and efficient way.
Option 2) is interesting when you already have code that prints what you want. It is a bit of a hassle to manage the output-file etc. It's very easy to support XPS as well.
Solution 3:[3]
Docotic.Pdf library may be used to create PDF files from scratch and many other purposes.
Please take a look at samples for various PDF tasks.
The library has no external dependencies and is written in C#. There are several different license types available.
Disclaimer: I work for Bit Miracle.
Solution 4:[4]
For me the easiest way is to use Reporting Services. http://www.microsoft.com/sqlserver/2008/en/us/reporting.aspx
Solution 5:[5]
You should also have a look at Fop/PdfBox for PDF creation/editing.
Solution 6:[6]
you need to use one of PDF generation libraries for C#. I tried to use iText , IronPDF and PDFFlow. All of them create PDF documents from scratch.
But PDFFlow was better for my needs, because it has easy fluent syntax and more functionality (I needed repeating headers, automatic page creation, automatic page numeration and multi-page spread table). They also have examples of business documents here: Examples, I haven't seen that much from other PDF generating libraries. There are also how-to-build articles for each sample, that helped me much.
This is how to create simple PDF file:
var DocumentBuilder.New()
.AddSection()
.AddParagraphToSection("Hello world!")
.AddImage("image.png").SetWidth(250)
.ToSection()
.AddLine(300, Color.Red)
.ToDocument()
.Build("Result.PDF");
Hope, this will help you to start.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | |
| Solution 3 | |
| Solution 4 | ykatchou |
| Solution 5 | mark stephens |
| Solution 6 | Mohammed El-Sharnouby |
