How to convert PDF Stamp Annotation if FDF to Image for use in Browser
I am working on the display of PDF documents in a browser via use of annotation data extracted from the data exported from the PDF to and FDF. I have had success with all the basic shapes and such, polyline, polygon, squiggle but I am stuck on how to get the Image for the stamp in a readable format for display. The end goal is to just dispaly the markups in the browser, no edit allowed. Here is what I see in the FDF file for the Stamp;
%FDF-1.2 %âãÏÓ
1 0 obj <</FDF<</Annots[2 0 R 3 0 R]/F(/D/workdir/du/svv6w167_aw50_12x_0103/FDF2AWMarkup/test.pdf)/ID[<1275CF6A0612174282FFD089B676446C><0BB42BE7EDDB3F4D91F4AF22EF2F59F7>]/UF(/D/workdir/du/svv6w167_aw50_12x_0103/FDF2AWMarkup/test.pdf)>>/Type/Catalog>> endobj 2 0 obj <</AP<</N 4 0 R>>/C[0.898026 0.133331 0.215683]/Contents(Test Approved Stamp)/CreationDate(D:20200113104506-06'00')/F 4/M(D:20200113104519-06'00')/NM(4c93a65e-c235-446d-96e7-5677a4a37f92)/Name/SBApproved/Page 0/Popup 3 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:19.21.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.5pt;text-align:left;color:#000000;font-\ weight:normal;font-style:normal">Test Approved Stamp</span></p></body>)/Rect[104.142 563.031 267.641 612.531]/Subj(Approved)/Subtype/Stamp/T(tomaszew)/Type/Annot>> endobj 3 0 obj <</F 28/Open false/Page 0/Parent 2 0 R/Rect[612.0 498.531 816.0 612.531]/Subtype/Popup/Type/Annot>> endobj 4 0 obj <</BBox[157.551 370.547 321.051 420.047]/Filter[/FlateDecode]/FormType 1/Group 5 0 R/Length 2402/Matrix[1.0 0.0 0.0 1.0 -157.551 -370.547]/Name/FRM/Resources<</ColorSpace<</CS0 15 0 R/CS1 16 0 R/CS2 17 0 R>>/ExtGState<</GS0 13 0 R/GS1 14 0 R>>/Pattern<</P0 6 0 R>>>>/Subtype/Form/Type/XObject>>stream
H‰lWËn[ÉÝà?Üe²¹ê®Ww/b2ˆcfcx¡Ð´Ã€’'’<ƒùûœê¾äíKi!ˆ<ìGÕ©Sþß«›·ßößï÷OOß›~øáæÝí×Ã?Ž_÷ÓGNçéÓÍûï§ÃÃLSš>½~ýöÝîæ·bÓ/ǧÓaúKÿžÿzóëññøo OßÓÍ»‡ÃïÇÃË·?ŸnÇ÷O‡ÏË··Ç»;|ùr{zÄ·7ßNߦ”ˆdb*V'Se…I_N·Oýºeí/·÷¿Ý>î÷.Øë×{ûfžž÷Óþ·¥éq¿KÓqÚݼ?àãï‡vÍñîðôpÜOÇÝÍOÒôõqǹÎ,TÊÄÅgwÔæ,ª,éläµãe%gš9ãó€íwÙl®%'ÐPžUÕl@³¥¹^Ý3b>œyF%§Ù/g®¨Ì$šiZï‘lËÊÕ¢ÛïVëWô´[ý\Ñ•õžKÙÏù<íþ³û²K3¬-uJ3i„ÿ©$õéýO»<ý1Éô3D÷_üý}úø)MŸ§ˆQ>Ç(iì3U¶ÝmPƒM5i‹s©ù¾2¼qÙ€õiqWö‘Áï Ž*Ã=#æÃ™gTrž“¶%FgTÀMÉeZï‘\–•«E+ÖcÔ_Ñ£î犮|¬÷ŒXÎ|ÎgÄèÃ.b#ŽÐHV‹PA2uzøºË!Oø º*¶XRE2Hª…ƒø*8þL"V¤Â´EK+‹€†¤3•ŠßÆŠâù
Ïž”·T0‘œêšg»2ìô¢¹}UðâV•=œ
knó2«y[M×:ö:-YXâÖ‚"Ú š+>IÊX–ÀÞ¾m.ÌžÚ$ÍÊËvð_2…^qK¥T„bh2˜ƒKAÀ)ñ`úËõdËžÃTÐ)IæêÞ<Å¢¬)2;Ø–’ D×ÐyÄ- 0TçT&ÀB#RP‚# Æzü2%|"¸ìV¢.àê¯vÃtÄ7{ |SìÆïHªÆ’ZVZ!vÄ-G†ÄÞÃØ„±ŽfçÜX’‰¬],ZpJ°¡äܬvø‚´H3[þ•Ù´Z°Ž‹EœÌ¬›#àãBSÆÀŒ«‰<›å¼`æËn”W5¿–1
¤zµ-ú<^§v=U±/¬«…r‹"NîÖPròEÔí+!dm`Ø¢6`=Šœ#Æ•>;ÙB°;›n0G…ËŽEÀ²"O§8O]ÍÀjf©ßÄa÷ŠÅndµ9²z\©ð%ľ&J‹„Q_fµèˆk&ºÐ)Ð…Ž2
LÆv„NQ ±[Gù¢¸V¤¯l„N(ŸLÞ¬Dq6¨g:J¯«©l…ž‘¿ht2
ÐìȸŒJ¿`©èEë(׎ȣÖq·Úô¨uBW¨›Uë”!M)Ñý.*˜¨lÅNèâ&Áä¸2ºt˨³Öƒ[÷ÔQ¸Ðq,ûFÔ‘·ˆ²ñú,b§v9Ž\¤ÞL 4H=Œ•†"Ti#õˆ#>2mVêìY£µ\¤>bg©¯Ø*õ8O+§<8èMvR]ÁAÞ,[Ž(JoqМÊ(õ—˜X¤NŒšWÜ7R'¸Ž5¡…üsΣ€Éœh+uFûR•±ÒÓ\È–:¿¸ÎˆV¿šš$b7D&h“:G&a%:oջѯ‘¼Á 'P-Q.hê÷pæVÛ3eœJ±Ž%‹y5v¯(h1Gÿ†Œ`»×ì½MÂðÉcBR¤\´6ÈôƒA¾Øƒs0»„†ªRÆ–ÕïP0ôgÞmôº)ëIô¸|¥u ªhYÈZ 0…‹sDB™IeŒ+© ïQ0@›q³Ð„Ÿoâ"Ü)ŠÊ€í›0jòTQŸ·Í'Š¡ÐúLnÂf&ë9U)Zˆ°FÞxÐî<ZtnÎh„Í—ý˜hš}#拌z€;Ú2Íå'B˜ei6Ťó™Út}öÍ ä‚Úf!¢jšÇN¨¡ePËK
¾àä’‚‚,!4U0Å‹Fà¾`œÃ@AJ\zF‡˜¢Ð ! ªHòææ4D“Ö¡Þ[OéUt’¼L…‘V–âá„ÍBË!Oájb¤¯á?ž,h½mw;ã(–u•Fóî=ÔyÀºRÈûÞEÿt¬ÅJè¡î
Îgƒîª¢»†Ò‹bâj»1§ÔµV™£(ÃÀó¼á/ÜP ù^°ý‹üChbçÈÆMzT
4yã¢åa„)H vЯ£a÷ÜCvËÙJªmÞŽÄÈ8Ìî[{6¡eOQÚÌÐQ‡ÚîÅéÎ!¿³ß½°Ð\êˆí›7‚‡7+QÛ«æ®g
±CÈ“µ@C&.’€œ¤¿(ðˆk.ÆRz^K<B¨ö©úyok<K,î€L¢FmHÔ¥q®ØþÅ,9cáx".ÕÑQ„‚ÌlóòCÎqËkdE£–Ç»…Ûœk½UŒÁy”!°"™zaa¨ ÕgZТޢ-ª}Ù/hœ ·RûÜAÉ2#Y¥Ýãñê †I7Èk\Á b6Æ—h’5ç+—4^n¼}̾DÕB"2¯ÑþÒ«˜ƒÄÒ·É4n„Cµ½
ÇøØÎŽR‰¢¶A‘ýQ‹¶v” §ÊU›À£_…ô!É«?Cs©Ô¥ñ ¶ŽPÓ쥨<CqYê9T[k ]-[ëÑ#úœ‡…¡yÛ µ°×O0„UÅó1¼Y‹C?Ë9ÞítÄÈ«Þ8W”Q~KAõk×X‰‰€cÎuiÃ"Ϲ=^b7òD7fðZ¼ÏüÖ^(#QáªmóŠÒrxȽœ‚r¼!c3H@á,½Ä6½v»‹‹ôY¤ÄÔ<„N‹·ÊoˆÀði™ÏÏdÓ¿ÒRc—•5„Vj—IΉQU"o‚ Œ+[V½„SÞœ©×†þfB3tHÔÕ>ñ¦Å¢ \mB[¡¸'†‡Ò²w]/޶ËDKo0¶ôAž™èÿüÁ×ÞE"®âÚ2âouuÄÌmó
ú2Ä5µ=¨†ÑbÔð2ˆ>Ú2®Ä ,º´†åi ¯KvꙂ-w¾@dWÿ?¿Ù½ú׫ÿ0 1îÕX
endstream endobj 5 0 obj <</CS/DeviceRGB/I false/K false/S/Transparency/Type/Group>> endobj 6 0 obj <</Matrix[1 0 0 1 0 0]/PatternType 2/Shading 7 0 R/Type/Pattern>> endobj 7 0 obj <</ColorSpace/DeviceRGB/Coords[163.729 415.523 315.349 374.897]/Extend[true true]/Function 8 0 R/ShadingType 2>> endobj 8 0 obj <</Bounds 9 0 R/Domain[0 1]/Encode 10 0 R/FunctionType 3/Functions 11 0 R>> endobj 9 0 obj [] endobj 10 0 obj [1 0] endobj 11 0 obj [12 0 R] endobj 12 0 obj <</C0[0.811752 0.878418 0.776459]/C1[0.949005 0.968613 0.921555]/Domain[0 1]/FunctionType 2/N 1>> endobj 13 0 obj <</AIS false/BM/Normal/CA 0.849991/Type/ExtGState/ca 0.849991>> endobj 14 0 obj <</AIS false/BM/Compatible/CA 1/Type/ExtGState/ca 1>> endobj 15 0 obj /Pattern endobj 16 0 obj /DeviceGray endobj 17 0 obj /DeviceRGB endobj trailer
<</Root 1 0 R>>
%%EOF
From what I can tell the actual data for the display of stamp is stored in a stream. I have been able via PDF Java Toolkit to get just the stream data and get the stream decoded and while in a more read able format I am unsure as to how to use it.
here is the code to get it
protected static Markup convertStampMarkup(PDFAnnotationMarkup mAnnot, ASName type, UserData userData, PDFPage page,
int pageIndex) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
final String mod_name = "PDFAnnotationMarkupConverter::convertStampMarkup";
LogUtil.debug("Enter " + mod_name);
final PDFResources pdfResources = page.getResources();
final PDFAppearance pdfApperance = mAnnot.getAppearance();
final PDFXObjectForm xObjectForm = pdfApperance.getNormalAppearance();
final CosStream csoStream = xObjectForm.getCosStream();
final PDFOCObject ocObject = xObjectForm.getOCObject();
ASName subType = xObjectForm.getSubtype();
//InputByteStream inputByteStream = csoStream.getStreamEncoded();
InputByteStream inputByteStream2 = csoStream.getStreamDecoded();
try {
InputStream inputSteam = inputByteStream2.toInputStream();
File outputFile = new File("D:\\workdir\\du\\svv6w167_aw50_12x_0103\\FDF2AWMarkup\\test2.jpg");
FileOutputStream outputStream = new FileOutputStream(outputFile);
int read;
byte[] bytes = new byte[2048];
while ((read = inputSteam.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
here is the result
q
/DocumentSetup <</PageOrigin [30 31 ]/RulerOrigin [0 0 ]>>DP /Layer <</Title (Layer 1)/Visible true /Preview true /Editable true /Printed true /Dimmed false /Color [20224 32768 65535 ]/flatLayer false /Transparency false >>BDC /Pattern cs /P0 scn 0 i /RelativeColorimetric ri /GS0 gs 318.34277 379.44531 m 318.34277 376.14551 315.62988 373.44531 312.31445 373.44531 c 166.87109 373.44531 l 163.55566 373.44531 160.84277 376.14551 160.84277 379.44531 c 160.84277 410.94531 l 160.84277 414.24512 163.55566 416.94531 166.87109 416.94531 c 312.31445 416.94531 l 315.62988 416.94531 318.34277 414.24512 318.34277 410.94531 c 318.34277 379.44531 l h f 0.16078 0.25882 0.07059 RG 1 w 4 M 0 j 0 J []0 d /GS1 gs 318.05078 379.54688 m 318.05078 376.24805 315.33789 373.54688 312.02246 373.54688 c 166.57959 373.54688 l 163.26416 373.54688 160.55127 376.24805 160.55127 379.54688 c 160.55127 411.04736 l 160.55127 414.34717 163.26416 417.04736 166.57959 417.04736 c 312.02246 417.04736 l 315.33789 417.04736 318.05078 414.34717 318.05078 411.04736 c 318.05078 379.54688 l h S 0.2549 0.41568 0.1098 rg 176.11279 389.56055 m 173.87305 384.04688 l 169.50732 384.04688 l 178.83447 405.27832 l 184.0791 405.27832 l 186.29053 384.04688 l 182.00928 384.04688 l 181.61279 389.56055 l 176.11279 389.56055 l 181.44287 393.02539 m 181.07373 397.59229 l 180.98877 398.75781 180.90381 400.4585 180.81885 401.75049 c 180.73389 401.75049 l 180.25146 400.4585 179.71289 398.8208 179.20264 397.59229 c 177.33203 393.02539 l 181.44287 393.02539 l h f 191.90332 404.8999 m 193.15088 405.24707 195.05029 405.43604 196.89307 405.43604 c 198.62256 405.43604 200.57861 405.12061 201.96777 404.01807 c 203.27197 403.07324 204.0376 401.56152 204.0376 399.51416 c 204.0376 396.83643 202.93164 394.78906 201.45752 393.5293 c 199.89795 392.17383 197.65869 391.54492 195.3335 391.54492 c 194.65381 391.54492 194.08643 391.63867 193.66113 391.66992 c 192.35693 384.04688 l 188.35986 384.04688 l 191.90332 404.8999 l 194.28467 395.38721 m 194.70996 395.29297 195.16357 395.22998 195.87256 395.22998 c 198.31055 395.22998 199.92676 396.99365 199.92676 399.104 c 199.92676 401.15186 198.59424 401.81348 197.03467 401.81348 c 196.26953 401.81348 195.70264 401.75049 195.3623 401.6875 c 194.28467 395.38721 l h f 207.89258 404.8999 m 209.14014 405.24707 211.03955 405.43604 212.88184 405.43604 c 214.61133 405.43604 216.56738 405.12061 217.95654 404.01807 c 219.26074 403.07324 220.02637 401.56152 220.02637 399.51416 c 220.02637 396.83643 218.92041 394.78906 217.44629 393.5293 c 215.88721 392.17383 213.64746 391.54492 211.32275 391.54492 c 210.64258 391.54492 210.0752 391.63867 209.6499 391.66992 c 208.34619 384.04688 l 204.34863 384.04688 l 207.89258 404.8999 l 210.27393 395.38721 m 210.69922 395.29297 211.15283 395.22998 211.86182 395.22998 c 214.29932 395.22998 215.91553 396.99365 215.91553 399.104 c 215.91553 401.15186 214.58301 401.81348 213.02393 401.81348 c 212.2583 401.81348 211.69141 401.75049 211.35107 401.6875 c 210.27393 395.38721 l h f 223.93799 404.8999 m 225.21338 405.24707 227.14111 405.43604 229.04102 405.43604 c 230.85547 405.43604 232.72656 405.15186 234.05859 404.20752 c 235.30615 403.38818 236.18506 402.06543 236.18506 400.08057 c 236.18506 396.93066 234.31396 394.94629 231.84766 394.06445 c 231.84766 393.96973 l 232.98193 393.40234 233.4917 392.01758 233.66211 390.0957 c 233.91699 387.70117 234.05859 384.92969 234.39893 384.04688 c 230.20313 384.04688 l 230.0332 384.61426 229.83496 386.44141 229.66455 389.05566 c 229.46631 391.63867 228.67236 392.42578 227.05615 392.42578 c 225.80908 392.42578 l 224.3916 384.04688 l 220.36572 384.04688 l 223.93799 404.8999 l 226.43262 395.82861 m 228.10498 395.82861 l 230.31689 395.82861 231.93262 397.30908 231.93262 399.38818 c 231.93262 401.12012 230.65674 401.87646 229.0127 401.87646 c 228.24756 401.87646 227.76514 401.81348 227.42529 401.71875 c 226.43262 395.82861 l h f 245.42725 383.70117 m 240.46582 383.70117 237.6875 387.60742 237.6875 392.55273 c 237.6875 396.39502 238.96338 400.20654 241.20264 402.60059 c 242.98877 404.49072 245.42725 405.625 248.17676 405.625 c 253.22314 405.625 255.88818 401.84473 255.88818 396.77295 c 255.88818 392.89844 254.66895 389.11914 252.48584 386.75586 c 250.7002 384.83398 248.29053 383.70117 245.45508 383.70117 c 245.42725 383.70117 l 246.02246 387.48047 m 247.2417 387.48047 248.34717 388.04785 249.22607 389.02344 c 250.72803 390.69336 251.55078 394.19043 251.55078 396.64697 c 251.55078 399.29346 250.7002 401.84473 247.69482 401.84473 c 246.41943 401.84473 245.28516 401.24658 244.40625 400.23828 c 242.87549 398.56885 242.0249 395.26123 242.0249 392.70898 c 242.0249 389.7168 243.24414 387.48047 245.99365 387.48047 c 246.02246 387.48047 l h f 260.70752 384.04688 m 258.32666 405.27832 l 262.55029 405.27832 l 263.40088 395.16699 l 263.59961 392.89844 263.74121 390.85156 263.85449 388.64648 c 263.91113 388.64648 l 264.62012 390.72461 265.52734 392.99316 266.4624 395.19873 c 270.74365 405.27832 l 275.30811 405.27832 l 265.44238 384.04688 l 260.70752 384.04688 l h f 286.33545 393.08789 m 279.56006 393.08789 l 278.68164 387.92188 l 286.30762 387.92188 l 285.65527 384.04688 l 273.91846 384.04688 l 277.54736 405.27832 l 288.85889 405.27832 l 288.17822 401.40381 l 280.97754 401.40381 l 280.18408 396.89893 l 287.01611 396.89893 l 286.33545 393.08789 l h f 292.14746 404.96338 m 293.7915 405.27832 295.57764 405.43604 297.44922 405.43604 c 300.42578 405.43604 302.77881 404.67969 304.39453 403.13623 c 305.9541 401.75049 306.91797 399.64014 306.91797 396.48975 c 306.91797 392.39453 305.3584 388.83594 303.00537 386.72461 c 300.79443 384.74023 297.98779 383.89063 293.84863 383.89063 c 291.55225 383.89063 289.56787 384.11035 288.604 384.33008 c 292.14746 404.96338 l 293.31006 387.66992 m 293.7915 387.60742 294.38721 387.57617 295.0957 387.57617 c 297.30713 387.57617 299.26318 388.45703 300.51074 390.03223 c 301.81494 391.70117 302.49512 393.90625 302.49512 396.4585 c 302.49512 399.82861 300.82275 401.81348 297.44922 401.81348 c 296.74023 401.81348 296.14502 401.75049 295.71924 401.65576 c 293.31006 387.66992 l h f EMC
Q
any suggestions would be greatly appeciated.
Stan T'''
