You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Gilad Denneboom <gi...@gmail.com> on 2022/05/23 12:56:53 UTC
Setting the raw value of a COSStream
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
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!
Re: Setting the raw value of a COSStream
Posted by Gilad Denneboom <gi...@gmail.com>.
Yes, that did the trick! Thank you very much, Tilman.
On Wed, May 25, 2022 at 7:38 PM Tilman Hausherr <TH...@t-online.de>
wrote:
> I tried myself with the trunk and got an NPE, and I now used setName()
> instead of setString() for the two types.
>
>
>
>
Re: Setting the raw value of a COSStream
Posted by Tilman Hausherr <TH...@t-online.de>.
I tried myself with the trunk and got an NPE, and I now used setName()
instead of setString() for the two types.
Re: Setting the raw value of a COSStream
Posted by Gilad Denneboom <gi...@gmail.com>.
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 <TH...@t-online.de>
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 <TH...@t-online.de>
> > 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: users-unsubscribe@pdfbox.apache.org
> >> For additional commands, e-mail: users-help@pdfbox.apache.org
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
Re: Setting the raw value of a COSStream
Posted by Tilman Hausherr <TH...@t-online.de>.
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 <TH...@t-online.de>
> 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: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting the raw value of a COSStream
Posted by Gilad Denneboom <gi...@gmail.com>.
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?
On Mon, May 23, 2022 at 9:03 PM Tilman Hausherr <TH...@t-online.de>
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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
Re: Setting the raw value of a COSStream
Posted by Tilman Hausherr <TH...@t-online.de>.
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: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org