How itext7 java add multi signature field which using same /AP and /V - pdf

I'm new to IText7, and It took me two days to do that.
When generated a pdf have 3 pages, like
...
4 0 obj
<</Contents 5 0 R/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/TrimBox[0 0 595 842]/Type/Page>>
endobj
7 0 obj
<</Contents 8 0 R/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/TrimBox[0 0 595 842]/Type/Page>>
endobj
9 0 obj
<</Contents 10 0 R/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/TrimBox[0 0 595 842]/Type/Page>>
endobj
...
then i signed it, the pdf added some object like this
...
1 0 obj
<</AcroForm 11 0 R/Pages 2 0 R/Type/Catalog>>
endobj
9 0 obj
<</Annots[13 0 R]/Contents 10 0 R/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/TrimBox[0 0 595 842]/Type/Page>>
endobj
11 0 obj
<</Fields[13 0 R]/SigFlags 3>>
endobj
13 0 obj
<</AP<</N 18 0 R>>/F 132/FT/Sig/P 9 0 R/Rect[280.5 810 314.5 842]/Subtype/Widget/T(sig)/V 12 0 R>>
endobj
...
I notice the third page changed, it has an annots(object 13).
Now, i want modify itext code to add /Widget for each page but using same /AP and /V.Then there have same signature graphic in each page but only add signature once. like
...
4 0 obj
<</Annots[13 0 R]/Contents 5 0 R/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/TrimBox[0 0 595 842]/Type/Page>>
endobj
7 0 obj
<</Annots[14 0 R]/Contents 8 0 R/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/TrimBox[0 0 595 842]/Type/Page>>
endobj
9 0 obj
<</Annots[15 0 R]/Contents 10 0 R/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>>>/TrimBox[0 0 595 842]/Type/Page>>
endobj
13 0 obj
<</AP<</N 18 0 R>>/F 132/FT/Sig/P 4 0 R/Rect[280.5 810 314.5 842]/Subtype/Widget/T(sig)/V 12 0 R>>
endobj
14 0 obj
<</AP<</N 18 0 R>>/F 132/FT/Sig/P 7 0 R/Rect[200 400 300 420]/Subtype/Widget/T(sig)/V 12 0 R>>
endobj
15 0 obj
<</AP<</N 18 0 R>>/F 132/FT/Sig/P 9 0 R/Rect[100 200 150 480]/Subtype/Widget/T(sig)/V 12 0 R>>
endobj
11 0 obj
<</Fields[13 0 R 14 0 R 15 0 R]/SigFlags 3>>
endobj
...
I don't know if the example fits. I've read about it before, What I want is a signature with a different /Rect signature graphic on each page after a signature.
How can i do that using iText7 Java?
Can add such a signature multiple times to a PDF and pass signature verification?
After doing so, can Signature ArcoForm and field be deleted and/widgets cleared?
Can I crop Signature Graphic to show different parts on different pages?
Here's some code:
PdfDocument pdfDocument = new PdfDocument(new PdfReader(FILE));
final int pageCount = pdfDocument.getNumberOfPages();
pdfDocument.close();
PdfReader pdfReader = new PdfReader(FILE);
PdfSigner pdfSigner = new PdfSigner(pdfReader, new FileOutputStream(SIGN), new StampingProperties().useAppendMode());
File imageFile = new File(IMAGE);
java.awt.Image image = ImageIO.read(imageFile);
ImageData imageData = ImageDataFactory.create(image, null);
Rectangle rect = new Rectangle(
(pdfDocument.getDefaultPageSize().getRight() / 2) - (imageData.getWidth() / 2),
pdfDocument.getDefaultPageSize().getTop() - imageData.getHeight(),
imageData.getWidth(),
imageData.getHeight()
);
PdfSignatureAppearance appearance = pdfSigner.getSignatureAppearance();
appearance.setPageNumber(pageCount);
appearance.setSignatureGraphic(imageData);
appearance.setRenderingMode(PdfSignatureAppearance.RenderingMode.GRAPHIC);
appearance.setPageRect(rect);
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setReuseAppearance(false);
pdfSigner.setFieldName("sig");
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream(KEYSTORE), PASSWORD);
String alias = ks.aliases().nextElement();
PrivateKey pk = (PrivateKey) ks.getKey(alias, PASSWORD);
Certificate[] chain = ks.getCertificateChain(alias);
BouncyCastleProvider provider = new BouncyCastleProvider();
Security.addProvider(provider);
IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256, provider.getName());
IExternalDigest digest = new BouncyCastleDigest();
pdfSigner.signDetached(digest, pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CMS);
append:
In com.itextpdf.signatures.PdfSigner.preClose() method, i tried the following code, although successfully adding the desired object, but only the widget annotations that are added first can be shown in Adobe Reader, what should I do? the PDF I got
if (fieldExist) ... else {
PdfDictionary ap = new PdfDictionary();
for (int i = 1; i <= document.getNumberOfPages(); i++) {
PdfWidgetAnnotation widget = new PdfWidgetAnnotation(appearance.getPageRect());
widget.setFlags(PdfAnnotation.PRINT | PdfAnnotation.LOCKED);
PdfSignatureFormField sigField = PdfFormField.createSignature(document);
sigField.setFieldName(name);
sigField.put(PdfName.V, cryptoDictionary.getPdfObject());
sigField.addKid(widget);
if (this.fieldLock != null) {
this.fieldLock.getPdfObject().makeIndirect(document);
sigField.put(PdfName.Lock, this.fieldLock.getPdfObject());
fieldLock = this.fieldLock;
}
widget.setPage(document.getPage(i));
widget.put(PdfName.AP, ap);
if (1 == i)
ap.put(PdfName.N, appearance.getAppearance().getPdfObject());
acroForm.addField(sigField, document.getPage(i));
}
...
}

