Drawing on PDF file C#

一世执手 提交于 2019-12-11 18:28:29

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/8388927/drawing-on-pdf-file-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!