Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi haukex,

I have to make a really big confession... After all, we're in a monastery. With monks. So it should be possible, allowed and doable, right? ;-)

I made a horrible mistake by checking the size of the calculated offset in my text editor (NPP) instead of comparing it with the XREF table which is part of the PDF itself. If I do this, then all is working perfect. I'm a bit of a dumb now...

Since I'm so pissed off (of myself, I mean) I stubbornly refused to give up and moved forward with making my SSCCE (as promised), even if it's only to "prove" myself I'm able to do this... :-)

And here's the result (in case it might be useful for someone else in the future that doesn't make such a silly mistake as I did...)

I've tried to assemble an example that should (hopefully) be SSCCE-compliant. Fingers crossed I got it right this time.

First, the original, uncompressed PDF file. It's a simple and very small PDF document called example_uncompressed.pdf. It's been made with LibreOffice and saved as PDF. It contains only one line of text: "A small PDF.".

Here goes the content of the uncompressed file. I've put it between the "readmore" and "code" tags as advised by you and others, I do hope it works (running the risk of being keelhauled if it isn't...):

%PDF-1.5 % 1 0 obj << /Group << /CS /DeviceRGB /I true /S /Transparency >> /Parent 2 0 R /MediaBox [0 0 595.303937007874 841.889763779528] /Resources 3 0 R /pdftk_PageNum 1 /Contents 4 0 R /Type /Page >> endobj 4 0 obj << /Length 150 >> stream 0.1 w q 0 0.028 595.275 841.861 re W* n q 0 0 0 rg BT 42.6 788.189 Td /F1 12 Tf[<01>55<0203>-2<04>2<05>1<06>-5<06>2<0207>-1< +08>-2<09>81<0A>]TJ ET Q Q endstream endobj 2 0 obj << /MediaBox [0 0 595 841] /Resources 3 0 R /Kids [1 0 R] /Count 1 /Type /Pages >> endobj 5 0 obj << /Length 9744 /Length1 9744 >> stream true  @cmap"  cvt =O;  fpgm\  glyfA h head=/ + ( 6hheaQy ` $hmtx<*  ,locatr  maxp*@  name ?H  vpostd $ "` prepLb " +     + + +   H=  p=  +  L +  ] F P i u + i P Z Z P ` + P P m { 1 o  + 1 M  f f  ›‹ J f + / ^ t F F < } S h v = + } J A l  T / Hj g a A +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E`h:-, #Id#SX<!Y-,KR +X}zY-, KKTB-, B#Q@SZX TXC`BY$QX @TXC` +B$TX C`B KKRXC`BY@ TXC`BY@ c TXC`BY@  + c TXC`BY&QX@  c TX@C`BY@  c TXC`BYYYYYY +CTX@ @@ @  CTX@   CRX@ @@ @Y@ U@  c UZX  YYYBBBBB-,Eh#KQX# E d@PX|Yh`YD-, %%#> #> #eB #B#? #? #eB#B-,CPCT[X!# Y-,Y+-, +-   H  _@   `Y _Y tdTD4$ +tdTD4$9tTD4$ +pP@0 pPO]]]]]] +]]qqqqqqqqqq_qqrrrrrrrrrrrrrr^]]]]]]]]]]]]]]]]qqqqqqqqqqqqqqqq ?3+ 3 +33?339/3+ .3939939910%!573!57!!Gɾ۪ɴ +‹55555}hu  T ( Y@4!  )* !PY PY*p*`*P* **_*O*]]]qqqqq ?3+ ?3+ 99993 +33310#"&'533254/.54632#'&#"ӱF0-1Kx™Ye\2g›/*5r +QUMNZ?#Dz4!DcF|m/PD9N2.CV  +  1@ ! ((-- +! 321.PY1(! -+-PY+ RY ' %RYv3V363$33 +3333333b3P3D303$333h3333t3@343$3 +3333333d3P3D343$333333333k3;3 3 +338333`3T3@343333333t@+3T3@343333 +333p3P333^]]]]]]_]]qqqqqqqqqqqrrrrrrrr^]]]]]]]]]]]qqqqqq +qqqqqqqrrrrrrrrr^]]]]]]_]]]]]]]qqqqqq ?+ 33?+ 33?33+ 33333?+ +93333310>32>32!574#"!574&#"!57'5!FK +@EuMDyUEE?B‹UUXVww`+:49+B--X 6A--XSY-- -  Hq  % m@?%% '&%" "QYPY   PY PY '_'@'']qrr ?+ ?+ ?39/_^]+ 9+ 39333310 +2!'#"4>?54&#"#563267њurIGJdS"8 _Dc2 +~-^r^{Aa\/u#^n  )  @p PY PY      t d $   9   p `  +P @    P      p ` P @ ]]]]]]]qqqqqqrrrr_rrr^]] +]]]]]]]]] ?+ 3?+910%!57'5!oFF---  ; !=   @ +   `Y `Y_Y  _Y o/oO?/o_8/ +?^]]]]]]qqqqrr^]]]]]]qqqqqqqrrrrr ?+ 3?++ 9 +/+99333104&+326!57'5! #ZbhN˟ +B555u  ;u=  L@/  _Y`Y_Y`Y ?@ p]]]qr^] ?++ ?++993310 + !#32  !%#57'5xsf""{" +55  ; )=  @  `Y_o-   + `Y _Y _Ytdt`T +DtdT@0 9q +_qrrrrr^]]]]]]]]]]]]]]qqqqqqqqrrrrrrr ?+ 3?++ 9/_^]_]]+933 +3310!57'5!#'&+!73#'B p‹==Z555Ѡ +d  y @   ›[ ?+9310%#"&54632yE44EF33F\1HH13FF   0]O_< + D    !E W  + 9    T9 + H9 )s ; ;s ; @d< +  2    / \    n  V    V  +   f    m            z  +  /  C  nQ    .  5   >   X        $   +  62    h             +    (         8   \    j j    4 Digitized data copyright (c) 2010 Google Corp +oration. Copyright (c) 2012 Red Hat, Inc.Liberation SerifRegularAscender - Libe +ration SerifLiberation SerifVersion 2.00.3LiberationSerifLiberation i +s a trademark of Red Hat, Inc. registered in U.S. Patent and Trademar +k Office and certain other jurisdictions.Ascender CorporationSteve Ma +ttesonBased on Tinos, which was designed by Steve Matteson as an inno +vative, refreshing serif design that is metrically compatible with Ti +mes New Roman. Tinos offers improved on-screen readability character +istics and the pan-European WGL character set and solves the needs of + developers looking for width-compatible fonts to address document po +rtability across platforms. under the SIL Open Font Lice +nse, Version 1.1 D i g i t i z e d d a t +a c o p y r i g h t ( c ) 2 0 1 0 G o o g l e C o r p o r a + t i o n . C o p y r i g h t ( c ) 2 0 1 2 R e d H a t , I n c . L i b + e r a t i o n S e r i f R e g u l a r A s c e n d e r - L i b +e r a t i o n S e r i f L i b e r a t i o n S e r i f V e r s i o + n 2 . 0 0 . 3 L i b e r a t i o n S e r i f L i b e r a t i o n +i s a t r a d e m a r k o f R e d H a t , I n c . r e g + i s t e r e d i n U . S . P a t e n t a n d T r a d e m a +r k O f f i c e a n d c e r t a i n o t h e r j u r i s d i + c t i o n s . A s c e n d e r C o r p o r a t i o n S t e v e M +a t t e s o n B a s e d o n T i n o s , w h i c h w a s d e + s i g n e d b y S t e v e M a t t e s o n a s a n i n n +o v a t i v e , r e f r e s h i n g s e r i f d e s i g n t h + a t i s m e t r i c a l l y c o m p a t i b l e w i t h T +i m e s N e w R o m a n!" . T i n o s o f f e r s i m p r o + v e d o n - s c r e e n r e a d a b i l i t y c h a r a c t e +r i s t i c s a n d t h e p a n - E u r o p e a n W G L c h + a r a c t e r s e t a n d s o l v e s t h e n e e d s o +f d e v e l o p e r s l o o k i n g f o r w i d t h - c o m p + a t i b l e f o n t s t o a d d r e s s d o c u m e n t p +o r t a b i l i t y a c r o s s p l a t f o r m s . h t t p : / / + w w w . a s c e n d e r c o r p . c o m / h t t p : / / w w w . a s +c e n d e r c o r p . c o m / t y p e d e s i g n e r s . h t m l L i + c e n s e d u n d e r t h e S I L O p e n F o n t L i c +e n s e , V e r s i o n 1 . 1 h t t p : / / s c r i p t s . s i l + . o r g / O F L  ! d PAbe hg  +` N_ UA =@ U@ B UC =B U.= = > U< =; U ; ?; O; + ; ; > U0 =/ U/ > U- =, U , , > U? => UJ H U +G H UF =E UE H UI =H U `  ?  @ P +)O_0 P`p  8=U=U < 0P݀ݰU 0p/ +O`P›`›/.G' FOL = NAM  M M /M OM oM M  L L /L@8_ ++{‹pvvsP)on+nG*3U3U@Ib%(F`_@_P)[Z +0ZG)3UU3U?OoRPQPPP@P FOO/O@eK! +(F`JpJJIF)HG8GG/GGGG_GGFFF@F)/F@F!FHU3UU3U + U3 U/_ ? TS++KRKP[%S@QZ UZ[ +XY BK2SX`YKdSX@YKSX BYsst++++++++sstu++s +u+t++ +^s+++++ ++++++++ +sss sssst+++s+++ss ssss s+ss ++s^s+++^s^s ^s +^ssss+s ssssssss +++++++s++++s++++++++s^ endstream endobj 6 0 obj << /FontName /BAAAAA+LiberationSerif /StemV 80 /FontFile2 5 0 R /Ascent 891 /Flags 6 /Descent -216 /ItalicAngle 0 /FontBBox [-543 -303 1278 982] /Type /FontDescriptor /CapHeight 981 >> endobj 7 0 obj << /Length 438 >> 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 <00> <FF> endcodespacerange 10 beginbfchar <01> <0041> <02> <0020> <03> <0073> <04> <006D> <05> <0061> <06> <006C> <07> <0050> <08> <0044> <09> <0046> <0A> <002E> endbfchar endcmap CMapName currentdict /CMap defineresource pop end end endstream endobj 8 0 obj << /LastChar 10 /BaseFont /BAAAAA+LiberationSerif /Subtype /TrueType /ToUnicode 7 0 R /FontDescriptor 6 0 R /Widths [777 722 250 389 777 443 277 556 722 556 250] /Type /Font /FirstChar 0 >> endobj 9 0 obj << /F1 8 0 R >> endobj 3 0 obj << /Font 9 0 R /ProcSet [/PDF /Text] >> endobj 10 0 obj << /Lang (nl-BE) /OpenAction [1 0 R /XYZ null null 0] /Pages 2 0 R /ViewerPreferences << /DisplayDocTitle true >> /Type /Catalog >> endobj 11 0 obj << /Creator <feff005700720069007400650072> /Title <feff00440065006600610075006c0074002000470056004300200074006500 +6d0070006c006100740065002d0055004b> /Producer <feff004c0069006200720065004f0066006600690063006500200036002 +e0034> /CreationDate (D:20200626184830+02'00') >> endobj xref 0 12 0000000000 65535 f 0000000015 00000 n 0000000422 00000 n 0000011269 00000 n 0000000218 00000 n 0000000522 00000 n 0000010335 00000 n 0000010537 00000 n 0000011029 00000 n 0000011236 00000 n 0000011326 00000 n 0000011477 00000 n trailer << /Info 11 0 R /Root 10 0 R /Size 12 /ID [<e96dcc1e51afc88fdd4e014ad07cc03b> <e96dcc1e51afc88fdd4e014ad07cc +03b>] >> startxref 11763 %%EOF