Related

Coordinates extracted from PDF are not exact

I'm working on rendering a georeferenced pdf within a map, I was able to retrieve the geolocation information from the pdf, but the coordinates I receive are not correct, they are a few meters apart from the places they really should be.
Opening the same PDF in Avenza Maps, it indicates this list of coordinates, and these are correct:
[-26.413082, -51.561534, -26.435838, -51.561643, -26.435909, -51.543773,-26.413152, -51.543667]
In the format I'm doing (reading the PDF as a String and doing a RegEx) I get these values:
[-26.43302 -51.56133 -26.41418 -51.56124 -26.41424 -51.54409 -26.43309 -51.54418]
[-26.45579 -51.59842 -26.41777 -51.59822 -26.41811 -51.51036 -26.45613 -51.51053]
But unfortunately none of the two reflect in the correct place (as in avenza).
That said, I opened the PDF in Notepad and found other values (more related to conversion and information), and I believe that maybe there is some way to convert the coordinates that I got through this other information, to the correct coordinates.
Follow the informations:
<?xpacket end="w"?>
endstream
endobj
294 0 obj
3495
endobj
295 0 obj
/DeviceRGB
endobj
296 0 obj
<</Length 297 0 R>>stream
/GS_init gs
/Group_6 Do
endstream
endobj
297 0 obj
24
endobj
298 0 obj
<</ExtGState 2 0 R/ColorSpace << /CS_P 295 0 R >>/XObject << /Group_6 6 0 R >>>>endobj
299 0 obj
<</Type /Group/S /Transparency/CS 295 0 R/I false/K false>>endobj
300 0 obj
<</Type /Page/Parent 301 0 R/Contents 296 0 R/Resources 298 0 R/MediaBox [0 0 841.88808 1190.5488]/ArtBox [0 0 841.88808 1190.5488]/UserUnit 1/Group 299 0 R/VP[<</Type /Viewport/BBox [14.1732 147.400915455 822.0456 1133.350548016]/Name (þÿ T S B I I)/Measure<</Type /Measure/Subtype /GEO/Bounds [0 0 0 1 1 1 1 0 0 0]/GPTS [ -26.43302 -51.56133 -26.41418 -51.56124 -26.41424 -51.54409 -26.43309 -51.54418]/LPTS [ 0 0 0 1 1 1 1 0]/GCS<</Type /PROJCS/WKT (PROJCS["SIRGAS_2000_UTM_Zone_22S",GEOGCS["GCS_SIRGAS_2000",DATUM["D_SIRGAS_2000",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",10000000.0],PARAMETER["Central_Meridian",-51.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]])>>>>>><</Type /Viewport/BBox [14.1732 14.1732 239.961243463 122.688692878]/Name (þÿ R e f e r e n c i a _ M a p a)/Measure<</Type /Measure/Subtype /GEO/Bounds [0 0 0 1 1 1 1 0 0 0]/GPTS [ -26.45579 -51.59842 -26.41777 -51.59822 -26.41811 -51.51036 -26.45613 -51.51053]/LPTS [ 0 0 0 1 1 1 1 0]/GCS<</Type /PROJCS/WKT (PROJCS["SIRGAS_2000_UTM_Zone_22S",GEOGCS["GCS_SIRGAS_2000",DATUM["D_SIRGAS_2000",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",10000000.0],PARAMETER["Central_Meridian",-51.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]])>>>>>>]>>endobj
301 0 obj
<</Type /Pages/Kids [ 300 0 R ]/Count 1>>endobj
302 0 obj
<<>>endobj
303 0 obj
<</Type /Catalog/Pages 301 0 R/PageMode /UseNone/PageLayout /SinglePage/ViewerPreferences <</PrintScaling /None /FitWindow true /DisplayDocTitle true>>/OpenAction [300 0 R /Fit]/OCProperties<</OCGs [ 10 0 R 11 0 R 12 0 R 13 0 R 14 0 R 15 0 R 16 0 R 17 0 R 18 0 R 19 0 R 20 0 R 21 0 R 22 0 R 35 0 R 36 0 R 43 0 R 44 0 R 47 0 R 50 0 R 53 0 R 56 0 R 59 0 R 62 0 R 63 0 R 64 0 R 65 0 R 66 0 R 67 0 R 68 0 R 69 0 R 76 0 R 77 0 R 80 0 R 83 0 R 90 0 R 93 0 R 96 0 R 99 0 R 102 0 R 105 0 R 108 0 R 111 0 R 114 0 R 117 0 R 120 0 R 123 0 R 126 0 R 129 0 R 132 0 R 135 0 R 138 0 R 141 0 R 148 0 R 149 0 R 152 0 R 155 0 R 158 0 R 161 0 R 176 0 R ]/D<</Name (Layers Tree)/Order [ 176 0 R 161 0 R 158 0 R 148 0 R [ 155 0 R 152 0 R 149 0 R ] 141 0 R 138 0 R 135 0 R 132 0 R 129 0 R 126 0 R 123 0 R 120 0 R 117 0 R 114 0 R 111 0 R 108 0 R 105 0 R 102 0 R 99 0 R 96 0 R 93 0 R 90 0 R 83 0 R 80 0 R 62 0 R [ 76 0 R [ 77 0 R ] 63 0 R [ 69 0 R 68 0 R 67 0 R 64 0 R [ 66 0 R 65 0 R ] ] ] 10 0 R [ 59 0 R 43 0 R [ 56 0 R 53 0 R 50 0 R 47 0 R 44 0 R ] 11 0 R [ 36 0 R 35 0 R 22 0 R 21 0 R 12 0 R [ 20 0 R 19 0 R 18 0 R 17 0 R 16 0 R 15 0 R 14 0 R 13 0 R ] ] ] ]/ListMode /VisiblePages>>>>/Metadata 293 0 R>>endobj
304 0 obj
<</Type/XRef/Size 305/W[1 4 2]/Filter/FlateDecode/Info 292 0 R/Root 303 0 R/ID [<c9167b70223726438d277b1b4409c053> <c9167b70223726438d277b1b4409c053>]/Length 923>>stream
I needed someone to tell me some way to get the correct coordinates, I hope this information helps to find
The PDF content in your question includes two ViewPort dictionaries.
These dictionaries map a location on the page ("BBox")
onto the GPTS referencing the specified WKT.
This is covered in the PDF 2.0 reference ISO-32000-2 section 12.9 & 12.10.
Unfortunately, this spec is not freely available, and it's not cheap.
Here are some definitions from the spec:
BBox:
A rectangle in default user space coordinates specifying the location of the viewport on the page.
The two coordinate pairs of the rectangle shall be specified in normalised form; that is, lower-left followed by upper-right, relative to the measuring coordinate system. This ordering shall determine the orientation of the measuring coordinate system (that is, the direction of the positive x and y axes) in this viewport, which may have a different rotation from the page.
GPTS:
(Required; PDF 2.0) An array of numbers that shall be taken pairwise, defining points in geographic space as degrees of latitude and longitude, respectively when defining a geographic coordinate system. These values shall be based on the geographic coordinate system described in the GCS dictionary. When defining a projected coordinate system, this array contains values in a planar projected coordinate space as eastings and northings. For Geospatial3D, when Geospatial feature information is present (requirement type Geospatial3D) in a 3D annotation, the GPTS array is required to hold 3D point coordinates as triples rather than pairwise where the third value of each tripe is an elevation value.
NOTE 2 Any projected coordinate system includes an underlying geographic coordinate system.
WKT:
A string of Well Known Text describing the geographic coordinate system.
The assumption is, if you're interested in Geospatial coordinates,
then you know what a WKT is, and what the projection means.
This may be enough information for you to map the geo coordinates for the
separate viewports to their locations on the page.
Here are the PDF Viewports in more readable form:
/VP [
<<
/Type
/Viewport
/BBox [14.1732 147.400915455 822.0456 1133.350548016]
/Name (TSBII)
/Measure <<
/Type
/Measure
/Subtype
/GEO
/Bounds [0 0 0 1 1 1 1 0 0 0]
/GPTS [ -26.43302 -51.56133 -26.41418 -51.56124
-26.41424 -51.54409 -26.43309 -51.54418]
/LPTS [ 0 0 0 1 1 1 1 0]
/GCS<<
/Type
/PROJCS
/WKT (
PROJCS["SIRGAS_2000_UTM_Zone_22S",
GEOGCS["GCS_SIRGAS_2000",
DATUM["D_SIRGAS_2000",SPHEROID["GRS_1980",6378137.0,298.257222101]],
PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]
],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",500000.0],
PARAMETER["False_Northing",10000000.0],
PARAMETER["Central_Meridian",-51.0],
PARAMETER["Scale_Factor",0.9996],
PARAMETER["Latitude_Of_Origin",0.0],
UNIT["Meter",1.0]
]
)
>>
>>
>>
<<
/Type
/Viewport
/BBox [14.1732 14.1732 239.961243463 122.688692878]
/Name (Referencia_Mapa)
/Measure <<
/Type
/Measure
/Subtype
/GEO
/Bounds [0 0 0 1 1 1 1 0 0 0]
/GPTS [ -26.45579 -51.59842 -26.41777 -51.59822
-26.41811 -51.51036 -26.45613 -51.51053]
/LPTS [ 0 0 0 1 1 1 1 0]
/GCS<<
/Type
/PROJCS
/WKT (
PROJCS["SIRGAS_2000_UTM_Zone_22S",
GEOGCS["GCS_SIRGAS_2000",
DATUM["D_SIRGAS_2000",SPHEROID["GRS_1980",6378137.0,298.257222101]],
PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]
],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",500000.0],
PARAMETER["False_Northing",10000000.0],
PARAMETER["Central_Meridian",-51.0],
PARAMETER["Scale_Factor",0.9996],
PARAMETER["Latitude_Of_Origin",0.0],
UNIT["Meter",1.0]])
>>
>>
>>
]
>>
Note that a PDF file is a structured document and not parsable as a string. These specific elements could be compressed, or might occur multiple times for different pages. You'll need a toolkit that can access Pages and Resources and Dictionaries in order to locate the ViewPorts.

