Home > itext, Java > Java Code to Convert PDF Using Itext jar

Java Code to Convert PDF Using Itext jar

Introduction

This article specifies a simple Java code to convert any kind of files to a PDF using iText jar. First let me give a small intro about the usage of  iText jar, which is an open source library used for creating and manipulating PDF, RDF and HTML files with the use of Java code. Thats Ok!! Let us come to the point, this article is consecrated for the peoples who wants to convert their files in to a PDF format using Java code. Download the latest iText jar here.

Read the rest of  this  entry…

  1. November 20, 2009 at 1:32 am | #1

    Hi Shunmuga,

    Good post. But it will be great if you can explain that in small steps that will help the users to understand the iText api.

    • November 22, 2009 at 3:55 am | #2

      Thank you very much for your valuable comments, As per your suggestion I had updated in the article!!

    • anju
      March 3, 2011 at 4:47 pm | #3

      hi,
      i tried this code, but it is not taking ppt files, doc with tables, excel etc..
      Is there any library available which can convert any file to pdf using java

  2. sreekar
    November 21, 2009 at 8:12 am | #4

    Hello Mr. Shanmuga Krishna,

    The above is converting html to PDF with the html tags..plz tell me how to convert html to PDF without displaying tags in the PDF..i want to display HTML page as PDF not the code.

    Thanks in advance.

    • November 25, 2009 at 11:01 pm | #5

      Hi sreekar,
      Thanks for your comments and your question is substantive. I will find a work around for your query in Java code and surely I will update in my next article. For the time being if you worked in a web based project means, you can use Primefaces Data Exporter. I hope the following link would be helpful to do so!!
      http://97.107.138.40:8080/prime-showcase/ui/exporter.jsf

      • kalesha
        January 27, 2011 at 2:18 am | #6

        Hi shunmuga,

        Plz tell me how to convert the jsp page data into pdf format.That data is getting from DB.

  3. November 26, 2009 at 1:56 am | #7

    Bruno (the guy who wrote much of Itext) has a new version of IText in Action coming out. The first few chapters are available to read online and the book is a brilliant resource if you are looking to make the most of IText.

  4. Arpita
    December 9, 2009 at 6:28 pm | #8

    Hello Shunmuga,
    The above code i use but it gives error in line 46

    pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));

    can u please help me why it is give error over there…?

  5. Geethani
    December 9, 2009 at 7:27 pm | #10

    I worked with this code,but in pdf file the whole image is not displayed.can you help me for this.thanx.

    • December 11, 2009 at 4:25 pm | #11

      Hi Geethani,
      Your question is substantive, I guess your image size is more than 1.5MB. For this, you need to set the page size by invoking the following code.

      package com.sample.pdfconvertor;
      import com.lowagie.text.Document;
      import com.lowagie.text.Paragraph;
      import com.lowagie.text.pdf.PdfWriter;
      import java.io.File;
      import java.io.FileOutputStream;
      /**
       *
       * @author shunmuga
       */
      public class PDFConversion
      {
       /**
       * This method is used to convert the given file to a PDF format
       * @param inputFile - Name and the path of the file
       * @param outputFile - Name and the path where the PDF file to be saved
       * @param isPictureFile
       */
       private void createPdf(String inputFile, String outputFile, boolean isPictureFile)
       {
            /**
            * Set the page size for the image
            */
            Rectangle pageSize = new Rectangle(2780, 2525);
          Document pdfDocument = new Document(pageSize);
           String pdfFilePath = outputFile;
           try
           {
               FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
               PdfWriter writer = null;
               writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
               writer.open();
               pdfDocument.open();
               /**
               * Proceed if the file given is a picture file
               */
                if (isPictureFile)
               {
                pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
               }
               /**
               * Proceed if the file given is (.txt,.html,.doc etc)
               */
               else
               {
               File file = new File(inputFile);
               pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
               }
      
               pdfDocument.close();
               writer.close();
           }
           catch (Exception exception)
           {
            System.out.println("Document Exception!" + exception);
           }
        }
      
        public static void main(String args[])
        {
         PDFConversion pdfConversion = new PDFConversion();
         pdfConversion.createPdf("C:/shunmuga/tajmahal.jpg", "C:/shunmuga/tajmahal.pdf", true);
      
      // For other files
         // pdfConversion.createPdf("C:/shunmuga/sample.html",
         //"C:/shunmuga/sample.pdf", false);
         }
      }
      
      

      I hope this one helps!!

      • Geethani
        December 16, 2009 at 1:14 pm | #12

        thanx a lot

  6. Ravi
    December 11, 2009 at 8:17 pm | #13

    Thanks a lot..

    • December 11, 2009 at 9:02 pm | #14

      you’re welcome.

      • Ashish
        March 8, 2011 at 2:15 pm | #15

        Here Problem with this code is that,,
        Newly created Pdf is not opened in my system while i am traying to create it from HTML file..
        Give me solution for that

  7. Arpita
    December 14, 2009 at 6:45 pm | #16

    Hello Shunmuga,
    thanks for your guide,
    i add commons-io-1.4-bin.tar,commons-io-1.4-src,commons-io-1.4-src.tar,commons-io-1.4-bin jar files in my library but error in line 46
    pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
    is not resolve.
    plz help….

  8. Arpita
    December 15, 2009 at 2:17 pm | #17

    Hello Shunmuga,
    thanks for your guide.

  9. Surendar
    December 16, 2009 at 5:17 pm | #18

    But I need to convert contents of browser into pdf…….

  10. Surendar
    December 16, 2009 at 5:18 pm | #19

    The given code converting the html code to pdf….. help me out for the browser contents….

  11. Arpita
    December 16, 2009 at 6:18 pm | #21

    Hello Shunmuga,
    thanks alot….

    according to your suggesion i do but at run time it gives error

    Document Exception!java.io.IOException: file:/D:/itext/workgroup/iText/WebContent/Demo.jsp is not a recognized imageformat.

    plz help me
    why it gives such kind of error….

    • December 16, 2009 at 8:38 pm | #22

      Hi Arpita,
      you are trying to convert a jsp file in to pdf, its not an image file.
      //for image file

      pdfConversion.createPdf("C:/shunmuga/tajmahal.jpg", "C:/shunmuga/tajmahal.pdf", true);
      

      //for other files

      pdfConversion.createPdf("C:/shunmuga/sample.txt", "C:/shunmuga/sample.pdf", false);
      

      I hope this one helps!!

  12. Surendar
    December 16, 2009 at 9:17 pm | #23

    is there any other way to do that?

  13. Arpita
    December 17, 2009 at 2:05 pm | #24

    thanks alot….
    Shunmuga

  14. Surendar
    December 18, 2009 at 12:55 am | #25

    with this I want to convert it to image pdf….. its giving me only the text pdf….

  15. Surendar
    December 18, 2009 at 12:56 am | #26

    and also let me know the other way for that browser content pdf…

  16. sajid
    December 27, 2009 at 8:57 pm | #27

    Hey Shunmugam
    thanks for this article. really good. i just wanted to know that is there any way by which we can just convert first page of the doc file into pdf ? please explain if API allows such methods.
    thanks

  17. sajid
    December 27, 2009 at 9:38 pm | #28

    Hey Shunmuga,
    it seems it is not working with doc files. when i am trying to convert doc to pdf then it is adding some junk characters in the start and end of the pdf. do u have any idea why it may happen ?

  18. sajid
    December 28, 2009 at 7:35 pm | #29

    Hey Shunmuga,
    thanks for this program. i have some issues here. when i am generating the pdf from doc its adding some junk chars in the start and end of the pdf file. so u have any idea why its happening? do we have any way to remove such junk chars from pdf.
    kindly help.
    thanks

    • Monty khurana
      December 15, 2011 at 3:28 am | #30

      Hi Sajid!!

      I am also facing the same issue..i know this thing is now 2 years ago.but tell me did u get any response or how did u solved your problem????

      Thanks in anticipation

      Monty Khurana

  19. Ravi
    January 4, 2010 at 10:12 pm | #31

    hello, thanks for help.
    i wanted to know that is there any way to write

    createPdf(String htmlCode, String outputFile, boolean isPictureFile) this function?

    e.g.: htmlCode=”Test”

    html code in string instead of input file??
    please help.
    thanks again
    Ravi

    • January 4, 2010 at 10:33 pm | #32

      Hi Ravi,
      Thanks for your comment ,you want convert html output as pdf or html code in to pdf?
      Here i m only consider about html code in to pdf …. now let me know whats your probs?

      • Surabhi
        February 19, 2010 at 8:20 pm | #33

        Hello,Shunmuga:
        Wanted to know how to generate a pdf with an image and data from db in the header of the pdf doc.I am trying to generate pdf on the fly.
        Thanks in advance.
        -Surabhi

      • February 21, 2010 at 2:52 pm | #34

        Hi Surabhi,
        Thanks for your comment ,you may try this following example .

        import com.lowagie.text.Document;
        import com.lowagie.text.DocumentException;
        import com.lowagie.text.Element;
        import com.lowagie.text.HeaderFooter;
        import com.lowagie.text.PageSize;
        import com.lowagie.text.Paragraph;
        import com.lowagie.text.Phrase;
        import com.lowagie.text.Rectangle;
        import com.lowagie.text.pdf.PdfWriter;
        import java.io.File;
        import java.io.FileOutputStream;
        import java.io.IOException;
        import java.util.logging.Level;
        import java.util.logging.Logger;
        
        /**
         *
         * @author shunmuga
         */
        public class PDFHeader
        {
        
            private void createPDF() throws DocumentException
            {
                try
                {
                    File inputFile = new File("tajmahal.JPG");
                    Document document = new Document(PageSize.A2.rotate());
                    PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\shunmuga\\Desktop" + File.separator + "SamplePicture.pdf"));
        
                    HeaderFooter header = new HeaderFooter(new Phrase("Wonders"), false);
                    header.setBorder(Rectangle.NO_BORDER);
                    header.setAlignment(Element.ALIGN_CENTER);
                    document.setHeader(header);
        
                    HeaderFooter footer = new HeaderFooter(new Phrase("Page no: "), true);
                    footer.setBorder(Rectangle.NO_BORDER);
                    footer.setAlignment(Element.ALIGN_CENTER);
                    document.setFooter(footer);
        
                    document.open();
                    document.add(new Paragraph("Tajmahal:"));
        
                    document.add(com.lowagie.text.Image.getInstance(inputFile.getName()));
        
                    document.close();
                } catch (IOException ex)
                {
                    Logger.getLogger(PDFHeader.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        
            public static void main(String[] args)
            {
                try
                {
                    PDFHeader pdfHeader = new PDFHeader();
                    pdfHeader.createPDF();
                } catch (DocumentException ex)
                {
                    Logger.getLogger(PDFHeader.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        

        I hope this one helps…

      • Surabhi
        February 22, 2010 at 7:15 pm | #35

        Hi, Shunmuga :
        Thank you . Do we have to create a XXX.pdf to generate the pdf on fly.
        I am using JSF. when i click on preview notice button it has to generate the message in .pdf format with the company’s logo on the top left corner and some other info from database on the top right end corner of the pdf.
        Thanks in advance.
        -Surabhi.

      • Surabhi
        February 23, 2010 at 9:04 pm | #36

        Hello, Shunmuga :

        the latest version of itext.jar doesn’t have import com.lowagie.text.HeaderFooter;
        It only has import com.itextpdf.text.Header;

        How do i handle this?

        Thank You.

        -Surabhi.

      • Surabhi
        March 2, 2010 at 5:49 pm | #37

        Hi,
        Can you please tell me how to call this code in a servlet.

        -Surabhi.

      • pavan
        June 21, 2011 at 9:18 pm | #38

        hi pavan,
        this exception shows when i convert txt,docx,xls file to pdf.
        Document Exception!java.io.IOException: file:/C:/Documents%20and%20Settings/Om/Desktop/_UpgradeReport_Files/pdftext.txt is not a recognized imageformat.
        and i also change the file path as you suggest its below.
        pdfConversion.createPdf(“C:\\Documents and Settings\\Om\\Desktop\\_UpgradeReport_Files\\pdftext.txt”, “C:\\Documents and Settings\\Om\\Desktop\\_UpgradeReport_Files\\cs4.pdf”, true);

  20. Soumya
    January 29, 2010 at 2:44 am | #39

    Hi Shanmuga,

    I have a jsp page which printout a web page which dynamic table fields(rows,columns) coming from the database.The requirement is to convert it to pdf on the fly with the help of a button.

    How would I do that?

    Any suggestion is gladly appreciated?

  21. jery
    February 16, 2010 at 9:42 pm | #40

    Hi,

    Will it convert textbox, checkbox & radio button as well???

    Thanks in advance

  22. jery
    February 16, 2010 at 9:43 pm | #41

    Hi,

    Will it convert textbox, checkbox & radio buttons while converting as a pdf from html???

    Thanks in advance

  23. Smita
    February 23, 2010 at 1:13 pm | #42

    hi,

    i want to convert Applet program into pdf file

  24. Smita
    February 23, 2010 at 1:32 pm | #43

    hi,

    The Applet program in which i have wrote jgraph code that want to convert pdf form can you help me.

  25. Surabhi
    February 24, 2010 at 8:24 pm | #44

    import java.io.ByteArrayInputStream;

    import java.io.ByteArrayOutputStream;

    import java.io.OutputStream;

    import javax.xml.parsers.DocumentBuilder;

    import javax.xml.parsers.DocumentBuilderFactory;

    import org.ajax4jsf.org.w3c.tidy.Tidy;

    import org.w3c.dom.Document;

    import org.xhtmlrenderer.pdf.ITextRenderer;

    public class NoticeRenderer {

    private OutputStream out;

    private NoticeSettings settings = null;

    private StringBuffer buffer = new StringBuffer();

    public NoticeRenderer(OutputStream out, NoticeSettings settings) {

    this.out = out;

    this.settings = settings;

    }

    public void start() {

    addHtml(“”);

    addDefaultStyleSheet();

    }

    public void end() {

    addHtml(“”);

    }

    public void startBody() {

    addHtml(“”);

    }

    public void endBody() {

    addHtml(“”);

    }

    public void addPageBreak() {

    addHtml(“”);

    }

    private void addHtml(String html) {

    buffer.append(html);

    }

    public void addDefaultStyleSheet() {

    String pageSize = “size: ” + settings.getPageWidth() + “in ”

    + settings.getPageHeight() + “in;\n”;

    String pageMargin = “margin: ” + settings.getPageBorderWidth() + “;\n”;

    String header = “” + “” + “@page { \n”

    + pageSize

    + pageMargin

    + (settings.isIncludePageBorderLine() ? “border: thin solid black;\n”

    : “”) + “padding: 1em;\n” + “}\n”

    + “table#addresslist, td#addresslist_td , th#addresslist_th\n”

    + “{\n” + ” border-color: #600;\n”

    + ” border-style: solid;\n” + “}\n” +

    “table#addresslist\n” + “{\n”

    + ” border-width: 1px 1px 1px 1px;\n”

    + ” border-spacing: 0;\n”

    + ” border-collapse: collapse;\n” + “}\n” +

    “td#addresslist_td\n” + “{\n” + ” margin: 0;\n”

    + ” padding: 4px;\n” + ” border-width: 1px 1px 0 0;\n”

    + ” background-color: #FFC;\n” + “}\n”

    + “th#addresslist_th\n” + “{\n” + ” margin: 0;\n”

    + ” padding: 4px;\n” + ” border-width: 0 0 1px 1px;\n”

    + ” background-color: #FFC;\n” + “}\n”

    + “” + “” + “”;

    addHtml(header);

    }

    public void addLogoAndHeader() {

    if (settings == null)

    return;

    String top = “”;

    if (settings.getClientLogo() != null

    && settings.getClientLogo().length > 0) {

    //top += ” 200 ? 200: true); max-height: 100px; height: expression(this.height > 100 ? 100: true);\” src=\”"

    top += “”;

    }

    if (settings.getNoticeHeader() != null

    && settings.getNoticeHeader().length() > 0) {

    top += “” + settings.getNoticeHeader() + “”;

    }

    top += “”;

    addHtml(“” + top + “”);

    }

    public void addFooter() {

    if (settings == null)

    return;

    String bottom = “”;

    if (settings.getNoticeFooter() != null

    && settings.getNoticeFooter().length() > 0) {

    bottom += settings.getNoticeFooter();

    }

    addHtml(“” + bottom + “”);

    }

    public void addReportPageContent(String reportText) {

    addHtml(reportText);

    }

    public void render() {

    Tidy tidy = new Tidy();

    tidy.setTidyMark(false);

    tidy.setDocType(“auto”);

    tidy.setWrapScriptlets(true);

    tidy.setOnlyErrors(false);

    tidy.setXHTML(true);

    tidy.setEncloseText(true);

    tidy.setXmlTags(true);

    ByteArrayOutputStream os = new ByteArrayOutputStream();

    String data = buffer.toString();

    tidy.parseDOM(new ByteArrayInputStream(data.getBytes()), os);

    String newString = new String(os.toByteArray());

    int errorCount = tidy.getParseErrors();

    if (errorCount == 0)

    newString = new String(os.toByteArray());

    if (newString.trim().length() == 0)

    newString = data;

    try {

    DocumentBuilder builder = DocumentBuilderFactory.newInstance()

    .newDocumentBuilder();

    Document doc = builder.parse(new ByteArrayInputStream(newString

    .getBytes(“UTF-8″)));

    ITextRenderer renderer = new ITextRenderer();

    renderer.setDocument(doc, HttpSessionHelper.getServerURL() + “/”);

    renderer.layout();

    renderer.createPDF(out);

    } catch (Exception e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    }

    public static void renderNotice(String reportText, OutputStream out,

    NoticeSettings settings) {

    NoticeRenderer renderer = new NoticeRenderer(out, settings);

    renderer.start();

    renderer.startBody();

    renderer.addLogoAndHeader();

    renderer.addReportPageContent(reportText);

    // renderer.addFooter();

    renderer.addPageBreak();

    renderer.endBody();

    renderer.end();

    renderer.render();

    }

    }

    I have used NoticeRenderer.java and previewnotice.jsp to generate a pdf doc on the fly when i click on “PreviewNotice” button.

    I want to convert a java file directly instead of using the HTML conversion i have used in NoticeRenderer.java

    i tried doing the same in java with the help of code given by you.

    this is all i could manage :

    //PDFHeader.java
    // import java.awt.Color;

    import com.lowagie.text.Document;
    import com.lowagie.text.DocumentException;
    import com.lowagie.text.Element;
    import com.lowagie.text.HeaderFooter;
    import com.lowagie.text.Paragraph;
    import com.lowagie.text.Phrase;
    import com.lowagie.text.Rectangle;
    import com.lowagie.text.pdf.PdfWriter;
    import com.lowagie.text.Image;
    import com.lowagie.text.PageSize;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    // import com.lowagie.text.pdf.draw.LineSeparator;
    // import com.lowagie.text.pdf.draw.VerticalPositionMark;

    /**
    *
    * @author Sushma P
    */
    public class PDFHeader
    {

    private void createPDF() throws DocumentException
    {
    try
    {
    File inputFile = new File(“tomcat.gif”);
    Document document = new Document(PageSize.A4);
    // VerticalPositionMark separator = new LineSeparator(1, 80, Color.RED, Element.ALIGN_RIGHT, -2);
    PdfWriter.getInstance(document, new FileOutputStream(“/home/sushma/Desktop” + File.separator + “SamplePicture.pdf”));
    String address = “#263, \n Himagiri Meadows, \n BG Road, \n Blr-83″;
    HeaderFooter header = new HeaderFooter(new Phrase(address), false);
    header.setBorder(Rectangle.NO_BORDER);
    header.setAlignment(Element.ALIGN_RIGHT);
    document.setHeader(header);

    // VerticalPositionMark separator = new LineSeparator(1, 80, Color.RED, Element.ALIGN_RIGHT, -2);

    HeaderFooter footer = new HeaderFooter(new Phrase(“Page no: “), true);
    footer.setBorder(Rectangle.NO_BORDER);
    footer.setAlignment(Element.ALIGN_CENTER);
    document.setFooter(footer);

    Image img = Image.getInstance(inputFile.getName());

    img.setAlignment(Element.ALIGN_LEFT);
    img.setAbsolutePosition(0 , 825 – img.getScaledHeight());

    document.open();
    document.add(img);
    document.add(new Paragraph(“Helloo:”));

    document.close();
    } catch (IOException ex)
    {
    Logger.getLogger(PDFHeader.class.getName()).log(Level.SEVERE, null, ex);
    }
    }

    public static void main(String[] args)
    {
    try
    {
    PDFHeader pdfHeader = new PDFHeader();
    pdfHeader.createPDF();
    } catch (DocumentException ex)
    {
    Logger.getLogger(PDFHeader.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    }

    Could you please help me out .
    Thanks in advance.

    -Surabhi.

    Notice

    • Surabhi
      February 24, 2010 at 8:31 pm | #45

      i want to generate the pdf in the format of a company’s letterhead. with logo and some info in the header region and a footer with info and body with some data.

      Thanks You.
      -Surabhi.

  26. kasthuri
    March 10, 2010 at 1:47 pm | #46

    Hello Shunmuga,
    thanks for your guide,
    But i’ve an error in line 46
    pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
    is not resolve.what i do
    plz help….

  27. kasthuri
    March 10, 2010 at 1:57 pm | #47

    And also how is use this code in GWT project,
    plz help me
    -kasthuri

  28. kasthuri
    March 10, 2010 at 2:20 pm | #48

    i’m execute my program for image file without 46th line,
    i have an exception,
    that exception is Exception!java.io.FileNotFoundException

    • March 11, 2010 at 12:15 am | #49

      Hi kasthuri,
      If you want to convert image file in to pdf means you may try following codes

      
      package samplePDF;
      
      import com.lowagie.text.Document;
      import com.lowagie.text.pdf.PdfWriter;
      import java.io.FileOutputStream;
      
      /**
       *
       * @author shunmuga
       */
      public class PDFImageConversion
      {
      
          private void createPdf(String inputFile, String outputFile, boolean isPictureFile)
          {
              /**
               * Create a new instance for Document class
               */
              Document pdfDocument = new Document();
              String pdfFilePath = outputFile;
              try
              {
                  FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
                  PdfWriter writer = null;
                  writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
      
                  writer.open();
                  pdfDocument.open();
      
                  /**
                   * Proceed if the file given is a picture file
                   */
                  if (isPictureFile)
                  {
                      pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
                  }
                  pdfDocument.close();
                  writer.close();
              } catch (Exception exception)
              {
                  System.out.println("Document Exception!" + exception);
      
              }
          }
      
          public static void main(String args[])
          {
              PDFImageConversion pdfConversion = new PDFImageConversion();
              pdfConversion.createPdf("C:/Users/shunmuga/Desktop/DSCN1320.JPG", "C:/Users/shunmuga/Desktop/ss.pdf", true);
      
          }
      }
      
      

      it may helps……..

  29. Prabhakaran
    March 10, 2010 at 6:25 pm | #50

    Please guide me how to generate invoice using itext

  30. kasthuri
    March 12, 2010 at 1:55 pm | #51

    Hi shanmuga,

    thanks for ur guide.
    i got the output for converting text and image file to pdf format.
    Now i want, how to generate the invoice and appropriate code in java(with GWT or without)

    With regards
    kasthuri.D

  31. jamuna
    March 23, 2010 at 3:12 pm | #52

    hi………… ur code is really useful 4 me….. wen i convert html page to pdf. it shows only page code . how to show html page as pdf

  32. ROUF RAHID
    March 24, 2010 at 11:07 pm | #53

    Thankyou Sir.
    we have a comand button on form(using jsf) coantaing datatable of records from database,for pdf-download. How can we do that

  33. April 12, 2010 at 2:39 pm | #54

    hi..
    could you pls tell me how to produce a pdf docuemnt from xml having an dtd associated with it using itext

  34. Anil sahu
    April 17, 2010 at 3:35 am | #55

    Dear All,

    I have a requirement for converting a pdf file to a tiff file format, Can any one give me some clue like how we can create that using itext or anyother opensource?

    Thanks,
    Anil Sahu

  35. musth
    April 29, 2010 at 1:45 pm | #56

    hi,

    could u please help me, i have html text in the database of data type ntext now my need is how to present this html text in a pdf report using iText

  36. srihari
    May 28, 2010 at 5:16 pm | #57

    Hello Shunmuga,
    thanks for your guide,
    i add commons-io-1.4-bin.tar,commons-io-1.4-src,commons-io-1.4-src.tar,commons-io-1.4-bin jar files in my library but error in line 46
    pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
    is not resolve.
    plz help….

    and

    the HTML data like


    (Regd. ; Head Office : ererer-444444)
    HR DEPARTMENT   Ref: >REFERENCENUMBER> Date: >Date>   

    >Witness Name>, (witness )
    >Witness Designation> St. No>Witness Number>
    >Witness Branch>

      Dear Sir,
    Sub: Domestic Enquiry against >Staff Name> (charge sheet)
    - E.C. >EC Number> 
    You are hereby requested to appear before the Enquiry Officer, Shri >Enq.Off Name>, at the time, date and place mentioned below, to give evidence in the above case:

    Time>EO Time>Date>EO Date>Place>EO Place>.

    You are also requested to meet >MR Name> HR ;IR Dept., Head Office, the Management Representative in the above case at the time, date and place mentioned below:

    Time>MR Time>Date>MR Date>Place>MR Place>
     Yours faithfully, CHIEF MANAGER(HR) cc to: The Assistant General Manager – Inspection and Audit Department, HO.
    With a request to arrange for delivering the original to the member under acknowledgment and intimate us the date of service of the original.Please relieve/permit the above member at appropriate time to enable him/her to attendthe enquiry. this data input to the PDF then automatic
    convert to PDF please help me

  37. rutvik prajapati
    August 16, 2010 at 4:22 pm | #58

    hello sir,

    i have project in clg on file conversion..
    so i use this code.but there is an error abt

    the import com.lowagie.text.Document can not be resolved

    theimport com.lowagie.text.Paragraph can not be resolved

    thr import com.lowagie.text.pdf.PdfWriter can not be resolved

    can u plz help me…
    waiting for ur reply…

  38. Mahesh
    August 31, 2010 at 3:36 am | #59

    HI Dear Shanmuga !

    I need some help for my academic project.. i need to process research papers and want to retrieve data like title of the paper, author name, key words from from each pdf document… when i gone through many itext examples everything is about writing to pdf.. but i need to read these data from PDfs.. i need ur concerned help. pls help me and if possible give me some sample codes. thanks in Advance

    Regards,
    Mahesh

  39. satya
    August 31, 2010 at 5:51 pm | #60

    hi …..

    can u plz suggest or pass some code how i convert word doc to pdf file using itext…
    I have been google it since 4 / 5 dys but didnt get a clue…plz help

  40. Kwex
    October 1, 2010 at 5:55 pm | #61

    Hi Shunmugakrishna,

    Any assistance in converting PDF to image(jpg) using iText java?

    Thanks.

  41. Ewald
    March 24, 2011 at 12:22 am | #62

    Hi Shanmuga,
    can i use your Code to convert html to pdf without html-tags?
    Can you help me plz?
    Currently I’m using the code, but i’m getting pdf with html-tags… :-(

    Thanx.

    regards,
    Ewald

  42. Ewald555
    March 24, 2011 at 6:04 pm | #63

    Hi Shunmuga,

    your Example converts html-code into a pdf-file.
    I need urgently a Funkction, that converts html-output into a pdf-file…
    Plz help me…
    Thanx in advance.

  43. Muthu
    April 22, 2011 at 2:27 am | #64

    Hi shunmugakrishna,

    I tried to use your code to create PDF file from doc file. But it is dumpling lot of garbage into the pdf…Apart from that everything is good from your code. Can you please let me know how to avoid that. How ever when I am converting the txt file to pdf it is working fine…..Only problem is with doc file to pdf…please suggest….

  44. Saj
    May 4, 2011 at 5:04 pm | #65

    Hi Shunmugakrishna,

    I am looking for a way to convert any file into PDF. For example user can upload a doc file, .html file, .png file, .txt file or any thing. Is it possible to do it using iText API or is there any limitation on the file type.

    Thanks
    Saj.

  45. mohan
    June 7, 2011 at 1:19 pm | #66

    Is it possible to convert PS to PDF using java code

  46. Bhargav
    June 20, 2011 at 9:42 pm | #67

    Hi…i want to convert .PS files into PDF is any API’s present in JAVA to do this
    Please HELP

    Thanks in Advance,
    Bhargav

  47. mohan
    June 21, 2011 at 8:23 pm | #68

    How to convert PS to PDF using java

  48. Sathya
    July 25, 2011 at 5:48 pm | #69

    How to Replace the Link annotation uri in pdf using iTextSharp )(iTextpdf 5.1.1)using JAVA?
    im having one task please help me on this…. Consider a PDF file named sample.pdf containing 72 pages.Now using iTextSharp library I had split the PDF pages into 72 separate file and saved with the name as 1.pdf,2.pdf….72.pdf. So in the 4.pdf when clicking that hyperlinks I need to make the PDF navigate to 24.pdf,27.pdf,28.pdf. how to do it in JAVA?
    please provide me the sample code….

    Thank you, Sathya:

  49. Sathya
    July 25, 2011 at 5:48 pm | #70

    How to Replace the Link annotation uri in pdf using iTextSharp )(iTextpdf 5.1.1)using JAVA?
    im having one task please help me on this…. Consider a PDF file named sample.pdf containing 72 pages.Now using iTextSharp library I had split the PDF pages into 72 separate file and saved with the name as 1.pdf,2.pdf….72.pdf. So in the 4.pdf when clicking that hyperlinks I need to make the PDF navigate to 24.pdf,27.pdf,28.pdf. how to do it in JAVA?
    please provide me the sample code….

    Thank you, Sathya

  50. Jitendra Chauhan
    August 27, 2011 at 1:37 am | #71

    Hi Shunmuga,
    I m working in Online Exam Portal in B.E.I wan convert the Database of MySql into PDF file in JSP.Plz help me for this problem..

  51. Rames
    November 6, 2011 at 10:02 am | #72

    Hi, Can any help me to convert PDF to TXT.

  52. Jitendra Chauhan
    November 14, 2011 at 1:25 am | #73

    Thanx for code…

  53. kexiuru
    November 28, 2011 at 6:25 pm | #74

    how can i convert a doc to pdf? when i use the code, convert sucessful, but the ouput pdf has Garbled…..

  54. @nil
    December 15, 2011 at 6:36 pm | #75

    Hi Shunmuga,

    By using that code it is able to convert my html page into pdf in a html text format. But i need html output into pdf as it is with css. do u know any solutions for that.

  55. viplav
    January 8, 2012 at 9:36 pm | #76

    Hi Shunmuga thanks for your code. I have one requirement for my project . There I have one link on jsp page ‘link to pdf’ on click of this I need to show the same jsp look and feel which currently showing. On that jsp I have few frames which calls different servlets from there. Is there any solution for this ? I am thinking it’s better to handle this requirement from client side like with Java Script rather than Server side.

  56. cindiya
    February 13, 2012 at 9:49 pm | #77

    Hi

    In my file I have written code to display table,list and image in order inside a table using itext.jar
    when Pdf is generated the vertical borders of the pdf is overridden by the image,is there anyway to get the lines.(Meaning the border lines are missed only in the image.
    Kindly guide.

  57. yeshvanth
    April 11, 2012 at 7:25 pm | #78

    Hi
    I used the above code for converting fiile to pdf but i got the following error

    The declared package “com.sample.pdfconvertor” does not match the expected package
    The import com.lowagie cannot be resolved
    org.apache cannot be resolved

    please me out….

  58. paru
    May 21, 2012 at 5:31 pm | #79

    hi,

    is there any way to convert pdf file to word file with formatting?please help if possible.

  1. November 20, 2009 at 11:55 pm | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.