[
https://issues.apache.org/jira/browse/PDFBOX-3010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14947713#comment-14947713
]
Tilman Hausherr commented on PDFBOX-3010:
-----------------------------------------
I suspect that the problem is in PDDocument.assignAppearanceDictionary(), this
includes several streams:
{code}
COSDictionary{(COSName{N}:COSStream{(COSName{Type}:COSName{XObject})
(COSName{Subtype}:COSName{Form})
(COSName{Resources}:COSDictionary{(COSName{XObject}:COSDictionary{(COSName{FRM1}:COSStream{(COSName{Type}:COSName{XObject})
(COSName{Subtype}:COSName{Form})
(COSName{Resources}:COSDictionary{(COSName{XObject}:COSDictionary{(COSName{n1}:COSStream{(COSName{Type}:COSName{XObject})
(COSName{Subtype}:COSName{Form}) (COSName{BBox}:COSArray{[COSFloat{100.0},
COSFloat{50.0}, COSFloat{0.0}, COSFloat{0.0}]})
(COSName{Matrix}:COSArray{[COSFloat{1.0}, COSFloat{0.0}, COSFloat{0.0},
COSFloat{1.0}, COSFloat{0.0}, COSFloat{0.0}]})
(COSName{Resources}:COSDictionary{(COSName{XObject}:COSDictionary{(COSName{img1}:COSStream{(COSName{Length}:COSInt{4933})
(COSName{Type}:COSName{XObject}) (COSName{Subtype}:COSName{Image})
(COSName{Filter}:COSName{DCTDecode}) (COSName{BitsPerComponent}:COSInt{8})
(COSName{Width}:COSInt{571}) (COSName{Height}:COSInt{386})
(COSName{ColorSpace}:COSName{DeviceRGB}) }) })
(COSName{ProcSet}:COSArray{[COSName{PDF}, COSName{Text}, COSName{ImageB},
COSName{ImageC}, COSName{ImageI}]}) }) (COSName{FormType}:COSInt{1})
(COSName{Length}:COSInt{31}) }) }) (COSName{ProcSet}:COSArray{[COSName{PDF},
COSName{Text}, COSName{ImageB}, COSName{ImageC}, COSName{ImageI}]}) })
(COSName{BBox}:COSArray{[COSFloat{100.0}, COSFloat{50.0}, COSFloat{0.0},
COSFloat{0.0}]}) (COSName{FormType}:COSInt{1}) (COSName{Length}:COSInt{26}) })
}) (COSName{ProcSet}:COSArray{[COSName{PDF}, COSName{Text}, COSName{ImageB},
COSName{ImageC}, COSName{ImageI}]}) })
(COSName{BBox}:COSArray{[COSFloat{100.0}, COSFloat{50.0}, COSFloat{0.0},
COSFloat{0.0}]}) (COSName{FormType}:COSInt{1}) (COSName{Length}:COSInt{29}) }) }
{code}
That one is called by prepareVisibleSignature, which goes through the objects
of the COSDocument visualSignature. That is the one that is closed prematurely
when options.close() is called.
So the solution must either be to clone the streams, or to do as suggested by
Rafael.
Btw the example does not close doc after calling saveIncremental().
> SignatureOptions object must not be closed before calling saveIncremental in
> trunk's CreateVisibleSignature example
> -------------------------------------------------------------------------------------------------------------------
>
> Key: PDFBOX-3010
> URL: https://issues.apache.org/jira/browse/PDFBOX-3010
> Project: PDFBox
> Issue Type: Bug
> Components: Signing
> Affects Versions: 2.0.0
> Reporter: Tilman Hausherr
> Fix For: 2.0.0
>
>
> As reported by Rafael on the user mailing list:
> {code}
> Exception in thread "main" java.io.IOException: COSStream has been closed and
> cannot be read. Perhaps its enclosing PDDocument has been closed?
> at org.apache.pdfbox.cos.COSStream.checkClosed(COSStream.java:78)
> at
> org.apache.pdfbox.cos.COSStream.createRawInputStream(COSStream.java:126)
> at
> org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:1138)
> at org.apache.pdfbox.cos.COSStream.accept(COSStream.java:372)
> at org.apache.pdfbox.cos.COSObject.accept(COSObject.java:158)
> at
> org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:538)
> at org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:450)
> at
> org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1039)
> at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:409)
> at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1289)
> at
> org.apache.pdfbox.pdmodel.PDDocument.saveIncremental(PDDocument.java:1118)
> at
> org.apache.pdfbox.examples.signature.CreateVisibleSignature.signPDF(CreateVisibleSignature.java:169)
> at
> org.apache.pdfbox.examples.signature.CreateVisibleSignature.main(CreateVisibleSignature.java:261)
> {code}
> He got rid of the exception by moving options.close() after
> doc.saveIncremental(fos))
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]