javaimagepdfxfdfpdf-annotations

How to create XFDF annotation with an image


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

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.


Solution

  • 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.