[ 
https://issues.apache.org/jira/browse/PDFBOX-3771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15990992#comment-15990992
 ] 

Tilman Hausherr commented on PDFBOX-3771:
-----------------------------------------

What you could do is to save into a {{ByteArrayOutputStream}} by changing this 
code from the example:
{code}
    public void signDetached(File inFile, File outFile, TSAClient tsaClient) 
throws IOException
    {
        if (inFile == null || !inFile.exists())
        {
            throw new FileNotFoundException("Document for signing does not 
exist");
        }

        FileOutputStream fos = new FileOutputStream(outFile);

        // sign
        try (PDDocument doc = PDDocument.load(inFile))
        {
            signDetached(doc, fos, tsaClient);
        }
    }
{code}
i.e. by changing what fos is. After that, save the content into your original 
file. (Not a good idea if power fails at the wrong monent)

> Signing example does not work if inFile = outFile
> -------------------------------------------------
>
>                 Key: PDFBOX-3771
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3771
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Signing
>    Affects Versions: 2.0.5
>         Environment: Mac, JDK8
>            Reporter: Manu Schiller
>            Priority: Minor
>
> Hi,
> I tried using the Signature example 
> (https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/signature/)
>  which works great for certifying pdfs. 
> However if I want to certify and replace the original pdf without creating a 
> new one (like foo_signed.pdf should only be foo.pdf), I get an exception:
> `Exception in thread "main" java.io.IOException: Error: End-of-File, expected 
> line pdfbox`
> I invoked the method like this (L215 of CreateSignature.java): 
> `signing.signDetached(inFile);`
> How would I change the example so that I can certify pdfs without creating 
> copy files?



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to