Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Troubleshooting PDF::API2 overlaying text on an existing PDF

by trillich (Sexton)
on Sep 15, 2021 at 15:51 UTC ( [id://11136789]=perlquestion: print w/replies, xml ) Need Help??

trillich has asked for the wisdom of the Perl Monks concerning the following question:

Having trouble diagnosing an issue with PDF::API2, where I have an existing PDF to bring in as a background/watermark/letterhead, and then I programmatically overlay text on top of that.

This is the code that brings in the background, before any text is overlaid on top:

my $xo = $pdf->importPageIntoForm( $bg_pdf, 1 ); my $gfx = $page->gfx(); $gfx->formimage( $xo, 0, 0, 1.0 );

This code runs fine, no errors -- and the $bg_pdf is a simple PDF v1.4 saved straight from Adobe Illustrator. But after some text is added by the script, the output is partially corrupted. That is, the imported letterhead PDF shows up to a point and then the rest is skipped/ignored until the overlaid text displays. For example, the letterhead includes several rectangles, and only a scant few show up in the generated PDF.

So it appears that upon display, the data for the existing background-pdf gets corrupted somehow, but the programmatic text overlaid on top, is just fine.

Early on I learned to turn off $pdf->{forcecompress} = 0; to keep the whole resulting PDF from being weirdly and randomly scrambled. So that shouldn't be pertinent here.

I've tried exporting the Illustrator PDF output in a number of different formats (v1.3, 1.4, 1.5); with or without 'preserve illustrator editing capabilities'; compression turned on or off; with including embedded fonts like garamond, vs using helvetica only, vs converting all text to outlines...

How does one go about troubleshooting this? Using PDF::API2 v2.038, in perl 5.30.0

Replies are listed 'Best First'.
Re: Troubleshooting PDF::API2 overlaying text on an existing PDF
by NERDVANA (Deacon) on Sep 16, 2021 at 10:11 UTC
    I don’t do much with PDF, but I notice you say that the whole file is scrambled unless you disable compression? that sounds like a red flag for text encoding issues. Are you using the module’s own function for reading and writing files? or did you maybe load the file yourself with the wrong binmode or encoding applied? Likewise for saving.

      Argh! You were spot on.

      It looks like the entirety of my difficulty was when I emailed the PDF as an attachment. Using encoding quoted-printable is what scrambled the results. After switching to base64 I haven't had a lick of trouble. PDF::API2 is rock solid!

Re: Troubleshooting PDF::API2 overlaying text on an existing PDF
by Anonymous Monk on Sep 15, 2021 at 22:00 UTC

    SSCCE and the $bg_pdf are prerequisites to troubleshoot, otherwise no problem with 3 lines of code almost verbatim from distribution's POD

Re: Troubleshooting PDF::API2 overlaying text on an existing PDF
by Anonymous Monk on Sep 16, 2021 at 15:01 UTC
    Indeed – you need to find a way to share with us your complete source-code and, if possible, the actual files: watermark, overlay, and output. We can't meaningfully diagnose this issue without it. I don't know what the PM site can do directly, but you could certainly publish a public DropBox URL ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11136789]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found