Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

PDF::API2: Difference between the contents of the outputs of the “to_string” and “save” methods

by espero (Novice)
on Jun 28, 2022 at 12:36 UTC ( #11145139=perlquestion: print w/replies, xml ) Need Help??

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

Hello,

I’m developing an API application. In the API response I get a pdf in a string. If I use the “from_string” and then the “save” method of the PDF::API2 module the pdf works fine. If I write the API response string into a file (without using PDF::API2) or use the “from_string” and then the “to_string” method of the PDF::API2 module (which should be the same as I understand) I get an error message and a blank document (or blank with part of the header) when I try to open the file with a pdf reader.

I was wondering what is the difference between the contents of the outputs of the “to_string” and “save” methods?

Thanks in advance for your help.

  • Comment on PDF::API2: Difference between the contents of the outputs of the “to_string” and “save” methods

Replies are listed 'Best First'.
Re: PDF::API2: Difference between the contents of the outputs of the “to_string” and “save” methods
by haukex (Archbishop) on Jun 28, 2022 at 13:01 UTC

    This kind of thing can happen when the files are opened with the wrong encoding (in this case I assume it should be :raw, Update: which actually means "no other encoding layers" or "binary") or with :crlf enabled, and you may need to binmode the file that you are opening yourself, but that's just a guess. Can you please post a Short, Self-Contained, Correct Example that reproduces the issue?

      Hello haukex,

      Thank you very much for your help and prompt reply, I added binmode and it works perfectly.

Re: PDF::API2: Difference between the contents of the outputs of the “to_string” and “save” methods
by roboticus (Chancellor) on Jun 28, 2022 at 13:11 UTC

    espero:

    When you have a problem like this, you may want to use a diff tool to find the difference(s) between the files. Often that'll give you the clues needed to figure out what is happening.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Hello roboticus,

      Thank you very much for your prompt reply and help. I appreciate the advice, I will keep it in mind for the future.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-08-19 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?