iTextSharp is a popular open-source PDF file manipulation library that is written in C#. It provides a variety of useful tools for working with PDFs, including the PdfReader class which allows you to read PDF files and extract information from them.
Here are some examples of how you can use the PdfReader class with iTextSharp:
1. Reading and extracting text from a PDF:
PdfReader reader = new PdfReader("my.pdf");
string text = "";
for (int page = 1; page <= reader.NumberOfPages; page++) { text += PdfTextExtractor.GetTextFromPage(reader, page); }
reader.Close();
This code reads a PDF file called "my.pdf" and extracts all the text from each page of the document. The extracted text is then stored in a string variable called "text".
if (resourcesDict != null) { PdfDictionary xObjectDict = resourcesDict.GetAsDict(PdfName.XOBJECT);
if (xObjectDict != null) { foreach (PdfName key in xObjectDict.Keys) { PdfObject obj = xObjectDict.Get(key);
if (obj.IsIndirect()) { PdfDictionary dict = (PdfDictionary)PdfReader.GetPdfObject(obj);
if (dict != null && dict.Get(PdfName.SUBTYPE).Equals(PdfName.IMAGE)) { int xrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture)); PdfObject pdfObj = reader.GetPdfObject(xrefIndex); PdfStream pdfStream = (PdfStream)pdfObj; byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStream); // do something with the image bytes... } } } } } }
reader.Close();
This code reads a PDF file called "my.pdf" and extracts all the images from each page of the document. The extracted images are then stored in a byte array variable called "bytes". This code uses the iTextSharp library's low-level PDF object model to retrieve the necessary data.
C# (CSharp) iTextSharp.text.pdf PdfReader - 60 examples found. These are the top rated real world C# (CSharp) examples of iTextSharp.text.pdf.PdfReader extracted from open source projects. You can rate examples to help us improve the quality of examples.