I just added it so that you could see the correct start locations of the different objects. The list of object starting positions can be found at the end of the above document (copy/paste it in an editor should reveal this...) and is also given below for clarity. There are apparently 11 COS (first line must be ignored) and e.g. the 3rd COS has an offset of 11269 bytes from the beginning of the file (that one is already after a section that has binary content in it).

0000000000 65535 f 0000000015 00000 n 0000000422 00000 n 0000011269 00000 n 0000000218 00000 n 0000000522 00000 n 0000010335 00000 n 0000010537 00000 n 0000011029 00000 n 0000011236 00000 n 0000011326 00000 n 0000011477 00000 n

Now for the dumped version of the above, I've used your script and sent the output to a file. This is the result (same here, used "readmore" and "code" to void the direct visibility of it):

my $data = do { require MIME::Base64; MIME::Base64::decode("JVBERi0xLjUKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3 +RoIDMgMCBSL0ZpbHRlci9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nCWKsQrCQBBE+/2KqYW +cu2s22YNjQUELu8CBhdip6QTT+PtelIHHMPM4CT70BoMTq8OyJR0N3kvyQbA86LLB62+0 +LDMdKvWaBozuSTyj3rE9CURRn9fCEmaFlXfRaeE+Giyk8BCdrdT1HKNrk/+UHN76Pm71T +MdKE034AkzVH9wKZW5kc3RyZWFtCmVuZG9iagoKMyAwIG9iagoxMjkKZW5kb2JqCgo1ID +Agb2JqCjw8L0xlbmd0aCA2IDAgUi9GaWx0ZXIvRmxhdGVEZWNvZGUvTGVuZ3RoMSA5NzQ +0Pj4Kc3RyZWFtCnic5ThtUFvXlee8JwmBAElEYIRs68kytjEfAh527MQYGZDABhvZQCo5 +iZFAAikBSZEEjpPNhm2+PDiu3TSb5ms2bif1Jl3v5BG7XaeTjUk3aZvppkm2aafd1I1nm +m6303jjpm6mmxSx5149MFAnne7sv73Sfe98n3PPOfe+J2VS4xEohEkQwT00FkquKTKUAM +C/AmDJ0ERGau4pvZ7gCwDCvw0nR8Ye/6ebLgNozgDknRkZPTRsPTm5A6AwCpA/E42Ews3 +lx1wAZRvIxuYoEfZmD+URHiR8bXQsc/s28bWNhN9LeM1oYiiUMaUKCFcILx8L3Z7cqHEL +hH+PcCkeGotILZpOwv8TwDCRTKQzYVg7B7CG2ZOSqUiy+/HBVwmfBBCPEw3pw0YhgTqGC +6JGq8vT5xfA/8+hPQql0KltBiMk+XXJEE+BFR4DmHufYVe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MDAwMCB +uIAowMDAwMDA3MTk4IDAwMDAwIG4gCnRyYWlsZXIKPDwvU2l6ZSAxNC9Sb290IDEyIDAg +UgovSW5mbyAxMyAwIFIKL0lEIFsgPEU5NkRDQzFFNTFBRkM4OEZERDRFMDE0QUQwN0NDM +DNCPgo8RTk2RENDMUU1MUFGQzg4RkRENEUwMTRBRDA3Q0MwM0I+IF0KL0RvY0NoZWNrc3 +VtIC9BRTk0RDREMDE2Mjg2RUQ4MUY5QkFDQ0FGOEVCN0U3OAo+PgpzdGFydHhyZWYKNzQ +3OAolJUVPRgo="); };

