PDF replacing the character mapping name with "wrong character name" - pdf

Hi I am trying to analyze some PDF document which displays somewhere on one of the pages money sum and currency sign after it. Graphically it represents it correctly, however when I extract text from it I notice that currency sign is replaced with "{" symbol. When looking into format I notice that indeed currency symbol (164) is replaced with "braceleft" character name, which probably causes text extractor to be confused.
48 0 obj
<<
/Differences [
...
164
/braceleft
254
/.notdef
]
/Type /Encoding
>>
The previous font definitions are as follows
27 0 obj
<<
/BaseFont /SUBSET+CZOQOM0T1U42409
/Encoding 48 0 R
/FirstChar 32
/FontDescriptor 49 0 R
/LastChar 254
/Subtype /Type1
/Type /Font
/Widths 50 0 R
>>
endobj
49 0 obj
<<
/Ascent 808
/CapHeight 600
/Descent -221
/Flags 6
/FontBBox [
-60
-249
1187
808
]
/FontFile3 112 0 R
/FontName /SUBSET+CZOQOM0T1U42409
/ItalicAngle 808
/StemV 62
/Type /FontDescriptor
>>
endobj
Why would PDF file encoder choose to replace character name with 'braceleft' instead of using 'currency'???

Related

String to PDF white page, Encoding /Identity-H

