PDF READER

How To Read PDF File

If you write down This code in Button click or Page_load in C#

For  create a reader (constructor overloaded for path to local file or URL)
PdfReader reader = new PdfReader(@"E:\crreport.pdf"); 

//= new PdfReader("http://www.chinehamchat.com/Chineham_Chat_Advertisements.pdf");

// total number of pages
int n = reader.NumberOfPages;

// size of the first page
Rectangle psize = reader.GetPageSize(1);

//reader.AddPdfObject (objd PdfPRow.RIGHT_LIMIT);
float width = psize.Width;
float height = psize.Height;

//Console.WriteLine("Size of page 1 of {0} => {1} × {2}", n, width, height);
Response.Write("Size of page 1 of " + n + "  => " + width + " × " + height + "");

// file properties
Dictionary<string, string> infodict = reader.Info;
foreach (KeyValuePair<string, string> kvp in infodict)

//Console.WriteLine(kvp.Key + " => " + kvp.Value);
Response.Write(kvp.Key + " => " + kvp.Value);

OK, let's say I have a PDF document called "Form.pdf" with 4 form fields. The form fileds are "name", "address", "postal_code" and "email".

Here's the code to create a new PDF file using "Form.pdf" as a template:

private void fillForm()
{
    string formFile = @"N:\.NET\Form.pdf";
    string newFile = @"N:\.NET\Filled-out Form.pdf";
    PdfReader reader = new PdfReader(form File);
    PdfStamper stamper = new PdfStamper(reader, new FileStream(
    newFile, FileMode.Create));
    AcroFields fields = stamper.AcroFields;
 
   
// set form fields
    fields.SetField("name", "John Doe");
    fields.SetField("address", "2 Milky Way, London");
    fields.SetField("postal_code", "XX1 4YY");
    fields.SetField("email", "[email protected]"); 
   
// flatten form fields and close document
}

Output looks like

pdf.gif

Summary

In this article, I discussed how we can read a Pdf file using Itextsharp and C#. We also saw how we can Read Columns in Pdf and Generate excel file also make Doc and Txt file to Pdfreader property in to ItextSharp Dll include in your project and write down this code………
 

Ebook Download
View all
Learn
View all