itextsharp pdf generation, insert image header.

Discussion in 'ASP .Net' started by guoqi zheng, Nov 30, 2005.

  1. guoqi zheng

    guoqi zheng Guest

    dear sir,

    I am using itextShap for pdf generation.
    I know I can insert image into it, I can add header to it as well. However,
    I can not add an image as a header.

    Does any one has experience with it and know how to insert an image header
    to the pdf file?

    This image is our company logo which we would like it to appear on every
    page on that pdf file.

    regards,

    Guoqi Zheng
    http://www.ureader.com
     
    guoqi zheng, Nov 30, 2005
    #1
    1. Advertisements

  2. Patrick.O.Ige, Dec 1, 2005
    #2
    1. Advertisements

  3. guoqi zheng

    guoqi zheng Guest

    I have read through them, and did not find it..

    It is possible to insert text header but not image header.

    regards,

    Guoqi Zheng
    http://www.ureader.com
     
    guoqi zheng, Dec 1, 2005
    #3
  4. guoqi zheng

    santhoshkumar.yes

    Joined:
    May 11, 2011
    Messages:
    1
    Likes Received:
    0
    Adding Image To Header of PDF using Itestsharp

    We cant add image directly to the Pdf Header and Footer.. There is an alternate way to add the Image File... Try the following code and chill..

    Document docPDF = new Document(PageSize.A4, 5, 5, 20, 50);

    Step 1: Add the Image file
    strImgPath is refer the directory Info..

    Image imgLogo = Image.GetInstance(strImgPath.ToString()+"\\CompWare.Jpg");
    imgLogo.Alignment = Image.ALIGN_CENTER;
    imgLogo.ScalePercent(50f);

    Step 2:

    Add this ImgLogo to the PdfPTable by use of this
    PdfPCell pdfcellImage = new PdfPCell(imgLogo, true);
    pdfcellImage.FixedHeight = 40f;
    pdfcellImage.HorizontalAlignment = Element.ALIGN_CENTER;
    pdfcellImage.VerticalAlignment = Element.ALIGN_CENTER;
    pdfcellImage.Border = Rectangle.NO_BORDER;
    pdfcellImage.Border = Rectangle.NO_BORDER;
    pdftblImage.AddCell(pdfcellImage);

    Step 3:

    Create Chunck to add Text for address or others
    fntBoldComHd is a Base Font Library Object

    Chunk chnCompany = new Chunk("Your CompanyName\nAddress", fntBoldComHd);

    Step 4:

    Create Phrase For add the Chunks and PdfPTables

    Phrase phHeader = new Phrase();

    phHeader.Add(pdftblImage);
    phHeader.Add(chnCompany);

    Step 5:

    Assign the Phrase to PDF Header
    HeaderFooter header = new HeaderFooter(phHeader, false);
    header.Border = Rectangle.NO_BORDER;
    header.Alignment = Element.ALIGN_CENTER;
    docPDF.Header = header;

    Bye
    Santhosh Kumar Subramaniam
     
    santhoshkumar.yes, May 11, 2011
    #4
  5. guoqi zheng

    Levitikon

    Joined:
    Oct 13, 2011
    Messages:
    1
    Likes Received:
    0
    Santhosh, I would like to say your code is useful, but there is a undeclared variable.

    pdftblImage, at the bottom of step 2. How and where is it instantiated?
     
    Last edited: Oct 13, 2011
    Levitikon, Oct 13, 2011
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.