Drawing on PDF file C#

2019-09-08 23:28发布

I need to write a PDF file from my WPF app. I've seen some 3rd party libraries to create PDF files, but I couldn't find any that would allow me to write boxes, or any shape for the matter. Do I have to use some 2D library from .NET or is there any PDF library that provides that type of work?

This is what I need to draw:

I'll have a list of objects List<ObjX> list; that I'll use to fill each box. Think of it as a Personal Data list of all employees, for instance.

____________________________________
{header_img}

| Name: {name} | Surname: {surname}|

| Address : {address} | City: {cit}|
____________________________________

It's a very poor drawing, what I'll do is a bit more elaborated, including even images.

标签: c# wpf drawing
3条回答
仙女界的扛把子
2楼-- · 2019-09-08 23:43

You probably want iTextSharp

You can find lots of help on how to use it by searching StackOverflow. :)

This is an answer to drawing a rectangle: Draw a rectangle in an iText pdf

Edit

Also, a search on "drawing shapes iTextSharp" gave me this link which looks quite detailed. http://www.mikesdotnetting.com/Article/88/iTextSharp-Drawing-shapes-and-Graphics

You will need to watch out for differences in version, since 1.4 and 1.5 are quite different.

查看更多
等我变得足够好
3楼-- · 2019-09-08 23:48

For me the best solution is to use PdfSharp and Migradoc, http://www.pdfsharp.net/ It's free and allow you to do everything.

查看更多
放我归山
4楼-- · 2019-09-08 23:53

You may want to take the approach that I did which is to generate your document entirely in WPF and then simply convert it to a bitmap image (very easy in WPF) and then add that bitmap image to a PDF document using iTextSharp. See this post for more details.

The main advantage to this approach is that you get a PDF that looks exactly like your WPF output. Plus, it takes very little code to make it work.

查看更多
登录 后发表回答