Home Answers Viewqa Java-Beginners Adding Image to Header and footer at generating Itext PDF

 
 


Shashi Kanth Karnati
Adding Image to Header and footer at generating Itext PDF
4 Answer(s)      a year and 9 months ago
Posted in : Java Beginners

i want to add Image to Header , am generating the PDF letter am able to add the text as showing below :

 HeaderFooter header = new HeaderFooter(new Phrase("This is page: ", new Font(bf_courier)), true);

 header.setAlignment(Element.ALIGN_CENTER);
 document.setHeader(header);

   HeaderFooter footer = new HeaderFooter(new Phrase(
    "This is page: ", new Font(bf_courier)), true);

   footer.setBorder(Rectangle.NO_BORDER);
    footer.setAlignment(Element.ALIGN_CENTER);
    document.setFooter(footer);

But i need to add the Image at header.

View Answers

August 3, 2011 at 4:38 PM


import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class CreatePDF{
    public static void main(String arg[])throws Exception{
      try{
                Document document=new Document();
                FileOutputStream fos=new FileOutputStream("C:/header-footer.pdf");
                PdfWriter writer = PdfWriter.getInstance(document, fos);
                document.open();
                Image image1 = Image.getInstance("C:/image1.jpg");
                Image image2 = Image.getInstance("C:/image2.jpg");

                image1.setAbsolutePosition(0, 0);
                image2.setAbsolutePosition(0, 0);

                PdfContentByte byte1 = writer.getDirectContent();
                PdfTemplate tp1 = byte1.createTemplate(600, 150);
                tp1.addImage(image2);

                PdfContentByte byte2 = writer.getDirectContent();
                PdfTemplate tp2 = byte2.createTemplate(600, 150);
                tp2.addImage(image1);

                byte1.addTemplate(tp1, 0, 715);
                byte2.addTemplate(tp2, 0, 0);

                Phrase phrase1 = new Phrase(byte1 + "", FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.NORMAL));
                Phrase phrase2 = new Phrase(byte2 + "", FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.NORMAL));

                HeaderFooter header = new HeaderFooter(phrase1, true);
                HeaderFooter footer = new HeaderFooter(phrase2, true);
                document.setHeader(header);
                document.setFooter(footer);
                document.close();
                System.out.println("File is created successfully showing header and footer.");
                }
                catch (Exception ex){
                    System.out.println(ex);

                }
            }
        }

August 4, 2011 at 5:56 PM


Hi I got with below code ,

thank you for the same. Code is :

Image logo = Image.getInstance("/image.gif");
logo.setAlignment(Image.MIDDLE);
logo.scaleAbsoluteHeight(20);
logo.scaleAbsoluteWidth(20);
logo.scalePercent(100);
Chunk chunk = new Chunk(logo, 0, -45);
HeaderFooter header = new HeaderFooter(new Phrase(chunk), false);
header.setAlignment(Element.ALIGN_CENTER);
header.setBorder(Rectangle.NO_BORDER);
document.setHeader(header);

July 11, 2012 at 9:01 PM


Hi, I have a similar question related to HeaderFooter class, I want to display three Phrases on Footer of the Page. First Phrase should be aligned left,Second phrase on the right and Third phrase in the middle. How can we acheive this? is it possible ? If so Please suggest me.


July 12, 2012 at 11:33 AM


HI, Here go through the below one.

This might be help you. or else you create different para's and then add with different alignments.

Font footFont = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL); // Font declaration

Paragraph footerLine = new Paragraph("---------------", footBold); // Bottom Line

footerLine.setAlignment(Element.ALIGN_CENTER); // ALIGN CENTER
Paragraph footerPara = new Paragraph("Company Name", footBold);
footerPara.setAlignment(Element.ALIGN_LEFT); //ALIGN LEFT

Paragraph footerHeadOfficeAdd = new Paragraph("Divisional Office: XYZ divistion,Mumbai, Tel:", footFont); // Phrase 1

Paragraph footerRegisteredAdd = new Paragraph( "Registered Office: XYZ Building,Dadar(W), Mumbai-400 028. ", footFont);

footerRegisterOfficeAdd.setAlignment(Element.ALIGN_LEFT);

Paragraph footPara = new Paragraph();

footPara.add( footerLine ); // Bottom Line

footPara.add( footerPara );  // Company Name

footPara.add( footerRegisteredAdd ); // Office Address

footPara.add( footerHeadOfficeAdd ); // Head office address

HeaderFooter footer = new HeaderFooter(new phrase (footPara), false);

footer.setBorder(Rectangle.NO_BORDER);

footer.setAlignment(Element.ALIGN_LEFT);

document.setHeader(header);