I have a database which contains a table with the following fields
id
data
timestamp
client_id
This was part of a very old web application that is no longer in use however is still been hosted in case we want to go back to to double check info. The field data currently is a string representing a file (xml, html and pdf). When the record is a pdf, I am trying to get the string
to open as pdf. I have done:
copy the string into notepad and save it as pdf. This open the file and matches the number of pages, but the pages looks blank.
I used a website like https://www.base64encode.org/ to encode the data as base64 and then I use a website like https://base64.guru/converter/decode/file to download the file, this does exactly the same as just saving the file as pdf where the downloaded file opens and display the same number of page but all of them are blank.
I am wonder what could i be missing to make this pdf to show their content?
In the ideal world I would like to run an script locally to generate this files and then uploaded them to S3 bucket, as we want to stop the server where this web application live
Table structure in mysql
Sample String:
%PDF-1.4
1 0 obj
<<
/Title (þÿC2B2-3DA7-9410-24DF::BF25-177E)
/Creator (þÿwkhtmltopdf 0.12.1)
/Producer (þÿQt 4.8.6)
/CreationDate (D:20150814130713+10'00')
>>
endobj
3 0 obj
<<
/Type /ExtGState
/SA true
/SM 0.02
/ca 1.0
/CA 1.0
/AIS false
/SMask /None>>
endobj
4 0 obj
[/Pattern /DeviceRGB]
endobj
6 0 obj
<<
/Type /XObject
/Subtype /Image
/Width 594
/Height 72
/ImageMask true
/Decode [1 0]
/Length 7 0 R
/Filter /FlateDecode
>>
stream
xœíÌ1
0ü›&vÒ
hÒ2µI¥R©T*•J¥R©T*•J¥R}©nZœ(ñ
endstream
endobj
7 0 obj
48
endobj
8 0 obj
<<
/Type /XObject
/Subtype /Image
/Width 594
/Height 72
/BitsPerComponent 8
/ColorSpace /DeviceRGB
/Mask 6 0 R
/Length 9 0 R
/Filter /FlateDecode
>>
stream
xœíÕ1
€PA||)h t€äíLNÀu»öc™™™Mßvûý†™™ÙS=33ëì©Þ s©ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#‡êСzt¨ª#Ç«zÌsZ£Å
endstream
endobj
9 0 obj
315
endobj
11 0 obj
<<
/Type /XObject
/Subtype /Image
/Width 634
/Height 100
/BitsPerComponent 8
/ColorSpace /DeviceGray
/Length 12 0 R
/Filter /FlateDecode
>>
stream
xœuX \SǺŸoÎI"Ö-Å´O%D÷%„¢ ¸±/BØ!a_ÃHwq—MQ[ë­Ëµmmµ­µî·j«Õ.¶µÚÖwkûêmõ¾[Iï›$PÛþ^Îo`æœ93ß|ßþßBÈ ÒD8B¢â¦Í|>äèV¼ÓŠ%3¯¸.·%hÉ5¬? d¤%_Ÿ¥Óo[xŒÙwxÏ7ou—¸ââ†íñù%UÆ'’çŽb{>¶—åduÙºŸ¹¶ëK²Œåd^DÞƒm·Ò¬½4mÊ"l_'\ ÇWÀd""D´C¤Â;ãìÿ¹I.ÅX±ÿ¾"ƒû¢‰¢«
ÖŠ
'Á„ôYÅD $W²ƒ7{Ø3>#Ôƒ
7|]Dt8š7¶9"!ÏáäY#!UpRÀâ¬Àÿ à¼­ô¼¯ð?ð¬õySN„>|F­VQÏ“}"‰µÁjæ{{¥ÔHkŸÜ§éÖ½ô[šÎŒ‹s~sHÈ`\ƒ‚S‚
” î²µ¨½™zUS¯&˺#¸
B>ŽM…]IzßÜ{|$ñ"Äc¦ÆW­)KÄ^b/OµÚGã«ñUÍ”»È•>^žJw‰X&)w¡SªüÒ3Š?17øùçl8V] •ñ û’µÚä˜ðЊœ˜¸)ÓÚ¶õŽÞT??¤°èpcdduõMåõÊ*fqrßÞ
ç•‘ „8{Ì$³Í¯tÇùå8—ŠÙ¤ÆÙñÂû2-Ì ,+ÙpkÕJœSRºáÖÊÕF}ξ½zÝÔi±ñ…/èôtJwƒ9<´£óɨÝæÆùí½NgÍ
æ«rS~ž¿ÀÜx™­¼W~™ R\¹Ø‹M(UI©ÊMƒÿ”\BÉOG´Úè.ÌX½v7èuè»Ö(áʧÜðÞ‹ø~7Æõ
®#ŽƒÉ˜ù.r™T)eÆ¢«$X…³SRÊŽ$&ÔÎYQ–°Ô»–8©Sû#Vöyk½´%<Bë­Ï¡8¢¼ï
EÙF”ªdJ)s€‹Ffw‡T©VI!ñ«¯ncçO‹®×ø]º$Š~̶NK™4žÉ–.k¥7²A†c#DüŒˆxѦ”*ÐþUñ?›-ïšL\°™¾i
õX
t#ö>„3º‹ Û‘Ø[îF£˜E©}tkR†0g†9sZ¬D„8;"$µa£¸¢ììçUµ•Uwß6TA]\lçíô´/:ãâ©—¥};Àašñ„lÞm’ë5Æs`¹YSëÀ÷1zr,ñÆ}è΂­VÛ ¡a>•)db;4r10×*"hк²ŠÙsÅÅËÎWWZ,P”ÿB梅‹W
ÿZ–îLWÅ'Œœb2vNBL,X¹æ»ùÉ:“Ò=Òÿ4gÉѽ4´;;‹Ø£I· 
ñá©Û㧒1PÒ-ž“*""µ5é7fŒå>’Àìàë(>àð»CÑúƾÿÀd^ƒoŽ#DããÀ±ÄÎj7Êe¼å..rï 29ýcsûhW×ÑîJ¹Ü…{ç©qDtFÔ‰íp4N!c,ò¹5ÙÄ­²<¦ûék’¨§Àzû¾ˆ»k/öµ!i`G1d;ö”FÊï
ž[UÓ~}+
^{­ D=–±ÛJJýg-3ßå~´xÔåææ¾Î}Þ?û#ûì
%0ß DùG&Ë[f3VÏßéuõô*ø»è‘}}ü)ì;œ<GÂŽ­ÃhgÀ¶ÆWªÆ +O#DZM££¢¢7n~Sø Fþ³u=¬YwWÔ×ÑufÕ¹ŽÎ˜8…õºwu€¨éIgZÒ‚k;-:O<Ð,ÇÂþDVÔAâ<þôèõ­÷÷™–…ÌŸÒ¼lÿ÷kWÉÍÓ„î‹ÕµU†sg²³\áâýºú˜˜¶í§Oéh‹‹YÖt°½M°³´·§¥¼Épjîû‘ÿg–3ÎûrXŒŸšÛE&¡vªr–°Ï/å
oj>Ð×½ÂÚ›hj
«ƒšÚkWŒõ`4~p½¦š®½ÜÑoMûÅ]q±11ÛÛÎŽ1Û:ÛÛ…G‚¥½CÑ«ÐÃð€R*E¾—2ÊI¡£èsûj¬÷3¬ß× Ó÷ŠDÈöõtÝßgm´.Ç×ñœgçD“
K6<ݶ.å†[j¸•–ÓƒÈGò¦¾ÀÕÇ7ÞÂ7F°¨Úˆë•37€“25ª‚Þ’ÍðÙw+–ClÜZ(n±üu;2Ò‘õŽ
ciKÔå†Ë
‹½­mCé%HNjíJL#«nâÈ‘¶\iç¡H“ [vk9¬ažö`vªÀ‡^³7çç³ÕPÛó­XbGüï¦yyØìbéK*<üfårXÖô³°ªe¤§eü]h¡1ÖWТÊêË”V#>$&tµkµ8+*~»-«:Ö«VðÛ…¡&aŸ)
rR^€½\±×ì5ˆÅBÅ&ÍS­¿˜¬¿n¥íÜhK•õ6ϵbïpäº7°·3öVIûSª?Õq
Pc|ï#ƒÁ×¹. w´®™Le¥ÿØš²‡Ån)â°q¨Á†=5zjìÜÌhËÕ,WŽ”»Ø/›Flë¦rl
îaBâ×÷òÚ`ÝšO7W‚‚̹¹‡÷çä$']8¯×ù¨p~½³±yÞ|0AUåéƒùy[:7hqÁË/æhütúúí©ZX¸ØXîãë?+*ºäå¼|ðÓää4íLJ^¼ˆEf;Ú€¶rlÅ,¦œ§ƒÖGÚ×ÎrÍ»xz¸º¸¸zxºÈùðwwe¤èú;û±lû
f"5K5èlý®µFcìîÔðë&ªX!䈉eB=t~ÖÌ‚ôø%dv‚ºNá©î'Cæ1•
±È¨p°9“eð‘r™bF£¶ t".ÎÊ.Ù•™
+–?ø®iÀ­j4{^+(P
ƒŒi“?yM§Ÿ2S7iÊÒÄU»ÒRÀT9^ðÜäf¾6õ쎒³ü³
*O Ä5µã.nBË<û„›œýå¥v¡t¨ˆ§Å3Zm°€ìÌZH«ž=gýò¤äÁuÁóVVÄÄxù€ž¬™3nèü|AXiJÿ±9<,6¶ÚêCo¬
à¹ÖÑLkp6ŽFz#5:–±™¥mÝ¿sìD­±mõï»èù¾¾nvPacä07ܶCÅ®ôHJîVBtWbüÒäá}QOfö[†Øøñc2³—-*ú¶õpLÔæUÑ‘ùºjüô€õE7z#Ͳ®—ãR;°,PH–;(׎c´‰a6oŽŠñð**<p¼´Ä]W¶ 0`Owt¤§#IÙ±SHô&ˆ‹]½,"œ“4j·1¼üýcb’´›Óƒƒ|Ôñ±“¦xxN˜0+~-F75¥µ `‚­ÄøpGÑm?›°VÁO°Ð$g …¦¿qm½íú-Õˬ¢Â÷3xÊ5ά»—ÄöΞg]Ïø/ù³p!WøaèPáç\á¢é·´l.ÐrÅPÀÍé½ÈigZöã(…‰“2NëCă
œÒRJ_~JaÖr-Y¨0ÿ"1mzn'æNΦçÜìw‚Œm&›z•öËl‰ÔF<W^ñν*C­á«ÓeFd󎪨oío¥Ï
ÛÚl뮣°e›ÐË}‚gÐø—®W««Ñz<³Ñ×EÇ™×pß‹Ô*úºQ¨‚‡#EnÛÊO 5FŒþcä)Q¢5Ô~ìp–Ž°/U*ñ±[#—°ãc(¯¸}«²
_Þ2jcâöíÅ`ÅÇïÝK3„«{^ØÝ
“#ªÝ»:º„OÅOšQõ7<¾ùmÅŠææßX¬²qîG87’ÞmÊtÞ¿~'P5žÆ±/¼”°Íœ±d¢wTô¶
IZ£¿¿^g¾h0Ì›_¹ý^Wµ¥¨4 ÐÙY;’ -㸑…úrnPÜúè¨Ø¸Õåi*UqÉ[IÚI^)éoW#­ÊHmhML†èÈÎ-¸ÉÐSÍÈøƒD'É2•q…ÒM"–öÛ(î×!j5Õøzp²~™‡&s‹‡ ÿî蜕šjx§¢|Ô997–·À«Ç ü‹Ê¬EvV÷z4–ŠNæuíÆN›²bÕÇ›*As¡³ã_FXýé'`í ÍË=]k,+=t8?ù03ß`ä1Ë|¨0=¶nm …–óÜ)QÑ“6Ñ¢\†:]ßcîúz™n×l^âœe#]ÔJ±Ï7<.€™Íh™a\ŽÞæʃÓ3KÌé*5øùê³[¾¨¯ƒ„ý.A²v°ß˜™>RÒvmÒ¦$/¥{3fªæW”¯ÞT[3/pM÷‹…êaëæóÂ*Cï˜êÀPõòþ²
¶Ž\Ç(´ÏÌÕàÀ‚×#Zø àGYÊáWóôé11·á„µ~¾ù¹-—åAs÷…ÔšJ}7¦§&¯‹‰‚ôŒ6“^7Ë¿ àxn]ýk#9r#é‚>ç)g”2Ü#2´9…mCÔ|NoY7©ªvŸ¯©6®®®Q9"!~SwtRîŽÄ9Aaôz±LÐØôñ·ME…§Û–Dää¼ñ¼^2ùlœwl_ýÁ®¬äHFëKhfqƒx
F'W¿Ÿ¶©IvìdJùJ!•pù÷î­qto‹µ”ŽVÃÇza3”Ïç,.8•å‘\“#¶ÁUÜŸÝqAO;5ŽôÊ=%NضSsÊ‘÷ú½yóŠ"–46]ÿ¨—²hASqð\¨®<sº¶:6+»½3#3-mÊIOHHZ¹6. 1~íêÄÞߤ89#sÙÛÅ¥PZò¶);sòDm’áxQ!—XÚW'/…„Äõ­x¤ˆ‹m¥'ÍŒþ£b—7EFBtúh½0‘–ˆ3™¾u¶cSnÛ\HbËO­~š’¢†1!ÁsUªqnÓ§ÆÇêÇ4ûúÑ%Ÿ]{ÿïÇLÓjÍ
];ÏxæìÖ¶…K¼ÊNenÂb®ÇñÅýkc_µœá%‹_!°Y˜ášüæäés–úùzª…ü–ÃÜÆÞa~†åˆ'O,ÚÊÏ`R •­Õ‘xùöó^vH©¯_aQ󘬄ØÓ§OO̳¬¨Ð_CgyùêÁCaÛ¶^8ûígßíìˆ8xèýŒËXÆa§|•Ú.Ö$v$cÒû—W_…ĸÎ#'U#ŽÆ€
w+»å¥ä$€º!³ƒÊWe[¼Ùh3h4A3Ì1r #Ü¥ÑzÆ ÅB÷fþqŒÑl§d¹Z%uˆB\…ýËؾ3x9¾4”Ÿû²ª²ºæREn~#Hã+ññ•_œ*7Ø>:¤MŒŠ.µ}v°âqé•îÞÛ7êêU3t'/ݽæhoï]¯1^„ÿÍóó­©eYQÈä)Ú"%îYÑ~úg•z90‹Y¹1ÊÓòŠ·îÔÔªïž++3&$v”FEO˜UÚžoKŒÝÖ[¢Ï»Ã6LŒü5£||uÖßÒf̨¯EÏTöMç¬â
Äÿ)Ï\­VÉú…ís—x#³HË”j±#Ù¶ÊÊßc¤§Ïy9÷T„1q­›"£aÑžW¢#'xåæÓ_.)5BªvßFmä•…‡…ådí|1W7üòeieÕ%&TQ›!¡¾~—äíÓå}çŠþ÷º“’!b Z»¥ï?ˆjdø_¿olùÿ?`0ØŠèùµ¡Ã³¾ý ÅMè `YÄñÃw$Å*}§}ª>•¸É6ÒÓ¿#<Kéø>2–GÒyÑòzÒ…¥›n%røç<HNÀrˆ7bÞhéQÒ
GH#ßDNˆæ‘}¢#ø6–™¤ETHÄÈ ~¶G’ãTAnòlÿ„åñá/W>„ó§HŽÙÆýHºù…D'‘“vþ>öJôÜgÄS<ˆñ:|VFvb9†¥K6–åX"°è±`9ÀMAÛËH–Bº´rï7º“(èK$ˆ."3ør´Û>N%|O¶àšg’(²ž\%#³ðŠ…tØ7á!Oh­£è?¹‰ÜbNǵs{¹cÜ—ÜC^ÂOàùùwECE‹EE_‹‹ÇˆÃÄfññ‰»¤DÒ,ùpdPÈ èAeƒ>v9y;%:58­wúpðàÁYƒ—ÙãAÉ\vúv´þü“-îràìçaGbFquÔ¹§îóOÕEd2êk{]Œ÷cõa$žbý‡¥
‹Y‚™:äc+–è±VMŠI1DlH%>-#¥Øo&rÊt¼fà¥Æ2Ëvµ}þ0┧Fd¥Š”£œ†W­íšŠ£—cÉÁ§zl•á,yø´ßÊÁ;¥8§Ë4g!æÑPIâðï»ÿC%˜ð
endstream
endobj
36 0 obj
4859
endobj
34 0 obj
<< /Type /Font
/Subtype /CIDFontType2
/BaseFont /Roboto-Light
/CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >>
/FontDescriptor 32 0 R
/CIDToGIDMap /Identity
/W [0 [440 620 511 556 545 545 319 241 702 222 551 512 334 208 558 652 704 650 644 671 858 564 630 264 523 611 592 594 546 588 222 486 531 879 608 502 477 748 544 550 550 550 550 550 550 550 550 550 394 550 550 316 471 323 328 284 550 550 550 237 ]
]
>>
endobj
35 0 obj
<< /Length 777 >>
stream
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
2 beginbfrange
<0000> <0000> <0000>
<0001> <003B> [<0041> <0063> <006F> <0075> <006E> <0074> <0020> <0048> <006C> <0064> <0065> <0072> <003A> <0046> <0055> <004E> <0044> <0043> <004F> <004D> <0045> <0052> <0049> <004C> <0050> <0054> <0059> <004A> <0053> <0069> <006B> <0061> <006D> <0042> <0073> <0076> <0077> <0068> <0062> <0031> <0030> <0033> <0036> <0037> <0039> <0032> <0035> <002F> <0034> <0038> <0028> <0079> <0029> <0066> <002D> <0067> <0070> <0024> <002E> ]
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
endstream
endobj
10 0 obj
<< /Type /Font
/Subtype /Type0
/BaseFont /Roboto-Light
/Encoding /Identity-H
/DescendantFonts [34 0 R]
/ToUnicode 35 0 R>>
endobj
2 0 obj
<<
/Type /Pages
/Kids
[
5 0 R
]
/Count 1
/ProcSet [/PDF /Text /ImageB /ImageC]
>>
endobj
xref
0 37
0000000000 65535 f
0000000009 00000 n
0000023948 00000 n
0000000223 00000 n
0000000318 00000 n
0000008502 00000 n
0000000355 00000 n
0000000560 00000 n
0000000578 00000 n
0000001075 00000 n
0000023809 00000 n
0000001094 00000 n
0000004216 00000 n
0000004237 00000 n
0000008431 00000 n
0000017155 00000 n
0000013032 00000 n
0000008452 00000 n
0000008859 00000 n
0000010796 00000 n
0000008623 00000 n
0000008839 00000 n
0000010817 00000 n
0000011026 00000 n
0000012309 00000 n
0000012560 00000 n
0000012288 00000 n
0000013174 00000 n
0000013437 00000 n
0000016203 00000 n
0000016536 00000 n
0000016182 00000 n
0000017295 00000 n
0000017557 00000 n
0000022528 00000 n
0000022980 00000 n
0000022507 00000 n
trailer
<<
/Size 37
/Info 1 0 R
/Root 17 0 R
>>
startxref
24046
%%EOF
I was able to get access to sftp.
I run the below script and use filezilla to download the files.
Because the files where named after their ID's, we are able to link to the actual parent record
<?php
$db_con = mysqli_connect("localhost", "my_user", "my_pass","my_database");
if ($db_con->connect_error) {
die("Connection failed: " . $db_con->connect_error);
}
$sql = "SELECT id, data, app_id FROM my_table WHERE SUBSTRING(data, 1, 4) = '%PDF'";
$result = $db_con->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$fname = $row['id'].'-'.$row['app_id'].".pdf";
$myfile = fopen('pdf/'.$fname, "w") or die("Unable to open file!");
$txt = $row['data'];
fwrite($myfile, $txt);
fclose($myfile);
}
} else {
echo "0 results";
}
$db_con->close();
?>

