itextsharp pdf generation, insert image header.

G

guoqi zheng

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
 
Joined
May 11, 2011
Messages
1
Reaction score
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
 
Joined
Oct 13, 2011
Messages
1
Reaction score
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:

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top