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

Tilman Hausherr commented on PDFBOX-4554:
-----------------------------------------

You could also do this:
{code:java}
FileInputStream fis = new FileInputStream(infile);
byte[] ba = IOUtils.toByteArray(new FileInputStream(infile));
fis.close();
RandomAccessBuffer rab = new RandomAccessBuffer(ba);
PDFParser parser = new PDFParser(rab, password);
parser.setLenient(false);
parser.parse();
PDDocument document = parser.getPDDocument();
....
byte[] buf = sig.getSignedContent(ba);
{code}
This works fine even if the file has several revisions, I tested it with a file 
that has been signed twice. There isn't any need to tell where the file ends.

However your comment made me aware that ShowSignature is inefficient, as it 
reads the file several times. I'll add a comment mentioning my code above, and 
also improve the javadoc of {{getSignedContent(InputStream pdfFile)}} because 
it closes the input and this isn't documented. (Which is annoying, but I can't 
change it, as it would break the API)

RandomAccessBufferedFileInputStream.java doesn't work with byte arrays or 
inputstreams at all. For byte array there is RandomAccessBuffer, for 
InputStream there is {{ScratchFile.createBuffer(input)}} which may indeed 
create a temp file depending on how ScratchFile is constructed.

Re feedback for the patch: all this is the feedback. The formal things are 
fine. My problem is that I don't see the need, and I'm trying to find out 
whether I missed something or not.

> operations taking a byte[] need to allow for offset and length too
> ------------------------------------------------------------------
>
>                 Key: PDFBOX-4554
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4554
>             Project: PDFBox
>          Issue Type: Improvement
>            Reporter: Jason Pyeron
>            Priority: Major
>
> Without this, massive amounts of memory must be copied/allocated to "trim" 
> byte[].
> See forthcoming pull request.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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

Reply via email to