Getting 'Object label badly formatted' when trying to create PDF visible signature

I'm trying to create a visible PDF signature pragmatically. Non-visible signature works but when I add the AP (appearance) object I get an error in Acrobat Reader saying the following: 'Object label badly formatted'.
The relevant XObject that I make look like this:
38 0 obj
<</F 132/Type/Annot/Subtype/Widget/Rect[343.0 142.0 543.0 192.0]/FT/Sig/DR<<>>/T(signature38)/V 40 0 R/AP <</N 41 0 R>>>>
endobj
39 0 obj << /Length 52 /Type /XObject /Subtype /Form /Resources << /XObject << /n2 42 0 R /n0 43 0 R >> /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] >> /BBox [0.0 0.0 200.0 50.0] /FormType 1 >> stream q 1 0 0 1 0 0 cm /n0 Do Q q 1 0 0 1 0 0 cm /n2 Do Q endstream endobj
40 0 obj
<</Contents <...>
/Type/Sig/SubFilter/adbe.pkcs7.detached/Location()/M(D:19700101010000+01'00')
/ByteRange [0000000000 0000064440 0000068536 0000220176]/Filter/Adobe.PPKLite/Reason()/ContactInfo()>>
endobj
41 0 obj << /Length 27 /Type /XObject /Subtype /Form /Resources << /XObject << /FRM 39 0 R >> /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] >> /BBox [0.0 0.0 200.0 50.0] /FormType 1 >> stream q 1 0 0 1 0 0 cm /FRM Do Q endstream
endobj
42 0 obj << /Length 31 /Type /XObject /Subtype /Form /BBox [0.0 0.0 200.0 50.0] /Matrix [1.0 0.0 0.0 1.0 0.0 0.0] /Resources << /XObject << /img1 44 0 R >> /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] >> /FormType 1 >>
stream q 200 0 0 50 0 0 cm /img1 Do Q
endstream
endobj
43 0 obj << /Length 0 /Type /XObject /Subtype /Form /BBox [0.0 0.0 200.0 50.0] /Resources << >> /FormType 1 >> stream endstream endobj
44 0 obj << /Length 218095 /Type /XObject /Subtype /Image /Filter /DCTDecode /BitsPerComponent 8 /Width 1300 /Height 1261 /ColorSpace /DeviceRGB
stream
-JPEG bytes-
endstream
I can't seem to find the error in this, but I must be missing something. I read this whole document by Adobe along with some other blogs and made my code according to that.
**UPDATE: **
I changed the code according to mkl's comment:
38 0 obj
<</F 132/Type/Annot/Subtype/Widget/Rect[343.0 142.0 543.0 192.0]/FT/Sig/DR<<>>/T(signature38)/V 40 0 R/P 3 0 R/AP <</N 41 0 R>>>>
endobj
39 0 obj
<<
/Length 52
/Type /XObject
/Subtype /Form
/Resources <<
/XObject <<
/n2 42 0 R
/n0 43 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
/BBox [0.0 0.0 200.0 50.0]
/FormType 1
>>
stream
q 1 0 0 1 0 0 cm /n0 Do Q q 1 0 0 1 0 0 cm /n2 Do Q
endstream
endobj
40 0 obj
<<content>>
endobj
41 0 obj
<<
/Length 27
/Type /XObject
/Subtype /Form
/Resources <<
/XObject <<
/FRM 39 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
/BBox [0.0 0.0 200.0 50.0]
/FormType 1
>>
stream
q 1 0 0 1 0 0 cm /FRM Do Q
endstream
endobj
42 0 obj
<<
/Length 31
/Type /XObject
/Subtype /Form
/BBox [0.0 0.0 200.0 50.0]
/Matrix [1.0 0.0 0.0 1.0 0.0 0.0]
/Resources <<
/XObject <<
/img1 44 0 R
>>
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
>>
/FormType 1
>>
stream
q 200 0 0 50 0 0 cm /img1 Do Q
endstream
endobj
43 0 obj
<<
/Length 0
/Type /XObject
/Subtype /Form
/BBox [0.0 0.0 200.0 50.0]
/Resources <<
>>
/FormType 1
>>
stream
endstream
endobj
44 0 obj << /Length 9451 /Type /XObject /Subtype /Image /Filter /DCTDecode /BitsPerComponent 8 /Width 1300 /Height 1261 /ColorSpace /DeviceRGB
stream
--JPEG bytes--
endstream
Here you can download my PDF.
UPDATE 2: It seems there was an error with my xref tables, where they weren't pointing to the right XObjects, that's why I was getting the error. However, now even though my PDF isn't corrupted and signature is ok (adobe will tell that the signature can't be verified because the certificate is self-signed but that's ok).
But now, I have another problem: The image doesn't appear. It's clickable and works but it's all blank.
A new version of the PDF is available here.
The issues you have come across are typical for projects implementing specific tasks of PDF editing without using a tested PDF library.
As discussed in comments, in the first file of which you only posted an excerpt there were fundamental syntax errors, in particular ignoring that for streams the specification requires The keyword stream shall be followed by an end-of-line marker.
Fixing that in your second file you yourself found broken cross reference entries.
Now you discuss the third file which appears to be properly signed as viewed in Adobe Reader, merely the image doesn't show up.
Actually, though, there still are multiple errors.
One reason for the image not showing up is that the image XObject stream is syntactically broken:
44 0 obj << /Length 9451 /Type /XObject /Subtype /Image /Filter /DCTDecode /BitsPerComponent 8 /Width 1300 /Height 1261 /ColorSpace /DeviceRGB
stream
...
Without looking into the values you set in the dictionary part of the stream, one already sees that the closing >> of that dictionary is missing. Thus, a PDF processor does not see where the image metadata ends and where the image payload starts.
In hindsight that was already visible in the previous files you posted, but there other issues first hit the eye.
Furthermore your cross references still are somewhat broken, many entries point to file offset 23 with some arbitrary generation number. At least some of the object numbers so treated are referenced in the document. This makes some programs already fail loading your PDF.
Also already discussed in comments, you tagged your question pades but use the SubFilter value adbe.pkcs7.detached. That is weird, if one starts implementing PAdES signing, why would one use the legacy profile?

