Discussions

XML & Web services: Inserting text to existing PDF file

  1. Inserting text to existing PDF file (15 messages)

    I have a PDF File that contains fields ID,name etc, one below the other. The user details from web page(or XML) are to be inserted against the appropriate fields in PDF files. I tried inserting texts using Itext Software for PDf. But it overwrites the existing file and is not suitable to my needs. Can anybody suggest a solution on how to insert texts at appropriate place without overwriting existing PDF file using JSP.

    Threaded Messages (15)

  2. I don't know of any easy way to do this. PDF is designed to be a platform-independent printing specification, not a data-storage format.

    I strongly suggest you store your data in something other than a PDF (XML is good), then use some other utility (say XSL-FO) to convert your data to PDF as needed.

    If you absolutely must do things the hard way (because you don't have control over the data format), the best you can do is directly hack the contents of the PDF file. This is going to be very ugly and very error prone. Check out:

    http://partners.adobe.com/asn/tech/pdf/specifications.jsp
  3. Thanks for information[ Go to top ]

    Thanks for the information. But to tell the truth I thought that the response will be different. As for meI adore reading. Very often I find books that are worth reading in pdf format (maybe because I use this pdf seach engine http://pdf.rapid4me.com but it's very nice and it can find any book I want). Of course I can't read without making notes. That is why I needed a positive response so much.
  4. Thanks for information[ Go to top ]

    Thanks for the information. But to tell the truth I thought that the response will be different. As for meI adore reading. Very often I find books that are worth reading in pdf format (maybe because I use this pdf seach engine http://pdf.rapid4me.com but it's very nice and it can find any book I want). Of course I can't read without making notes. That is why I needed a positive response so much.

    If the needs are as Nataly Arlingston describes them (annotating PDF files), there are tons of solutions, even by Adobe itself.
    Here's a blog post that lists 20! http://www.hongkiat.com/blog/free-pdf-annotation-tools/
    Except for Adobe Reader and PDF Annotation, I do not know the solutions listed. But I'm sure there's something here that will suit your needs.

  5. taking notes on a pdf file[ Go to top ]

    copy paste into another format, or print and take notes the old fashioned way?

  6. iText PdfReader[ Go to top ]

    Use iText

    http://www.mail-archive.com/itext-questions at lists dot sourceforge dot net/msg06170.html

    http://www.lowagie.com/iText/tutorial/ch13.html
  7. Basic iText Example[ Go to top ]

    This will take an existing PDF called "somePDF.pdf" read the file, then add content to the fields in the PDF, then write the file to a new file called "aNewPDF.pdf". This is the most basic form of this method. For instance if the field names are unknown you can get a list of all field names and iterate through them. If you wish to combine pdfs into a single document you can. As I said this is just a bit of basic code.

    import com.lowagie.text.pdf.*;
    import com.lowagie.text.DocumentException;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.util.*;

    //Insert the following into a servlet or adapt it to a standard java class
        ServletContext context = getServletContext();
            
        //get a handle to the file location
        templatePath = context.getRealPath("/SomeDirectory");

        
        if(templatePath == null)
            {templatePath = File.separator;}
        else if(!templatePath.endsWith(File.separator))
            {templatePath += File.separator;}

    //Reads in the pdf Template
    PdfReader reader = new PdfReader(templatePath + "somePDF.pdf ");
        
    try
        {
        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("aNewPDF.pdf"));
        AcroFields form = stamp.getAcroFields();
                    
        //set the field values in the pdf form
        form.setField("fieldName","aValue");
        ...etc...
        ...etc...
                    
        stamp.setFormFlattening(true);
        stamp.close();}
                    
    catch(Exception e)
        {System.out.println("Error: " + e);}
  8. This is a nice example to explan how to insert text into pdf template file. In thie example, it make a new pdf file that is not I want. My requirement is to insert data into pdf template file and make a new pdf datastream and response to WEB http via servlet... I think it just need to change a little bit. But I have no idea how to do. Does anyone who can answer my question?
  9. How to do this with Web Application.[ Go to top ]

    Instead of using a File OutputStream use a ByteArrayOutputStream and get the bytes from the ByteArrayOutputStream
  10. inserting text into pdfs[ Go to top ]

    has anyone got the solution for this problem.
  11. iText is a library that allows you to generate PDF files on the fly. Please find more details on iText on below link.
    http://www.lowagie.com/iText/

    Here is a code snippet which takes multiple PDFs stream as input and merging them to a new PDF file


    Hope it did answer your question
  12. Thanks![ Go to top ]

    Thanks a lot the last comment helped me a great deal!

  13. Of course it is possible. but i suggest you'd better choose some tools . have you ever tried someone. if not, i want to recommend a professional PDF Plugin i've used before. it is pretty a genius. i believe you can add page numbers and consecutive numbers in locked PDF documents with the help of it. you can also other free trials of Yiigo. to deal with different files of documents, images, and barcodes. i wish i've offered a good choice for you. Bset Regards Arron
  14. convert[ Go to top ]

    Couldn't you just convert it to .docx and then back to .pdf
  15. The best thing that you can do is to convert your pdf files to word so that you can edit if you don't like it look over write.

  16. reply[ Go to top ]

    HI there

    I agree with you ,You can just convert your pdf files to word so that you can edit.Here is the code:

    namespace RE__Test
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {

    RasterEdgeImaging PDF = new RasterEdgeImaging();
    public void Convert Pdf to Word();
    {
    PDFInputFile = (@"C:/1.pdf");
    PDFPageNumber = "2";
    WordOutputFile = OutputFormat.docx;
    }
    PDF.Save("OutputFormat.docx", SaveFormat.docx);