Hi everyone,
How do I create and read the pdf file using C# programmatically?
Hi everyone,
How do I create and read the pdf file using C# programmatically?
You have to use a special library. ITextSharp is free for non commercial applications.
Creating PDFs is quite easy with open source libraries (such as ITextSharp). Reading PDFs with anything but very simple formatting can be quite difficult though. PDF is not the easiest format to parse.
At NiXPS we are working on a new completely native C# library to create, read and edit PDF files. If you're interested in testing it, send us an email at info at nixps.com.
Unfortunately, like most people said PDF is not easy to read.
However there are options, but it requires having Adobe Acrobat installed on your system, and isn't quite 'server grade'.
The native acrobat type libraries have methods to grab text given coordinates in the PDF file. It's based on standard 72 points per inch , and originates from the bottom left corner of the document. It's a bit cumbersome but possible. Obviously this is missing all the calls to create the various objects but to give you an example, this is how to 'scrape' text from a PDF location
objPDFRect.Left = 36
objPDFRect.right = 400
objPDFRect.Top = 115
objPDFRect.bottom = 110
objPDFTextSelection = objPDFDoc.CreateTextSelect(xyz - 1, objPDFRect)
If objPDFTextSelection Is Nothing Then
Else
temptextcount = objPDFTextSelection.GetNumText
For lngTextRangeCount = 1 To objPDFTextSelection.GetNumText
line2 = line2 & objPDFTextSelection.GetText(lngTextRangeCount - 1)
Next
If temptextcount > 0 Then
'store line2 somewhere.
End If
End If
Open Source:
iTextSharp (for generating PDF)
GhostScript (for interpretting PDF, eg rasterising to Images etc)
Commercial:
The components from Tall Components are very good, have use to great successs (not affiliated)
Reporting:
If you want to generate reports a commercial reporting tool is advised.
HTH
iTextSharp is a C# port of iText, a Java PDF library. The C# port is maintained by Paulo Soares (no I don't know how to pronounce it either), the second-largest contributor to iText after Bruno Lowagie (the original author). iTextSharp (as of 5.0) is covered under the AGPL. That means anyone with access to the program's output must have access to the source. In order to use it in a closed-source/commercial environment, you must license it from iTextSoftware.com.
Prior to 5.0, it was released under the LGPL and Mozilla licenses (as was iText proper), which is much more commerce-friendly (and much less likely to earn the people who have spent years on it any money, thus the change). These versions are still available, but don't expect to get any support from the [email protected] mailing list.
But there's always stack overflow...