.NET DeflateSream seems not work with pdf

I'm trying to write PDF files with c# and I also want to compress pdf streams. It is important not to use any 3rd parties libraries (DotNetZip etc..).
The only way for me to compress pdf streams is System.IO.DeflateStream but it seems that it doesn't work: when I compress a simple stream
BT
/F9 30 Tf
10 730 Td
(Hello World!) Tj
ET
PDF cannot decompress it and displays no text.
I have read similar topic
Is it possible to use the .NET DeflateStream for pdf creation?
but the answer contains broken link on MS bug report, and I'm not able to use any 3rd parties libraries in my project.
Is there any possibility to force DeflateStream work properly with pdf?
EDIT: source code
Here is how I write PDF object:
var resultLine = new StringBuilder();
resultLine.AppendFormatLine("{0} 0 obj", objectId);
resultLine.AppendFormatLine("<< /Length {0} /Filter /FlateDecode >>");
resultLine.AppendLine("stream");
WriteRaw(resultLine.ToString());
WriteRaw(DeflateCompress(content));
var footer = new StringBuilder();
footer.AppendLine();
footer.AppendLine("endstream");
footer.AppendLine("endobj");
It works perfect without deflate compression.
here is my Deflate method
public static byte[] DeflateCompress(string source)
{
using (var output = new MemoryStream())
{
using (var compress = new DeflateStream(output, CompressionMode.Compress))
{
var inBuffer = Encoding.UTF8.GetBytes(source);
compress.Write(inBuffer, 0, inBuffer.Length);
}
return output.ToArray();
}
}
input source variable is
"q\r\nBT\r\n/F9 30 Tf\r\n0 0 0 rg\r\n10 730 Td\r\n(Hello World!) Tj\r\nET\r\nQ\r\n"
out byte array is
{byte[61]}
[0]: 43
[1]: 228
[2]: 229
[3]: 114
[4]: 10
[5]: 225
[6]: 229
[7]: 210
[8]: 119
[9]: 179
[10]: 84
[11]: 48
[12]: 54
[13]: 80
[14]: 8
[15]: 73
[16]: 227
[17]: 229
[18]: 50
[19]: 80
[20]: 0
[21]: 193
[22]: 162
[23]: 116
[24]: 94
[25]: 46
[26]: 67
[27]: 3
[28]: 5
[29]: 115
[30]: 144
[31]: 96
[32]: 10
[33]: 47
[34]: 151
[35]: 134
[36]: 71
[37]: 106
[38]: 78
[39]: 78
[40]: 190
[41]: 66
[42]: 120
[43]: 126
[44]: 81
[45]: 78
[46]: 138
[47]: 162
[48]: 166
[49]: 66
[50]: 72
[51]: 22
[52]: 47
[53]: 151
[54]: 43
[55]: 80
[56]: 91
[57]: 32
[58]: 47
[59]: 23
[60]: 0
EDIT 2: incorrectly compressed PDF
%PDF-1.6
1 0 obj
<<
/Type /Catalog
/Version /1.6
/Pages 5 0 R
/Outlines 3 0 R
>>
endobj
2 0 obj
<<
/Title (my( title..)
/Subject ()
/Keywords ()
/Author (me..\)
/CreationDate (D:20150724042147)
/ModDate (D:20150724042147)
/Creator ()
/Producer ()
>>
endobj
3 0 obj
<<
/Type /Outlines
/Count 0
>>
endobj
4 0 obj
<<
/Type /Font
/Subtype /Type1
/Name /F6
/BaseFont /Courier-Bold
>>
endobj
5 0 obj
<<
/Type /Pages
/Count 1
/Kids [6 0 R ]
>>
endobj
6 0 obj
<<
/Type /Page
/UserUnit 1
/Parent 5 0 R
/Resources <</Font <</F6 4 0 R >>
>>
/MediaBox [0 0 612 792]
/CropBox [0 0 612 792]
/Rotate 0
/ProcSet [/PDF /Text /ImageC]
/Contents [7 0 R ]
>>
endobj
7 0 obj
<< /Length 61 /Filter /FlateDecode >>
stream
+деr
беТwіT06PIге2P Бўt^.Csђ`
/—†GjNNѕBx~QNЉў¦BH/—+P[ /
endstream
endobj
xref
0 8
0000000000 65535 f
0000000010 00000 n
0000000097 00000 n
0000000278 00000 n
0000000330 00000 n
0000000421 00000 n
0000000486 00000 n
0000000702 00000 n
trailer
<<
/Size 8
/Root 1 0 R
/Info 2 0 R
>>
startxref
840
%%EOF

pdftk field names for insertion

when I do pdftk samplex.pdf dump_data_fields
I get back fields with format like:
FieldType: Text
FieldName: form1[0].Page1[0].Header[0].RepeatHeader[0].Project[0]
FieldNameAlt: Project
FieldFlags: 0
FieldJustification: Left
I have a sample that works with pdftk in filling in the fields, but it is a simpler format and the FieldNames are things like 'name'.
I try to merge the following fdf to get my infill for this field (as you can see below I try both the long name and the short name), but it doesn't seem to be working, any ideas on why?:
%FDF-1.2
%âãÏÓ
1 0 obj
<<
/FDF << /Fields [ << /V (Something wonderful!)/T <br/>(form1[0].Page1[0].Header[0].RepeatHeader[0].Project[0]) /ClrF 2 /ClrFf 1 >>
<< /V (Something)/T (Activity) /ClrF 2 /ClrFf 1 >>
<< /V (Something else)/T (Project) /ClrF 2 /ClrFf 1 >>
<< /V (Arthur, King of the Britons)/T (name) /ClrF 2 /SetFf 1 >>
<< /V ()/T (submit_name) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (name_border) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (name_border_red) /ClrF 2 /ClrFf 1 >>
<< /V (I seek the Holy Grail.)/T (quest) /ClrF 2 /SetFf 1 >>
<< /V ()/T (submit_quest) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (quest_border) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (quest_border_red) /ClrF 2 /ClrFf 1 >>
<< /V (Blue... no, yellow!)/T (color) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (submit_color) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (color_border) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (color_border_red) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (message_red) /ClrF 2 /ClrFf 1 >>
<< /V ()/T (message_green) /ClrF 2 /ClrFf 1 >>
]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF
How are you generating your FDF? Here is an example FDF modified from a form I use pdftk with
field hierarchy like:
form1[0].Page1[0].Title[0]
form1[0].Page1[0].Item[0]
form1[0].Page1[0].Year[0]
form1[0].Page1[0].Desc[0]
%FDF-1.2 %���� 1 0 obj <<
/FDF <<
/Fields [
<< /T (form1[0]) /Kids [
<< /T (Page1[0]) /Kids [
<< /T (Title[0]) /V (Android Phone) /ClrF 2 /ClrFf 1 >>
<< /T (Item[0]) /V (Evo 3D) /ClrF 2 /ClrFf 1 >>
<< /T (Year[0]) /V (2011) /ClrF 2 /ClrFf 1 >>
<< /T (Desc[0]) /V (3D Smart Phone) /ClrF 2 /ClrFf 1 >>
] >>
] >>
]
>>
>> endobj trailer << /Root 1 0 R >> %%EOF
so you dont have the /Kids wrappers, and you arent using the field index numbers. Try modifying your FDF like my example to see if that works.
If you are a PHP user, you should check out pdftk-php. I use it on our server to inject mysql data into livecycle pdfs for a variety of uses and it takes care of the pdftk fdf injection part very nicely: http://www.andrewheiss.com/blog/2009/06/19/pdftk-php-officially-released/

Failed to open self created pdf with Adobe Reader

Here's a hello world Pdf creatred by my self.It's xref info is store in XRefStm .How every it failed open with Adobe Reader.Can some body tell me the reason ? Thank you in advance!
RoyDeng.
%PDF-1.7
1 0 obj << /Length 94 >>stream
BT 10 782 Td /0 50 Tf 50 TL (Hello)' (World)' (OK)Tj (World)' Tj ET
endstream endobj
2 0 obj << /Count 1 /Kids 3 0 R /Type /Pages >> endobj
3 0 obj [ 4 0 R ] endobj
4 0 obj << /Contents 5 0 R /MediaBox 6 0 R /Parent 2 0 R /Resources 10 0 R /Type /Page >> endobj
5 0 obj [ 1 0 R ] endobj
6 0 obj [ 0 0 612 792 ] endobj
7 0 obj << /BaseFont /Helvetica /Encoding /MacRomanEncoding /Subtype /Type1 /Type /Font >> endobj
8 0 obj << /0 7 0 R >> endobj
9 0 obj [ /PDF /Text ] endobj
10 0 obj << /Font 8 0 R /ProcSet 9 0 R >> endobj
11 0 obj << /Pages 2 0 R /Type /Catalog /PageLayout /OneColumn >> endobj
12 0 obj << /Type /XRef /Index [0 11] /W [1 4 1] /Filter /ASCIIHexDecode /Size 12 /Length 144 /Root 11 0 R >>stream
00 00000000 00
01 00000009 00
01 0000009A 00
01 000000D1 00
01 000000EA 00
01 0000014B 00
01 00000164 00
01 00000183 00
01 000001E5 00
01 00000203 00
01 00000221 00
01 00000252 00
endstream
endobj
startxref
667
%%EOF
I tried to fix this code with pdftk
pdftk 1.pdf output fixed.pdf
Error: Failed to open PDF file:
1.pdf
Errors encountered. No output created.
Done. Input errors, so no output created.
then I tried with cpdftk (from coherent), and gained further info
# cpdftk 1.pdf output fixed.pdf
cpdf could not read the file. Technical details follow:
Could not read x-ref table
finally I tried to fix file with Multivalent.jar
https://rg.to/file/c6bd7f31bf8885bcaa69b50ffab7e355/Multivalent20060102.jar.html
java -cp Multivalent.jar tool.pdf.Split -page 1 file.pdf
and Multivalent repaired pdf (I attach the result)
http://i.minus.com/1329489690/Df3N96HJPByy3NRF8Jz2hQ/d2Y4wduOvygk.pdf