[
https://issues.apache.org/jira/browse/PDFBOX-4028?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16283691#comment-16283691
]
Martin Mancuska commented on PDFBOX-4028:
-----------------------------------------
Usually it fails on larger files (small are not affected). I cannot provide
internal PDF file, but PDF reference 1.7 can be used for this purpose of
testing. I've attached to this case.
Here is piece of code, pls update path to PDF file according to your
environment:
{code:java}
public static void main(String[] args) {
try {
// encryptFile();
PDDocument doc = PDDocument.load(new
File("e:\\pdf_reference_1-7.pdf"));
System.out.println("# Pages: " + doc.getPages().getCount() + ".");
PDStructureTreeRoot stRoot =
doc.getDocumentCatalog().getStructureTreeRoot();
COSDictionary stDict = stRoot.getCOSObject();
stDict.setNeedToBeUpdated(true);
COSDictionary catalogDict = doc.getDocumentCatalog().getCOSObject();
catalogDict.setNeedToBeUpdated(true);
saveIncremental(doc, "e:\\pdf_reference_1-7 copy.pdf"); //This is ok
saveIncremental(doc, "e:\\pdf_reference_1-7.pdf"); //This gets
corrupted
doc.close();
}
catch (InvalidPasswordException ex) {
return;
}
catch (IOException ex) {
System.out.println("IO chyba.");
return;
}
}
{code}
> SaveIncremental on same opened file
> -----------------------------------
>
> Key: PDFBOX-4028
> URL: https://issues.apache.org/jira/browse/PDFBOX-4028
> Project: PDFBox
> Issue Type: Bug
> Components: Writing
> Affects Versions: 2.0.8
> Reporter: Martin Mancuska
>
> The incremental save does not work correctly if it is done on the same opened
> document. It produces corrupted file. The save incremental should append
> changes at the end of file (after last origin EOF).
> Newly saved file contains changes also in the middle of the file not only at
> the end. Changes in the middle of file contains zeroed bytes or garbage.
> Tested with the latest stable version of PDFBox 2.0.8.
>
> Sample code:
> {code:java}
> String fileName = "/path/to/document.pdf";
> PDDocument doc = PDDocument.load((new File(fileName));
> ...
> document changes
> ...
> try ( OutputStream outStream = new FileOutputStream(fileName)) {
> doc.saveIcremental(outStream);
> }
> catch ....
> ...
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]