Assigning an ExtGState to a stroke in a PDF does not work

I am trying to assign a ExtGState object to a stroke in a image stream in a pdf. The ExtGState should set the Blend Mode of the stroke. But no matter what, it does not work and the PDF Specification does not help.
I hope somebody here knows what to do.
Here is my ExtGState Object:
5 0 obj
<< /Type /ExtGState
/BM Multiply
>>
endobj
My Proc Set of the Page:
4 0 obj
<< /ProcSet [/PDF /Text]
/ExtGState << /GS1 5 0 R
>>
>>
endobj
And finally the image stream
6 0 obj
<< >>
stream
3 w
0 0 0 RG
1 J
1 j
178 2658 m
310 2322 l
S
10 w
0.13725490196078433 0.4196078431372549 0.5568627450980392 RG
1 J
1 j
/GS1 gs
[3 5] 6 d
152 2423 m
400 2600 l
S
endstream
endobj
I am using /GS1 gs in order to assign the ExtGState Object to my second stroke. The first stroke is just for checking, if the blend mode works (which does not).
Here you can find my whole pdf: https://pastebin.com/nwGBb7vB
It is supposed to look like this:
You have a syntax error in your graphics state dictionary:
5 0 obj
<< /Type /ExtGState
/BM Multiply
>>
endobj
The Multiply needs to be a PDF name object. In particular it has to start with a slash:
5 0 obj
<< /Type /ExtGState
/BM /Multiply
>>
endobj
After this change you get:

