Results 1 to 2 of 2
  1. #1
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    25
    Rep Power
    0

    Default PDFBox multiple text lines and fields

    Hello.

    I am trying to create a PDF file with a lot of text boxes in the document and textfields from another class. I am using PDFBox.

    OK, creating a new file is easy and writing one line of text is easy. Now, when I am trying to insert the next text line or textfield, it overwrites the content.

    Java Code:
    PDDocument doc = null;
    	    PDPage page = null;
    
    	       try{
    	    	   doc = new PDDocument();
    	           page = new PDPage();
    
    	           doc.addPage(page);
    	           PDFont font = PDType1Font.HELVETICA_BOLD;
    
    	           PDPageContentStream title = new PDPageContentStream(doc, page);
    	           title.beginText();
    	           title.setFont( font, 14 );
    	           title.moveTextPositionByAmount( 230, 720 );
    	           title.drawString("DISPATCH SUMMARY");
    	           title.endText();
    	           title.close();
    	           
    	           PDPageContentStream title1 = new PDPageContentStream(doc, page);
    	           title1.beginText();
    	           title1.setFont( font, 11 );
    	           title1.moveTextPositionByAmount( 30, 620 );
    	           title1.drawString("DEPARTURE");
    	           title1.endText();
    	           title1.close();
    
    	           
    	           doc.save("PDFWithText.pdf");
    	           doc.close();
    	    } catch (Exception e){
    	        System.out.println(e);
    	    }
    It does give me an error: "You are overwriting an existing content, you should use the append mode".
    So I am trying title1.appendRawCommands(String), but it is not working.

    How would I add new text boxes and textfields (from another class)? I have read tens of tutorials on Internet, but they only show creating one line.

    Many thanks!
    Last edited by igorland; 02-02-2013 at 03:16 AM.

  2. #2
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    25
    Rep Power
    0

    Default Re: PDFBox multiple text lines and fields

    Nevermind. I've found it:
    PDPageContentStream title1 = new PDPageContentStream(doc, page, true, true);
    Cheers.

Similar Threads

  1. Reading text using PDFBOX
    By umadas in forum Advanced Java
    Replies: 15
    Last Post: 01-21-2012, 09:47 AM
  2. Writing multiple lines to text file at once
    By Plex in forum New To Java
    Replies: 14
    Last Post: 11-08-2010, 10:17 PM
  3. Deleting multiple lines of text from a file
    By barman in forum New To Java
    Replies: 4
    Last Post: 06-29-2010, 10:12 AM
  4. working with Text in PDFBox
    By juehv in forum Advanced Java
    Replies: 0
    Last Post: 03-31-2010, 03:58 PM
  5. Read text content from pdf using pdfbox
    By cssatheesh in forum Advanced Java
    Replies: 0
    Last Post: 09-22-2009, 09:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •