User Login

Please enter user name and password into following boxes!

If you are not registered yet, please click

Forget Password

If you forget your password, please click
favorite

Add Headers To All Pages in ItextSharp

Add Headers To All Pages


public void WritePageNumber(string path,string outputPath)
{
    
    PdfReader reader = new PdfReader(path);
    
    // Create a stamper
    PdfStamper stamper
    = new PdfStamper(reader,new FileStream(outputPath,FileMode.Create));
    // Loop over the pages and add a header to each page
    int n = reader.NumberOfPages;
    for (int i = 1; i <= n; i++)
    {
        GetHeaderTable(i, n).WriteSelectedRows(0, -1, 34, 803, stamper.GetOverContent(i));
        
    }
    // Close the stamper
    stamper.Close();
    reader.Close();
}
/**
* Create a header table with page X of Y
* @param x the page number
* @param y the total number of pages
* @return a table that can be used as header
*/
public static PdfPTable GetHeaderTable(int x, int y)
{
    PdfPTable table = new PdfPTable(2);
    table.TotalWidth=527;
    table.LockedWidth = true;
    table.DefaultCell.FixedHeight = 20;
    table.DefaultCell.Border = Element.ALIGN_BOTTOM;
    table.AddCell("FOOBAR FILMFESTIVAL");
    table.DefaultCell.HorizontalAlignment=(Element.ALIGN_RIGHT);
    table.AddCell($"Page {x} / {y}");
    return table;
}
}


PayPal - The safer, easier way to pay online!


Comments About Tutorial

There is no comment



Add Comment

Name*
Surname* 
Email* 
Subject* 
What is (12 + 5) :
WARNING

Please fill all text boxes

Message Result

Your comment is saved. After approved, it will be published

An Error Occured

We are sorry, your request cannot be continued try again later

LOGIN REQUESTED

Please login for this operation
Login