You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (Jira)" <ji...@apache.org> on 2021/03/16 18:56:00 UTC
[jira] [Commented] (PDFBOX-5130) Getting Error: End-of-File,
expected line while merging input streams to create a single pdf file
[ https://issues.apache.org/jira/browse/PDFBOX-5130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17302818#comment-17302818 ]
Tilman Hausherr commented on PDFBOX-5130:
-----------------------------------------
Change your code to this
{code:java}
try (FileOutputStream fileOutputStream = new FileOutputStream(mergedFileName))
{
PDFMergerUtility pdfmerger = new PDFMergerUtility();
for (InputStream stream : streams)
{
//PDDocument document = PDDocument.load(stream);
pdfmerger.setDestinationStream(fileOutputStream);
//pdfmerger.addSources(streams);
pdfmerger.addSource(stream);
//document.close();
//stream.close();
}
pdfmerger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
} {code}
The problem with your code is that you're opening each stream 3 times so it gets consumed. Once with load(), then once because you add the array (instead of the stream) each time, and once when merging.
> Getting Error: End-of-File, expected line while merging input streams to create a single pdf file
> --------------------------------------------------------------------------------------------------
>
> Key: PDFBOX-5130
> URL: https://issues.apache.org/jira/browse/PDFBOX-5130
> Project: PDFBox
> Issue Type: Bug
> Components: Parsing
> Affects Versions: 2.0.22
> Environment: java
> Reporter: Amar Kumar
> Priority: Major
> Attachments: BaseToPdf.java
>
>
> Getting below while merging input streams to create a single pdf file
> Error: End-of-File, expected line
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org