Problem is it relies on a bunch of other code, generating the file, adding
the signature field, and then signing it.
But it's basically using CreateEmptySignatureForm and
CreateVisibleSignature with the modifications I mentioned, added to
findExistingSignature.
These are the relevant changes to that function:
if (signature == null)
{
signature = new PDSignature();
// after solving PDFBOX-3524
// signatureField.setValue(signature)
// until then:
// NEW CODE STARTS HERE
COSStream s = new COSStream();
// TODO : Set the new stream's raw value
OutputStream outStream = s.createOutputStream();
String jsonString = "<x:xmpmeta
xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 5.4-c006 80.159825,
2016/09/16-03:31:08\"></x:xmpmeta>";
outStream.write(jsonString.getBytes());
outStream.close();
s.setString(COSName.TYPE, "Metadata");
s.setString(COSName.SUBTYPE, "XML");
signature.getCOSObject().setItem("Metadata", s);
// NEW CODE ENDS HERE
signatureField.getCOSObject().setItem(COSName.V,
signature);
}
On Tue, May 24, 2022 at 9:29 PM Tilman Hausherr <[email protected]>
wrote:
> Am 24.05.2022 um 21:11 schrieb Gilad Denneboom:
> > Thanks, Tilman!
> > I tried that and made some progress, but when I view the file in the PDF
> > Debugger the Metadata object is still null, although the "Length"
> property
> > now shows the right size of the string I applied... Weird, no?
> > Here's the code I added:
> >
> > OutputStream outStream = s.createOutputStream();
> > String jsonString = "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"
> x:xmptk=\"Adobe
> > XMP Core 5.4-c006 80.159825, 2016/09/16-03:31:08\"></x:xmpmeta>";
> > outStream.write(jsonString.getBytes());
> > outStream.close();
> >
> > Do you see any issues with it?
>
> It looks ok... here's the code from the PDMetadata class:
>
> public void importXMPMetadata( byte[] xmp )
> throws IOException
> {
> try (OutputStream os = createOutputStream())
> {
> os.write(xmp);
> }
> }
> }
>
> Maybe create a minimal fully (almost) working program (remove all that
> isn't relevant) and share your code.
>
> Tilman
>
>
> >
> > On Mon, May 23, 2022 at 9:03 PM Tilman Hausherr <[email protected]>
> > wrote:
> >
> >> Am 23.05.2022 um 14:56 schrieb Gilad Denneboom:
> >>> Hi all,
> >>>
> >>> I have a signed document where the Signature field's value contains a
> >>> Metadata dictionary with some info in it. I'm trying to reproduce this
> >>> using PDFBox but am having a hard time doing so.
> >>> This is what the original structure of the file looks like:
> >>> https://imgur.com/yHE3r7j
> >>>
> >>> I've used CreateVisibleSignature as my base, and manipulated its
> >>> findExistingSignature method to create the Metadata dictionary and add
> it
> >>> to the field's value, but I don't manage to set the actual contents of
> >> the
> >>> object (seen in the right-hand side of the screenshot above). This is
> the
> >>> code I added:
> >>> https://imgur.com/gC9SZwk
> >> call COSStream.createOutputStream() and then write there and close it.
> >>
> >> Tilman
> >>
> >>
> >>> The result is nearly identical to the original, just without any actual
> >>> value under the Metadata object:
> >>> https://imgur.com/86KDOC2
> >>>
> >>> It seems like I'm missing something quite basic here, so any advice
> would
> >>> be appreciated!
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>