And finally, the code I've used to search for the different locations where x 0 obj occurs. x is a number going from 1 to - in this example - 11.

To use it, first the above content (full or dumped code) has to be saved into a file of your choice and then call the script using perl <filename>.

use 5.010; use strict; use warnings; use Path::Tiny; my $data = path($ARGV[0])->slurp_raw; my $outcome = get_nr_of_cos_objects(); find_obj_blocks($outcome); # Returns the number of COS items found in an uncompressed PDF file # We're looking for a line that starts with "/Size", followed by a # number that indicates the number of objects found. # Note that we have to subtract 1 from the result found since the firs +t # item in the XREF table is referring to a non-obj block (root) sub get_nr_of_cos_objects { my $regex = qr/(\/Size \d*)/; my $result = $1 if ($data =~ $regex) or -1; $result = $1 if $result =~ /(\d+)/; $result -= 1; # $1 is the result of the above regex execution. say "Number of COS: " . $result . "."; return $result; } # Searches for the occurences of patterns like "^x 0 obj" where x is # a number from 1 to nr of objects passed as a parameter. sub find_obj_blocks { my @counter = (1..$_[0]); my $result; for (@counter) { if ($data =~ qr/^\Q$_\E 0 obj/mp) { $result = $_; printf("Begin of Block [%5d] found at position [$-[0]]\n", + $_); printf("End of Block [%5d] found at position [$+[0]]\n\n +", $_); } } }

Since all is going well now, I was able to scan my whole PDF file and compared to the speed I had with Python to do the same, it's blazing fast in Perl!!! What took "forever" in Python - say, half an hour or so? dunno really, since I never got the patience to wait until it was finished - takes not even half a minute in Perl...

Indeed, once again it's proven Perl is much, much better, powerful and faster for text processing than almost any other language (apart from pure C, I guess)!

Thanks anyway for your patience and willingness to help me. Much, much appreciated! Others too!

Best rgds,

In reply to Re^6: Calculated position incorrect when using regex in text file that also contains binary info by geertvc
in thread Calculated position incorrect when using regex in text file that also contains binary info by geertvc

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-05-29 03:18 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.