Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Using PDFBox to Merge Multiple PDF Files

 
Steve Dyke
Ranch Hand
Posts: 2119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For some reason I get the following error when I try and run this code: Can someone help me to get this to work?

[12/19/17 15:45:04:139 CST] 00000088 SystemOut     O DocsVisionDrawingList: AcrobatRotateAndMerge_2_2: java.io.IOException: Error: End-of-File, expected line
[12/19/17 15:45:04:139 CST] 00000088 SystemErr     R java.io.IOException: Error: End-of-File, expected line
[12/19/17 15:45:04:139 CST] 00000088 SystemErr     R at org.apache.pdfbox.pdfparser.BaseParser.readLine(BaseParser.java:1119)
[12/19/17 15:45:04:139 CST] 00000088 SystemErr     R at org.apache.pdfbox.pdfparser.COSParser.parseHeader(COSParser.java:2442)
[12/19/17 15:45:04:139 CST] 00000088 SystemErr     R at org.apache.pdfbox.pdfparser.COSParser.parsePDFHeader(COSParser.java:2425)
[12/19/17 15:45:04:139 CST] 00000088 SystemErr     R at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:233)
[12/19/17 15:45:04:140 CST] 00000088 SystemErr     R at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1145)
[12/19/17 15:45:04:140 CST] 00000088 SystemErr     R at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1061)
[12/19/17 15:45:04:140 CST] 00000088 SystemErr     R at org.apache.pdfbox.multipdf.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:264)
[12/19/17 15:45:04:140 CST] 00000088 SystemErr     R at com.FAIWebApp.docsVision.DocsVisionDrawingList$AcrobatRotateAndMerge.<init>(DocsVisionDrawingList.java:575)

Line 575 - ut.mergeDocuments(null);

 
Paul Clapham
Marshal
Posts: 26914
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as a guess, it looks like a PDF parser is reading a PDF document which appears to be incomplete. So I'd suggest flushing the output stream before doing that. (Anyway, flushing the output stream after you close it would do nothing, you might as well not do it there.)
 
Steve Dyke
Ranch Hand
Posts: 2119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Just as a guess, it looks like a PDF parser is reading a PDF document which appears to be incomplete. So I'd suggest flushing the output stream before doing that. (Anyway, flushing the output stream after you close it would do nothing, you might as well not do it there.)



I moved line 59 to 47 but still got the same result(PDF file is created but no content.

I am not sure that in line 31 any data is being pushed to the add function.

Is line 23 actually writing data to an InputStream?
 
Paul Clapham
Marshal
Posts: 26914
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:I am not sure that in line 31 any data is being pushed to the add function.



No! You're quite correct about that, I'm sure. In line 25:



the load() method will consume the contents of the InputStream and produce a PDDocument object from that. So then line 31 will be working with the InputStream which is all used up.

I assume you want to include that PDDocument in the merge process? Well, maybe there's a way to tell the merge process to use the PDDocument. It's a very long time since I used PDFBox. If not, then I guess you'd have to create a second InputStream from the same SmbFile and let the merge process use that one.
 
Steve Dyke
Ranch Hand
Posts: 2119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Steve Dyke wrote:I am not sure that in line 31 any data is being pushed to the add function.



No! You're quite correct about that, I'm sure. In line 25:



the load() method will consume the contents of the InputStream and produce a PDDocument object from that. So then line 31 will be working with the InputStream which is all used up.

I assume you want to include that PDDocument in the merge process? Well, maybe there's a way to tell the merge process to use the PDDocument. It's a very long time since I used PDFBox. If not, then I guess you'd have to create a second InputStream from the same SmbFile and let the merge process use that one.



Thanks again. I got this to work: Now, my challenge is to insert on PDF file into another instead of merge. Welcome any help.

 
Tim Moores
Saloon Keeper
Posts: 7181
166
 
reply
    Bookmark Topic Watch Topic
  • New Topic