mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Update pdf-overlay-page example to copy annotations
This commit is contained in:
parent
8e8c0d8290
commit
f02aa74bf5
@ -1,5 +1,8 @@
|
||||
2021-02-22 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* Update pdf-overlay-page example to include copying of
|
||||
annotations.
|
||||
|
||||
* Add a new version of QPDFPageObjectHelper::placeFormXObject that
|
||||
initializes the transformation matrix that was used so you don't
|
||||
have to call both placeFormXObject and
|
||||
|
@ -56,9 +56,10 @@ static void stamp_page(char const* infile,
|
||||
|
||||
// Generate content to place the form XObject centered within
|
||||
// destination page's trim box.
|
||||
QPDFMatrix m;
|
||||
std::string content =
|
||||
ph.placeFormXObject(
|
||||
stamp_fo, name, ph.getTrimBox().getArrayAsRectangle());
|
||||
stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m);
|
||||
if (! content.empty())
|
||||
{
|
||||
// Append the content to the page's content. Surround the
|
||||
@ -72,6 +73,11 @@ static void stamp_page(char const* infile,
|
||||
ph.addPageContents(
|
||||
QPDFObjectHandle::newStream(&inpdf, "\nQ\n" + content), false);
|
||||
}
|
||||
// Copy the annotations and form fields from the original page
|
||||
// to the new page. For more efficiency when copying multiple
|
||||
// pages, we can create a QPDFAcroFormDocumentHelper and pass
|
||||
// it in. See comments in QPDFPageObjectHelper.hh for details.
|
||||
ph.copyAnnotations(stamp_page_1, m);
|
||||
}
|
||||
|
||||
QPDFWriter w(inpdf, outfile);
|
||||
|
@ -18,9 +18,16 @@ $td->runtest("compare files",
|
||||
{$td->FILE => "a.pdf"},
|
||||
{$td->FILE => "out.pdf"});
|
||||
|
||||
$td->runtest("overlay-page with fields/ annotations",
|
||||
{$td->COMMAND => "pdf-overlay-page in.pdf annotations.pdf a.pdf"},
|
||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||
$td->runtest("compare files",
|
||||
{$td->FILE => "a.pdf"},
|
||||
{$td->FILE => "annotations-out.pdf"});
|
||||
|
||||
cleanup();
|
||||
|
||||
$td->report(2);
|
||||
$td->report(4);
|
||||
|
||||
sub cleanup
|
||||
{
|
||||
|
702
examples/qtest/overlay-page/annotations-out.pdf
Normal file
702
examples/qtest/overlay-page/annotations-out.pdf
Normal file
@ -0,0 +1,702 @@
|
||||
%PDF-1.4
|
||||
%¿÷¢þ
|
||||
1 0 obj
|
||||
<< /AcroForm 3 0 R /Pages 4 0 R /Type /Catalog >>
|
||||
endobj
|
||||
2 0 obj
|
||||
<< /CreationDate (D:20120721200217) /Producer (Apex PDFWriter) >>
|
||||
endobj
|
||||
3 0 obj
|
||||
<< /Fields [ 5 0 R 6 0 R 7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 12 0 R 13 0 R 14 0 R 15 0 R 16 0 R ] >>
|
||||
endobj
|
||||
4 0 obj
|
||||
<< /Count 4 /Kids [ 17 0 R 18 0 R 19 0 R 20 0 R ] /Type /Pages >>
|
||||
endobj
|
||||
5 0 obj
|
||||
<< /AP << /N 21 0 R >> /DA (0 0.4 0 rg /F1 18 Tf) /DR 22 0 R /DV () /FT /Tx /Ff 0 /Rect [ 72 470.774 190.8 484.922 ] /Subtype /Widget /T (Text Box 1) /Type /Annot /V (Formy field) >>
|
||||
endobj
|
||||
6 0 obj
|
||||
<< /AP << /N 23 0 R >> /DA (0 0.4 0 rg /F1 18 Tf) /DR 22 0 R /DV () /FT /Tx /Ff 0 /Rect [ 372 330.774 386.148 470.374 ] /Subtype /Widget /T (Text Box 1) /Type /Annot /V (Rot-ccw field) >>
|
||||
endobj
|
||||
7 0 obj
|
||||
<< /DV /1 /FT /Btn /Ff 49152 /Kids [ 24 0 R 25 0 R 26 0 R ] /T (r1) /V /2 >>
|
||||
endobj
|
||||
8 0 obj
|
||||
<< /AP << /N 27 0 R >> /DA (0 0.4 0 rg /F1 18 Tf) /DR 22 0 R /DV () /FT /Tx /Ff 0 /Rect [ 72 470.774 190.8 484.922 ] /Subtype /Widget /T (Text Box 1) /Type /Annot /V (Formy field) >>
|
||||
endobj
|
||||
9 0 obj
|
||||
<< /AP << /N 28 0 R >> /DA (0 0.4 0 rg /F1 18 Tf) /DR 22 0 R /DV () /FT /Tx /Ff 0 /Rect [ 372 330.774 386.148 470.374 ] /Subtype /Widget /T (Text Box 1) /Type /Annot /V (Rot-ccw field) >>
|
||||
endobj
|
||||
10 0 obj
|
||||
<< /DV /1 /FT /Btn /Ff 49152 /Kids [ 29 0 R 30 0 R 31 0 R ] /T (r1) /V /2 >>
|
||||
endobj
|
||||
11 0 obj
|
||||
<< /AP << /N 32 0 R >> /DA (0 0.4 0 rg /F1 18 Tf) /DR 22 0 R /DV () /FT /Tx /Ff 0 /Rect [ 72 470.774 190.8 484.922 ] /Subtype /Widget /T (Text Box 1) /Type /Annot /V (Formy field) >>
|
||||
endobj
|
||||
12 0 obj
|
||||
<< /AP << /N 33 0 R >> /DA (0 0.4 0 rg /F1 18 Tf) /DR 22 0 R /DV () /FT /Tx /Ff 0 /Rect [ 372 330.774 386.148 470.374 ] /Subtype /Widget /T (Text Box 1) /Type /Annot /V (Rot-ccw field) >>
|
||||
endobj
|
||||
13 0 obj
|
||||
<< /DV /1 /FT /Btn /Ff 49152 /Kids [ 34 0 R 35 0 R 36 0 R ] /T (r1) /V /2 >>
|
||||
endobj
|
||||
14 0 obj
|
||||
<< /AP << /N 37 0 R >> /DA (0 0.4 0 rg /F1 18 Tf) /DR 22 0 R /DV () /FT /Tx /Ff 0 /Rect [ 72 470.774 190.8 484.922 ] /Subtype /Widget /T (Text Box 1) /Type /Annot /V (Formy field) >>
|
||||
endobj
|
||||
15 0 obj
|
||||
<< /AP << /N 38 0 R >> /DA (0 0.4 0 rg /F1 18 Tf) /DR 22 0 R /DV () /FT /Tx /Ff 0 /Rect [ 372 330.774 386.148 470.374 ] /Subtype /Widget /T (Text Box 1) /Type /Annot /V (Rot-ccw field) >>
|
||||
endobj
|
||||
16 0 obj
|
||||
<< /DV /1 /FT /Btn /Ff 49152 /Kids [ 39 0 R 40 0 R 41 0 R ] /T (r1) /V /2 >>
|
||||
endobj
|
||||
17 0 obj
|
||||
<< /Annots [ 42 0 R 5 0 R 43 0 R 6 0 R 44 0 R 45 0 R 46 0 R 47 0 R 24 0 R 25 0 R 26 0 R ] /Contents [ 48 0 R 49 0 R 50 0 R ] /MediaBox [ 0 0 612 792 ] /Parent 4 0 R /Resources << /Font << /F1 51 0 R >> /ProcSet [ /PDF /Text ] /XObject << /Fx1 52 0 R >> >> /Type /Page >>
|
||||
endobj
|
||||
18 0 obj
|
||||
<< /Annots [ 53 0 R 8 0 R 54 0 R 9 0 R 55 0 R 56 0 R 57 0 R 58 0 R 29 0 R 30 0 R 31 0 R ] /Contents [ 59 0 R 60 0 R 61 0 R ] /MediaBox [ 0 0 612 792 ] /Parent 4 0 R /Resources << /Font << /F1 51 0 R >> /ProcSet [ /PDF /Text ] /XObject << /Fx1 52 0 R >> >> /Type /Page >>
|
||||
endobj
|
||||
19 0 obj
|
||||
<< /Annots [ 62 0 R 11 0 R 63 0 R 12 0 R 64 0 R 65 0 R 66 0 R 67 0 R 34 0 R 35 0 R 36 0 R ] /Contents [ 68 0 R 69 0 R 70 0 R ] /MediaBox [ 0 0 612 792 ] /Parent 4 0 R /Resources << /Font << /F1 51 0 R >> /ProcSet [ /PDF /Text ] /XObject << /Fx1 52 0 R >> >> /Type /Page >>
|
||||
endobj
|
||||
20 0 obj
|
||||
<< /Annots [ 71 0 R 14 0 R 72 0 R 15 0 R 73 0 R 74 0 R 75 0 R 76 0 R 39 0 R 40 0 R 41 0 R ] /Contents [ 77 0 R 78 0 R 79 0 R ] /MediaBox [ 0 0 612 792 ] /Parent 4 0 R /Resources << /Font << /F1 51 0 R >> /ProcSet [ /PDF /Text ] /XObject << /Fx1 52 0 R >> >> /Type /Page >>
|
||||
endobj
|
||||
21 0 obj
|
||||
<< /BBox [ 0 -2.826 118.8 11.322 ] /Matrix [ 1 0 0 1 0 0 ] /Resources 22 0 R /Subtype /Form /Type /XObject /Length 58 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœÓ©Ppòuæ*är
|
||||
áRPÐw3T0´PI²5Üò‹r+Ò2SsR4B²¸\C¸¹\<5C>ŠVÙíendstream
|
||||
endobj
|
||||
22 0 obj
|
||||
<< /Font << /F1 80 0 R >> >>
|
||||
endobj
|
||||
23 0 obj
|
||||
<< /BBox [ 0 -2.826 140.4 11.322 ] /Matrix [ 0 1 -1 0 0 0 ] /Resources 22 0 R /Subtype /Form /Type /XObject /Length 60 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœÓ©Ppòuæ*är
|
||||
áRPÐw3T0´PI²5‚òKt““ËÒ2SsR4B²¸\C¸¹\<5C>ÊrP
endstream
|
||||
endobj
|
||||
24 0 obj
|
||||
<< /AP << /N << /1 81 0 R /Off 82 0 R >> >> /AS /1 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 7 0 R /Rect [ 152.749 648.501 164.801 660.549 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
25 0 obj
|
||||
<< /AP << /N << /2 84 0 R /Off 85 0 R >> >> /AS /2 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 7 0 R /Rect [ 152.749 627.301 164.801 639.349 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
26 0 obj
|
||||
<< /AP << /N << /3 86 0 R /Off 87 0 R >> >> /AS /3 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 7 0 R /Rect [ 151.399 606.501 163.451 618.549 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
27 0 obj
|
||||
<< /BBox [ 0 -2.826 118.8 11.322 ] /Matrix [ 1 0 0 1 0 0 ] /Resources 22 0 R /Subtype /Form /Type /XObject /Length 58 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœÓ©Ppòuæ*är
|
||||
áRPÐw3T0´PI²5Üò‹r+Ò2SsR4B²¸\C¸¹\<5C>ŠVÙíendstream
|
||||
endobj
|
||||
28 0 obj
|
||||
<< /BBox [ 0 -2.826 140.4 11.322 ] /Matrix [ 0 1 -1 0 0 0 ] /Resources 22 0 R /Subtype /Form /Type /XObject /Length 60 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœÓ©Ppòuæ*är
|
||||
áRPÐw3T0´PI²5‚òKt““ËÒ2SsR4B²¸\C¸¹\<5C>ÊrP
endstream
|
||||
endobj
|
||||
29 0 obj
|
||||
<< /AP << /N << /1 88 0 R /Off 89 0 R >> >> /AS /1 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 10 0 R /Rect [ 152.749 648.501 164.801 660.549 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
30 0 obj
|
||||
<< /AP << /N << /2 90 0 R /Off 91 0 R >> >> /AS /2 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 10 0 R /Rect [ 152.749 627.301 164.801 639.349 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
31 0 obj
|
||||
<< /AP << /N << /3 92 0 R /Off 93 0 R >> >> /AS /3 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 10 0 R /Rect [ 151.399 606.501 163.451 618.549 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
32 0 obj
|
||||
<< /BBox [ 0 -2.826 118.8 11.322 ] /Matrix [ 1 0 0 1 0 0 ] /Resources 22 0 R /Subtype /Form /Type /XObject /Length 58 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœÓ©Ppòuæ*är
|
||||
áRPÐw3T0´PI²5Üò‹r+Ò2SsR4B²¸\C¸¹\<5C>ŠVÙíendstream
|
||||
endobj
|
||||
33 0 obj
|
||||
<< /BBox [ 0 -2.826 140.4 11.322 ] /Matrix [ 0 1 -1 0 0 0 ] /Resources 22 0 R /Subtype /Form /Type /XObject /Length 60 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœÓ©Ppòuæ*är
|
||||
áRPÐw3T0´PI²5‚òKt““ËÒ2SsR4B²¸\C¸¹\<5C>ÊrP
endstream
|
||||
endobj
|
||||
34 0 obj
|
||||
<< /AP << /N << /1 94 0 R /Off 95 0 R >> >> /AS /1 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 13 0 R /Rect [ 152.749 648.501 164.801 660.549 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
35 0 obj
|
||||
<< /AP << /N << /2 96 0 R /Off 97 0 R >> >> /AS /2 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 13 0 R /Rect [ 152.749 627.301 164.801 639.349 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
36 0 obj
|
||||
<< /AP << /N << /3 98 0 R /Off 99 0 R >> >> /AS /3 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 13 0 R /Rect [ 151.399 606.501 163.451 618.549 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
37 0 obj
|
||||
<< /BBox [ 0 -2.826 118.8 11.322 ] /Matrix [ 1 0 0 1 0 0 ] /Resources 22 0 R /Subtype /Form /Type /XObject /Length 58 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœÓ©Ppòuæ*är
|
||||
áRPÐw3T0´PI²5Üò‹r+Ò2SsR4B²¸\C¸¹\<5C>ŠVÙíendstream
|
||||
endobj
|
||||
38 0 obj
|
||||
<< /BBox [ 0 -2.826 140.4 11.322 ] /Matrix [ 0 1 -1 0 0 0 ] /Resources 22 0 R /Subtype /Form /Type /XObject /Length 60 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœÓ©Ppòuæ*är
|
||||
áRPÐw3T0´PI²5‚òKt““ËÒ2SsR4B²¸\C¸¹\<5C>ÊrP
endstream
|
||||
endobj
|
||||
39 0 obj
|
||||
<< /AP << /N << /1 100 0 R /Off 101 0 R >> >> /AS /1 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 16 0 R /Rect [ 152.749 648.501 164.801 660.549 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
40 0 obj
|
||||
<< /AP << /N << /2 102 0 R /Off 103 0 R >> >> /AS /2 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 16 0 R /Rect [ 152.749 627.301 164.801 639.349 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
41 0 obj
|
||||
<< /AP << /N << /3 104 0 R /Off 105 0 R >> >> /AS /3 /DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf) /DR << /Font << /ZaDi 83 0 R >> >> /F 4 /FT /Btn /MK << /CA (l) >> /Parent 16 0 R /Rect [ 151.399 606.501 163.451 618.549 ] /Subtype /Widget /Type /Annot >>
|
||||
endobj
|
||||
42 0 obj
|
||||
<< /A << /S /URI /URI (https://www.qbilt.org/) >> /Border [ 0 0 .4 ] /C [ .8 .6 .6 ] /H /I /Rect [ 72 501.832 374.4 520.696 ] /Subtype /Link /Type /Annot >>
|
||||
endobj
|
||||
43 0 obj
|
||||
<< /AP << /N 106 0 R >> /Contents (attachment1.txt) /FS 107 0 R /NM (attachment1.txt) /Rect [ 72 400 92 420 ] /Subtype /FileAttachment /Type /Annot >>
|
||||
endobj
|
||||
44 0 obj
|
||||
<< /AP << /N 108 0 R >> /DA () /Rect [ 72 350 92 360 ] /Subtype /FreeText /Type /Annot >>
|
||||
endobj
|
||||
45 0 obj
|
||||
<< /AP << /N 109 0 R >> /DA () /Rect [ 102 350 112 370 ] /Subtype /FreeText /Type /Annot >>
|
||||
endobj
|
||||
46 0 obj
|
||||
<< /AP << /N 110 0 R >> /DA () /Rect [ 122 350 142 360 ] /Subtype /FreeText /Type /Annot >>
|
||||
endobj
|
||||
47 0 obj
|
||||
<< /AP << /N 111 0 R >> /DA () /Rect [ 152 350 162 370 ] /Subtype /FreeText /Type /Annot >>
|
||||
endobj
|
||||
48 0 obj
|
||||
<< /Length 10 /Filter /FlateDecode >>
|
||||
stream
|
||||
xœ+ä |