You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Rafael <ra...@gmail.com> on 2015/10/07 19:59:24 UTC

SignatureOptions object must not be closed before calling saveIncremental in trunk's CreateVisibleSignature example

Hi,

Otherwise, you will get:

...
org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDFTemplateCreator
buildPDF
INFO: stream returning started, size= 11019
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 CreateVisibleSignature.signPDF(CreateVisibleSignature.java:169)
at CreateVisibleSignature.main(CreateVisibleSignature.java:256)

Moreover. Two questions:

1) Once I got rid of that IOE (by moving options.close() after
doc.saveIncremental(cos)), I found that the example produces a corrupted
signed pdf. The Signature Panel says:

Rev. 1: Signed by signer name
Signature is invalid:
There are errors in the formatting or information contained in this
signature (support information: SigDict /Contents illegal data)
Signer's identity has not yet been verified
Signing time is from the clock on the signer's computer.
Last checked: 2015.10.07 19:41:53 +02'00'
Field: Signature1 on page 1

I couldn't find the reason for that. Any ideas about what's wrong with the
example apart from that options closing?

2)  After a while I decided to create my own example (SignPDFPoC) by
combining trunk CreateSignature and CreateVisibleSignature. With my
example, I get a valid pdf after signing. Strange, cause it is just a "mix"
of those 2 trunk examples. However, the Signature Panel always shows:

Field: Signature1 on page 1

I thought that PDVisibleSignDesigner.signatureFieldName was used for that
purposes. But it does not seem to be the case. Moreover, for invisible
signatures, no PDVisibleSignDesigner is used, so there must be a different
way.

So the question is: how can I set the value of "Field" shown by Signature
Panel for both invisible and visible signatures?

Br, Rafael

Re: SignatureOptions object must not be closed before calling saveIncremental in trunk's CreateVisibleSignature example

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi, I've reproduced the first problem and opened

https://issues.apache.org/jira/browse/PDFBOX-3010

Tilman

Am 07.10.2015 um 19:59 schrieb Rafael:
> Hi,
>
> Otherwise, you will get:
>
> ...
> org.apache.pdfbox.pdmodel.interactive.digitalsignature.visible.PDFTemplateCreator
> buildPDF
> INFO: stream returning started, size= 11019
> 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 CreateVisibleSignature.signPDF(CreateVisibleSignature.java:169)
> at CreateVisibleSignature.main(CreateVisibleSignature.java:256)
>
> Moreover. Two questions:
>
> 1) Once I got rid of that IOE (by moving options.close() after
> doc.saveIncremental(cos)), I found that the example produces a corrupted
> signed pdf. The Signature Panel says:
>
> Rev. 1: Signed by signer name
> Signature is invalid:
> There are errors in the formatting or information contained in this
> signature (support information: SigDict /Contents illegal data)
> Signer's identity has not yet been verified
> Signing time is from the clock on the signer's computer.
> Last checked: 2015.10.07 19:41:53 +02'00'
> Field: Signature1 on page 1
>
> I couldn't find the reason for that. Any ideas about what's wrong with the
> example apart from that options closing?
>
> 2)  After a while I decided to create my own example (SignPDFPoC) by
> combining trunk CreateSignature and CreateVisibleSignature. With my
> example, I get a valid pdf after signing. Strange, cause it is just a "mix"
> of those 2 trunk examples. However, the Signature Panel always shows:
>
> Field: Signature1 on page 1
>
> I thought that PDVisibleSignDesigner.signatureFieldName was used for that
> purposes. But it does not seem to be the case. Moreover, for invisible
> signatures, no PDVisibleSignDesigner is used, so there must be a different
> way.
>
> So the question is: how can I set the value of "Field" shown by Signature
> Panel for both invisible and visible signatures?
>
> Br, Rafael
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: SignatureOptions object must not be closed before calling saveIncremental in trunk's CreateVisibleSignature example

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 07.10.2015 um 19:59 schrieb Rafael:
> Field: Signature1 on page 1
>
> I thought that PDVisibleSignDesigner.signatureFieldName was used for that
> purposes. But it does not seem to be the case. Moreover, for invisible
> signatures, no PDVisibleSignDesigner is used, so there must be a different
> way.
>
> So the question is: how can I set the value of "Field" shown by Signature
> Panel for both invisible and visible signatures?

I think the above is the only unanswered question left.

It is set by PDDocument.addSignature, which calls new PDSignatureField() 
if a signature field doesn't exist already, and that one sets it. (see 
the private method findSignatureField for how to do it)

If you manage to get the PDSignature field object, you can call 
setPartialName().

Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: SignatureOptions object must not be closed before calling saveIncremental in trunk's CreateVisibleSignature example

Posted by Rafael <ra...@gmail.com>.
Done. Please have a look at PDFBOX-3011
<https://issues.apache.org/jira/browse/PDFBOX-3011>

Br, Rafael

On Thu, Oct 8, 2015 at 1:29 AM, Tilman Hausherr <TH...@t-online.de>
wrote:

> Am 07.10.2015 um 19:59 schrieb Rafael:
>
>> 2)  After a while I decided to create my own example (SignPDFPoC) by
>> combining trunk CreateSignature and CreateVisibleSignature. With my
>> example, I get a valid pdf after signing. Strange, cause it is just a
>> "mix"
>> of those 2 trunk examples.
>>
>
> Could you open another issue in JIRA, and attach your code, a "bad signed"
> file, and a "good signed" file?
>
> Tilman
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: SignatureOptions object must not be closed before calling saveIncremental in trunk's CreateVisibleSignature example

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 07.10.2015 um 19:59 schrieb Rafael:
> 2)  After a while I decided to create my own example (SignPDFPoC) by
> combining trunk CreateSignature and CreateVisibleSignature. With my
> example, I get a valid pdf after signing. Strange, cause it is just a "mix"
> of those 2 trunk examples.

Could you open another issue in JIRA, and attach your code, a "bad 
signed" file, and a "good signed" file?

Tilman



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org