Visible Signature in a PDF file

I 'm trying to create a visible signature in a PDF file.
Taking a simple PDF "hello world" file:
%PDF-1.7
1 0 obj % entry point
<<
/Type /Catalog
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/MediaBox [ 0 0 200 200 ]
/Count 1
/Kids [ 3 0 R ]
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources <<
/Font <<
/F1 4 0 R
>>
>>
/Contents 5 0 R
>>
endobj
4 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Roman
>>
endobj
5 0 obj % page content
<<
/Length 44
>>
stream
BT
10 05 TD
/F1 12 Tf
(Hello, world!) Tj
ET
endstream
endobj
xref
0 6
0000000000 65535 f
0000000010 00000 n
0000000079 00000 n
0000000173 00000 n
0000000301 00000 n
0000000380 00000 n
trailer
<<
/Size 6
/Root 1 0 R
>>
startxref
492
%%EOF
And signing it with a text to appear "Yolo" at some position at the first page produces this:
%PDF-1.7
1 0 obj % entry point
<<
/Type /Catalog
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/MediaBox [ 0 0 200 200 ]
/Count 1
/Kids [ 3 0 R ]
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources <<
/Font <<
/F1 4 0 R
>>
>>
/Contents 5 0 R
>>
endobj
4 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Roman
>>
endobj
5 0 obj % page content
<<
/Length 44
>>
stream
BT
10 05 TD
/F1 12 Tf
(Hello, world!) Tj
ET
endstream
endobj
xref
0 6
0000000000 65535 f
0000000010 00000 n
0000000079 00000 n
0000000173 00000 n
0000000301 00000 n
0000000380 00000 n
trailer
<<
/Size 6
/Root 1 0 R
>>
startxref
492
%%EOF
8 0 obj
<</F 132/Type/Annot/Subtype/Widget/Rect[0 0 0 0]/FT/Sig/DR<<>>/T(Signature1)/V 6 0 R/P 3 0 R/AP<</N 7 0 R>>>>
endobj
6 0 obj
<</Contents <...>/Type/Sig/SubFilter/ETSI.CAdES.detached/M(D:20190626125540+00'00')/ByteRange [0 824 60826 1401]/Filter/Adobe.PPKLite>>
endobj
9 0 obj
<</BaseFont/Helvetica/Type/Font/Subtype/Type1/Encoding/WinAnsiEncoding/Name/Helv>>
endobj
10 0 obj
<</BaseFont/ZapfDingbats/Type/Font/Subtype/Type1/Name/ZaDb>>
endobj
12 0 obj
<</Length 35>>stream
BT
1 15 TD
/Helv 6 Tf
(Yolo) Tj
ET
endstream
endobj
7 0 obj
<</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0]/Length 8/FormType 1/Filter/FlateDecode>>stream
xœ
endstream
endobj
3 0 obj
<</Type/Page/Parent 2 0 R/Resources<</Font<</F1 4 0 R>>>>/Contents [12 0 R 5 0 R]/Annots[8 0 R]>>
endobj
2 0 obj
<</Type/Pages/MediaBox[0 0 200 200]/Count 1/Kids[3 0 R]>>
endobj
1 0 obj
<</AcroForm<</Fields[8 0 R]/DR<</Font<</Helv 9 0 R/ZaDb 10 0 R>>>>/DA(/Helv 0 Tf 0 g )/SigFlags 3>>/Type/Catalog/Pages 2 0 R>>
endobj
11 0 obj
<</Producer(AdES Tools https://www.turboirc.com)/ModDate(D:20190626125540+00'00')>>
endobj
xref
0 4
0000000000 65535 f
0000061604 00000 n
0000061529 00000 n
0000061414 00000 n
6 7
0000000804 00000 n
0000000000 65535 f
0000000679 00000 n
0000060952 00000 n
0000061050 00000 n
0000061746 00000 n
0000061127 00000 n
trailer
<</Root 1 0 R/Prev 492/Info 11 0 R/Size 17/ID[<4BB225C2F629BB21464F66FBF2FED264><8E3C9AD8354C66931EAAC282088455EA>]>>
startxref
61846
%%EOF
So there is an object in the PDF that shows some text in the first page:
12 0 obj
<</Length 35>>stream
BT
1 15 TD
/Helv 6 Tf
(Yolo) Tj
ET
endstream
endobj
My problem is now that this object is treated like a common text object in adobe reader. I want it, when clicked, to go to the digital signature, like how Adobe Acrobat signs the documents.
What do I miss? Is there a parameter in the digital signature (The 6 or 8 number object) or in any of the other objects my app puts in the new PDF that links the text object with the signature?
Thanks a lot.
Your object 8
8 0 obj
<</F 132/Type/Annot/Subtype/Widget/Rect[0 0 0 0]/FT/Sig/DR<<>>/T(Signature1)/V 6 0 R/P 3 0 R/AP<</N 7 0 R>>>>
endobj
is an AcroForm form field for signatures (as the FT entry with value Sig tells us). At the same time, though, this object also is a form field widget annotation (as can be seen in the Type and Subtype entries). Form field widget annotations are the visual representations of form fields, and if a form field has only one representation, the widget can be merged with the form field as in your object.
In your case the annotation has a 0x0 size (/Rect[0 0 0 0]), i.e. invisible. To have a visible representation, you need an annotation rectangle that does not vanish.
The content that is displayed is defined in the normal appearance /AP<</N 7 0 R>> which points to object 7.
7 0 obj
<</Type/XObject/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]>>/Subtype/Form/BBox[0 0 0 0]/Matrix [1 0 0 1 0 0]/Length 8/FormType 1/Filter/FlateDecode>>stream
xœ
endstream
endobj
At first glance this looks pretty empty, even after decompression.
Thus, what you have to do is
choose a non-vanishing rectangle for your signature form field annotation,
adapt the BBox of the normal appearance stream to that annotation rectangle, and
create a non-empty content in the normal appearance stream of that annotation instead of adding page content.
Furthermore you should fix obvious errors in your PDF, e.g.
object 7, your signature field normal appearance, is marked as free in your cross references
your trailer claims a size of 17
For details please study the PDF specification ISO 32000. Part 1 is published for download by Adobe at https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf
In particular sections
12.5 "Annotations"
12.7 "Interactive Forms"
12.8 "Digital Signatures"