Related Pages:
Adding Image to Header and footer at generating Itext PDF
Adding Image to Header and footer at generating Itext PDF  i want to add Image to Header , am generating the PDF letter am able to add the text...); document.setFooter(footer); But i need to add the Image at header
Adding images in itext pdf
Adding images in itext pdf  Hi, How to add image in pdf file using itext? Thanks   Hi, You can use following code... image in the pdf file. Thanks
itext pdf
itext pdf  i am generating pdf using java i want to do alignment in pdf using java but i found mostly left and right alignment in a row. i want to divide single row in 4 parts then how can i do
generating itext pdf from java application - Java Beginners
generating itext pdf from java application  hi, Is there any method in page events of itext to remove page numbers from pdf generated frm.../java/itext/index.shtml
itext pdf - Java Interview Questions
itext pdf  sample program to modify the dimensions of image file in itext in java  HiIf you want to know deep knowledge then click here and get more information about itext pdf program.http://www.roseindia.net/java
Using HeaderFooter class of iText API , Can we display multiple phrases in the footer section of PDF ,each with different alignment.
Using HeaderFooter class of iText API , Can we display multiple phrases in the footer section of PDF ,each with different alignment.  Hi, I have... on Footer of the Page. First Phrase should be aligned left,Second phrase
Examples of iText
.   Inserting image in the pdf file...; How to wrap image in the pdf file... portrait in iTextiText is a framework for creating pdf files
Generating PDF reports - JSP-Servlet
Generating PDF reports  Hello everyone i have submitted several... Question I am try to generate a pdf report using jsp .... i want to export values stored in sql server DB on to a pdf files so please do reply its very
alignment for header and footer
alignment for header and footer  header and footer alignment is not fit like footer is not fit in bottom some white space is there in jsf, what to do
How to set the pdfptable as pdf page header when generating the pdf from jsp page. - JSP-Servlet
How to set the pdfptable as pdf page header when generating the pdf from jsp page.  how to set the pdfptable column headers as a header of the documet.i need to display the column headers for every pdf page if pdf documt is 20
How to set iText pdf document background image - Java Beginners
How to set iText pdf document background image  Hi, I have created the pdf document using the iText classes. but i need to set the background image for this pdf document. there is way to set the background color, but i
Generating pdf in Spring
Generating pdf in Spring  Sir/Madam, I need your help in generating a pdf by fetching the data form database and by using unicode in spring framework
How to access the image file from project folder itself while writing to pdf using itext?
How to access the image file from project folder itself while writing to pdf using itext?  I am writing a pdf using itext where i add a image in the beginning of the document. When i use image = Image.getInstance("C
page break using itext in java column wise
page break using itext in java column wise  I have a itext report which will displays n number of idcodes which will display from db.But in the pdf... in column wise in pdf. mainTab = new PdfPTable(prolength
Read Header/Footer Margin size using Java
Read Header/Footer Margin size using Java  Hi, Is it possible to read the "Header from Top" and "Footer from bottom" properties of a MS word document in Java? I have been searching the web for hours now, POI's and several other
Read Header/Footer Margin size using Java
Read Header/Footer Margin size using Java  Hi, Is it possible to read the "Header from Top" and "Footer from bottom" properties of a MS word document in Java? I have been searching the web for hours now, POI's and several other
Struts PDF Generating Example
Struts PDF Generating Example To generate a PDF in struts you need to use...;/param> </result> An example of PDF Generating is given below...;head> <title>PDF Generating Example</title> </head>
filling pdf by itext
filling pdf by itext  I read the pdf that contain of text field and I want to fill this field in the same pdf file that it oppened? what the sutible..., DocumentException { // read an existing pdf file PdfReader reader1 = new PdfReader
make header and footer and attache it with excel sheet.
 make header and footer and attache it with excel sheet... header and footer and attaché it with excel sheet.  Code description ...; class is used to create the header and footer. We create the object of header
PDF to Image
PDF to Image  Java code to convert PDF to Image
regarding the pdf table using itext
regarding the pdf table using itext  if table exceeds the maximum width of the page how to manage
Displaying html code in pdf with itext - Java Beginners
in the database i need to display this data in the pdf . i am using itext to create the pdf . i am using HTMLWorker to convert the html data . but styles...Displaying html code in pdf with itext   Hi , I am
How to set the border in header and footer from login page using swings/awt
How to set the border in header and footer from login page using swings/awt  Hi, How to set the border in header and footer from login page using swings/awt
How to put the image in footer in login form ?
How to put the image in footer in login form ?  Hi, how to put the image in footer in login form ?   Here is an example that shows image on footer along with Login Form in Java Swing. import javax.swing.*; import
How to open an Acroform in iText?
\iText_5.0.0.jar. All I want to do, initially, is try to open my PDF in iText, and I can't...How to open an Acroform in iText?  I modified a client's Acroform in Acrobat Pro 9, and now the client says he can't open it in iText. I had never
itext chunk
itext chunk       In this free tutorial we are going to tell you about chunk in iTextiText is a framework for creating pdf files in java. A Chunk
Read Issue itext
Read Issue itext  Hello, I m using itext to read data from pdf file... is der any way to read line by line data using itext so dat i can process it manually afterwords.. thnx in advance Rohit   Java itext read pdf file
Read Issue itext
Read Issue itext  Hello, I m using itext to read data from pdf file... is der any way to read line by line data using itext so dat i can process it manually afterwords.. thnx in advance Rohit   Java itext read pdf file
How to insert a single page PDF file into another multipage PDF file using iText? - Java Beginners
How to insert a single page PDF file into another multipage PDF file using iText?  Hi ALL: I have two PDF files. PDF-A.pdf is a multipage PDF file. PDF-B.pdf is a single page PDF file. I want to insert PDF-B into PDF-A only
HTML5 footer example, Definition of footer tag of HTML5.
of document.  A document can support more than one footer. You can not insert image in footer. Declaration Syntax : Declaration syntax of  footer...HTML5 footer example, Definition of footer tag of HTML5. The <footer>
Creating files of PDF's thumnails
server. You can then use following code to create PDF thumbnail image. <?php $im = new imagick('myfile.pdf'); $im->setImageFormat( "jpg" ); header...Creating files of PDF's thumnails  Hi, How to create PDF's thumbnail
Image display in pdf
Image display in pdf  i am trying to display a image in pdf using xsl fo but " [ERROR] Error while creating area : Error with image URL: images... go through the following link: Display image in pdf
how to get the image path when inserting the image into pdf file in jsp - JSP-Servlet
how to get the image path when inserting the image into pdf file in jsp ...")); document.open(); Image image = Image.getInstance("C:/image2.png"); Image image1 = Image.getInstance("C:/node.jpg"); document.add(image); document.add
itext version
itext version       In this program we are going to find version of  the iText jar file which is using to make a pdf file through the java program. In this example we need
How I can filling pdf file that crated by livecycle using itext
How I can filling pdf file that crated by livecycle using itext  I have pdf file that already done by livecycle.. I read it then I used the pdfstamber class to manipolute and filling file.... the result it will be a new pdf file
itext - Java Beginners
itext  Hi, Can we add contents to the back side of an itext..., new FileOutputStream("imagesWrapPDF.pdf")); document.open(); Image image... Technologies."); document.add(para); document.add(image); document.close
how to add the scrollbar to the pdf page when generating the pdf file from jsp - JSP-Servlet
how to add the scrollbar to the pdf page when generating the pdf file from jsp  I am not able to see all the columns when i generated the pdf file from jsp.i have 12 colums so how to add the scrollbar
Add Content of an iText PDF File using java code
Add Content of an iText PDF File using java code  ... to generate pdf file dynamically. The iText library can be used to generate PDF... facility to create pdf file from java application. iText is a freely available Java
pdf image extractor - Development process
pdf image extractor  hi deepak , can u pls tell me how to extract a text from a image in a pdf in java. for example bank stmt. i want to extract text from thet image which is in pdf. pls help me. Regards
pdf to text
pdf to text  how to covert pdf file (which contain table and text) into word or excel file using itext api
adding background image - Java Beginners
adding background image  how do i add background image to this code: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class sampleProg extends JFrame { JButton button = new JButton ("Result
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Adding image to database through jsp or HTML page ,while adding only image should show.
Adding image to database through jsp or HTML page ,while adding only image should show.   Adding image to database through jsp or HTML page,while adding only image should show. After that i need view that uploaded image from
Open Source PDF
Open Source PDF Open Source PDF Libraries in Java iText is a library that allows you to generate PDF files on the fly...: The look and feel of HTML is browser dependent; with iText and PDF you can
how to add the two tables in same row when generating pdf file from jsp - JSP-Servlet
how to add the two tables in same row when generating pdf file from jsp  How to add the two tables in same row one is left side and other is right side please help me.   Hi Friend, Try the following code
The type Font is ambiguous where generating pdf file from jsp page - JSP-Servlet
The type Font is ambiguous where generating pdf file from jsp page  I am geeting ambiguous error .Do u want to add any jar files   Hi Friend, Import the class Font into your JSP page like the following
Rotating image in the pdf file
Rotating image in the pdf file   ... insert a image in a pdf file and rotate it irrespective of the fact whether... will help us to make and use pdf file in our program. Now create a file named
The type Font is ambiguous where generating pdf file from jsp page - JSP-Servlet
The type Font is ambiguous where generating pdf file from jsp page  i am getting the type font is ambiguous and type imgae ambiguous ? document.open(); 32: Font headFont = FontFactory.getFont(FontFactory.HELVETICA

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.