0

I would like to generate in Java a XFDF Stamp Annotation that would have a transparent image inside. I have serious trouble recognizing the format in which the image is stored and how to transform my input image to that form.

So far I know

  • The stamp element is a child of the annots element and corresponds to the Rubber Stamp annotation. A Rubber Stamp annotation displays text or graphics intended to look as if they were stamped on the page with a rubber stamp. If present, the appearance child element (the AP key in the annotation dictionary) takes precedence over the icon attribute (Name key in the rubber stamp annotation dictionary). Content model ( contents-richtext? & contents? & appearance? & popup? )
  • The appearance element is a child of the stamp element and corresponds to the AP key in the annotation dictionary. The value is a base 64 encoded string. Content model Base 64 encoded string. Attributes None.

I have an example XFDF which contains an image, when I decode the image I get to see a syntax like this, but sadly I have no idea what kind of raw data is present in <DATA MODE="RAW" ENCODING="HEX"> tag.

<DICT KEY="AP">
<STREAM KEY="N">
    <ARRAY KEY="BBox">
        <FIXED VAL="250"/>
        <FIXED VAL="550"/>
        <FIXED VAL="400"/>
        <FIXED VAL="575"/>
</ARRAY>
    <INT KEY="FormType" VAL="1"/>
    <INT KEY="Length" VAL="35"/>
    <DICT KEY="Resources">
        <DICT KEY="XObject">
            <STREAM KEY="Im1">
                <INT KEY="BitsPerComponent" VAL="8"/>
                <NAME KEY="ColorSpace" VAL="DeviceRGB"/>
                <NAME KEY="Filter" VAL="FlateDecode"/>
                <INT KEY="Height" VAL="150"/>
                <INT KEY="Length" VAL="1907"/>
                <STREAM KEY="SMask">
                    <INT KEY="BitsPerComponent" VAL="8"/>
                    <NAME KEY="ColorSpace" VAL="DeviceGray"/>
                    <NAME KEY="Filter" VAL="FlateDecode"/>
                    <INT KEY="Height" VAL="150"/>
                    <INT KEY="Length" VAL="5690"/>
                    <NAME KEY="Subtype" VAL="Image"/>
                    <NAME KEY="Type" VAL="XObject"/>
                    <INT KEY="Width" VAL="300"/>
                    <DATA MODE="RAW" ENCODING="HEX">

I have managed to create a Rubber Stamp Annotation with custom Image in a PDF with the help of PDFBox, but sadly PDFBox does not seem to support exporting this kind of annotation to XFDF, they support only exporting from Forms(AcroForm). I don't know any other tool in Java that will allow me to export it, except the paid ones.

Javo
  • 435
  • 1
  • 5
  • 16

3 Answers3

2

It's a HEX representation of DCT format (JPEG). If want a transparent image stamp you'll have a two of these things in your XFDF, the image itself and the mask.

joelgeraci
  • 4,606
  • 1
  • 12
  • 19
  • Is it the only format supported or you assumed it from the example content? Could you please point me to a documentation to this? – Javo Oct 07 '16 at 08:59
  • I assumed it based on a sample that I made by creating a custom stamp from a PNG file using Acrobat DC. The documentation for XFDF is at the link below https://partners.adobe.com/public/developer/en/xml/XFDF_Spec_3.0.pdf – joelgeraci Oct 07 '16 at 14:41
  • I have tried to convert Base64 to text, convert Hex to text and save it as a jpg and it did not worked. But I admit that I could have made a faulty conversion. The specification you've pointed me at does not say much about the format. – Javo Oct 07 '16 at 14:46
  • I hit enter too soon. Here's the full comment... I assumed it based on a sample that I made by creating a custom stamp from a PNG file using Acrobat DC. I imagine any of the stream encodings for images could work but even Acrobat doesn't necessarily support everything that is possible in the spec, in my experience, it's best to follow what Acrobat *does* not what the spec *says*. The documentation for XFDF is at the link below. https://partners.adobe.com/public/developer/en/xml/XFDF_Spec_3.0.pdf – joelgeraci Oct 07 '16 at 14:48
  • I know this is an old post. Could someone please tell me, How can I convert a HEX representation of a DCT format (JPEG) to IRandomAccessStream in C#? (UWP) – Gayashan Rathnavibhushana Oct 18 '20 at 09:52
1

Add a stamp element that looks like this:

<stamp creationdate="D:20200422160322Z" flags="print" date="D:20200422160322Z" icon="Unknown" page="0" rect="276.675,778.525,318.325,841">
  <imagedata>data:image/png;base64,iVBORw0 . . . FTkSuQmCC</imagedata>
  <apref y="841" x="276.675" gennum="2" objnum="198" />
</stamp>
Brian THOMAS
  • 482
  • 1
  • 5
  • 19
0

The XFDF specs does not explain what those dict tags are for. Guess they left out a crucial part of information.

This thread saved me time to figure out why the resulting base 64 image does not get imported into Acrobat. So it is an XML of XOjbect.

Maybe the acrobat PDF specs mention this.

chitgoks
  • 311
  • 2
  • 6
  • 17