Manually creating interactive PDFs

For reasons tedious to explain, I need to create simple PDFs from a C# application without using any third-party libraries. The PDFs in question need to include text and line drawings, and if possible should include images, radio buttons, and text fields. I've been reading Adobe's documentation, which is for the most part straightforward, but so far have been unable to figure out how to make interactive fields actually appear on the document.
For example, consider the partial test PDF document described below:
1 0 obj
<< /Type /Catalog
/Pages 2 0 R
/AcroForm 6 0 R
>>
endobj
...
6 0 obj
<< /Fields [ 7 0 R ]
/DR 5 0 R
>>
endobj
7 0 obj
<< /FT /Btn
/Ff 65536
/Kids [ 8 0 R 9 0 R ]
>>
endobj
8 0 obj
<< /Parent 7 0 R
/AS /FieldA
/AP 10 0 R
>>
endobj
9 0 obj
<< /Parent 8 0 R
/AS /FieldB
/AP 10 0 R
>>
endobj
10 0 obj
<< /N
<< /FieldA 11 0 R
/FieldB 12 0 R
/Off 13 0 R
>>
>>
endobj
11 0 obj
<< /Length 59 >>
stream
BT
/F1 12 Tf
0 0 Td
(Field A) Tj
ET
endstream
endobj
...
Where 5 0 R references a resource dictionary containing the font /F1 and 12 0 R and 13 0 R reference streams similar to 11 0 R with the string replaced by Field B and Off respectively.
What changes do I need to make to the document to cause the fields thus defined to actually appear on a page?
Edit: Since mkl asked, here's the whole pdf (extra line breaks removed to save space)
%PDF-1.7
%¥±ë
1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [0 0 200 200] >> endobj
3 0 obj << /Type /Page /Parent 2 0 R /Resources 5 0 R /Contents 4 0 R >> endobj
4 0 obj << /Length 39 >>
stream
BT /F1 12 Tf 0 0 Td (Hello World) Tj ET
endstream
endobj
5 0 obj << /Font << /F1 << /Type /Font /Subtype /Type1 /BaseFont /Helvetica >> >> >> endobj
6 0 obj << /Fields [ 7 0 R ] /DR 5 0 R >> endobj
7 0 obj << /FT /Btn /Ff 65536 /Kids [ 8 0 R 9 0 R ] >> endobj
8 0 obj << /Parent 7 0 R /AS /FieldA /AP 10 0 R >> endobj
9 0 obj << /Parent 7 0 R /AS /FieldB /AP 10 0 R >> endobj
10 0 obj << /N << /FieldA 11 0 R /FieldB 12 0 R /Off 13 0 R >> >> endobj
11 0 obj << /Length 59 >>
stream
BT /F1 12 Tf 0 0 Td (Field A) Tj ET
endstream
endobj
12 0 obj << /Length 39 >>
stream
BT /F1 12 Tf 0 0 Td (Field B) Tj ET
endstream
endobj
13 0 obj << /Length 39 >>
stream
BT /F1 12 Tf 0 0 Td (Off... ) Tj ET 94
endstream
endobj
xref
0 14
0000000000 65535 f
0000000018 00000 n
0000000068 00000 n
0000000150 00000 n
0000000233 00000 n
0000000327 00000 n
0000000420 00000 n
0000000470 00000 n
0000000533 00000 n
0000000592 00000 n
0000000651 00000 n
0000000727 00000 n
0000000821 00000 n
0000000917 00000 n
trailer << /Root 1 0 R /Size 5 >>
startxref
1013
%%EOF
Based on the full file you posted I see several issues (there might be more):
The document catalog does not include an /AcroForm entry
The page does not include an /Annots entry with links to field widgets
Field definitions 8 and 9 are incomplete, they do not include the widget annotation entries. These entries specify the field location on the page
Your field is a pushbutton, it does not have different appearance states, the /N appearance should be a reference to an appearance stream (11, 12 or 13)
Field appearances 11, 12, 13 are invalid, entries such as /Type, /Subtype, /BBox, /Resources are missing
Update: below you can find a minimum file structure for a radio button.
1 0 obj
<< /Type /Catalog /Version /1.4 /Pages 8 0 R /AcroForm <</Fields [2 0 R ]>> >>
endobj
2 0 obj
<< /FT /Btn /T (Radio) /V /Off /Kids [5 0 R 3 0 R ] /Ff 32768 >>
endobj
3 0 obj
<< /Type /Annot /F 4 /Rect [250 667 270 687 ] /Subtype /Widget /AS /Off /AP << /N << /Two 7 0 R /Off 6 0 R >> >> /Parent 2 0 R /P 4 0 R >>
endobj
4 0 obj
<< /Type /Page /Contents null /MediaBox [0 0 612 792 ] /Parent 8 0 R /Annots [5 0 R 3 0 R ] >>
endobj
5 0 obj
<< /Type /Annot /F 4 /Rect [150 667 170 687 ] /Subtype /Widget /AS /Off /AP << /N << /One 7 0 R /Off 6 0 R >> >> /Parent 2 0 R /P 4 0 R >>
endobj
6 0 obj
<< /Type /XObject /Subtype /Form /BBox [0 0 20 20 ] /Length 74 >>
stream
/DeviceRGB CS 0 0 0 SC 1 w 0.5 0.5 m 19.5 0.5 l 19.5 19.5 l 0.5 19.5 l h S
endstream
endobj
7 0 obj
<< /Type /XObject /Subtype /Form /BBox [0 0 20 20 ] /Length 55 >>
stream
/DeviceRGB cs 0 0 0 sc 0 0 m 20 0 l 20 20 l 0 20 l h f
endstream
endobj
8 0 obj
<< /Type /Pages /Count 1 /Kids [4 0 R ] >>
endobj
You can download minimum radio button sample and a more detailed radio button sample.
Using our XFINIUM.PDF Inspector you can visualize the PDF file structure.
Your fields will need to include what are known as "appearances" which are XObjects that contain the drawing instructions used to create the visual appearance of the field. See section 12.5.5 of the PDF Specification. Alternatively, you can set the NeedAppearances property of the AcroForm entry in the document catalog to true. See section 12.7.2 of the PDF specification. Setting this to true will cause a conforming viewer to create the appearances of the fields based on their properties. However, you can't count on most viewers to do this.

Is it possible to append data to a PDF page with modifying the original page object

I'm trying to append some data to a page of a PDF, by using the PDF versioning system (e.g. appending data to the end of a valid PDF with it's own XREF and what not).
Right now I'm just attempting to do a proof of concept. I can append an orange square to an existing page, but it requires me to parse out the original page object, alter the Contents array, and add that the data I'm appending. Example:
Original Page:
5 0 obj
<<
/Parent 4 0 R
/Contents[2 0 R 8 0 R 3 0 R]
/Type
/Page
/Resources
<<
/ExtGState
<<
/GSa 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/XObject
<<
/Im9 9 0 R
>>
/ColorSpace
<<
/CSp/DeviceRGB/CSpg/DeviceGray/PCSp 7 0 R
>>
/Font
<<
/F11 10 0 R
/F6 11 0 R
/Xi0 1 0 R
>>
>>
/MediaBox[0 0 595 842]
/Annots 12 0 R
>>
endobj
Modified page:
5 0 obj
<<
/Parent 4 0 R
/Contents[2 0 R 8 0 R 3 0 R 2 0 R 901 0 R 3 0 R]
/Type
/Page
/Resources
<<
/ExtGState
<<
/GSa 6 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/XObject
<<
/Im9 9 0 R
>>
/ColorSpace
<<
/CSp/DeviceRGB/CSpg/DeviceGray/PCSp 7 0 R
>>
/Font
<<
/F11 10 0 R
/F6 11 0 R
/Xi0 1 0 R
>>
>>
/MediaBox[0 0 595 842]
/Annots 12 0 R
>>
endobj
As you can see, I'm just altering the Contents array to insert my own data (an orange square with the object ID "901").
Is it possible to achieve the same result without parsing & modifying the original page object?
Since the /Contents array is a direct object, the entire page object is modified so you have to parse the page object and rewrite it with the new /Contents array.
If the /Contents would have been an indirect object then you could have modified only the array without touching the page object.