CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to correctly return a PDF file in response to a query?

 



zhukovi
New User

Apr 25, 2017, 8:20 AM

Post #1 of 4 (1101 views)
How to correctly return a PDF file in response to a query? Can't Post

I have a perl script that receives binary data from another script (PDF file). The question is how to transfer this data to another script. I try so.

Code
$con = $response->content; 
open (OUT2,">11.txt") || die;
print OUT2 $con;
close OUT2;
binmode $con;
print "Content-Type: application/octet-stream;;\n";
print "Content-Length: ".length($con)."\n";
print "Content-Disposition: attachment; filename=FILE.pdf\n\n";
print $con;

Data comes in utf8 encoding. I tried to recode

Code
Encode::_utf8_off($con); 
Encode::from_to($con, 'utf-8', 'windows-1251');
print encode("cp1251", decode("utf8", $con));

Comes already in ANSI but the characters are not the ones. And if you save the string $ con in perle to a file, you get everything in the right format. Tell me what I'm doing wrong?


Laurent_R
Veteran / Moderator

Apr 25, 2017, 11:04 PM

Post #2 of 4 (1089 views)
Re: [zhukovi] How to correctly return a PDF file in response to a query? [In reply to] Can't Post

I am not sure what your problem is, but one thing is sure to me:


Code
binmode $con;


does not make sense. binmode takes an filahandle (and optionally an IO layer) as argument(s), but is not designed to act on a string (and my best guess is that $con is a string).


zhukovi
New User

Apr 26, 2017, 3:32 AM

Post #3 of 4 (1085 views)
Re: [Laurent_R] How to correctly return a PDF file in response to a query? [In reply to] Can't Post

Yes $con is a string with binary data, represents a pdf file. This

Code
binmode $con;

I put as a result of the search for a solution and its absence does not affect the result in any way. Is there any idea what I'm doing wrong? I have not been able to get this damn file for weeks. Can you give a link to a working example of sending a file out of perl? By the way the script file of the perl is in my encoding utf8, if it has.


zhukovi
New User

Apr 26, 2017, 11:15 AM

Post #4 of 4 (1076 views)
Re: [zhukovi] How to correctly return a PDF file in response to a query? [In reply to] Can't Post

I found a mistake. The problems were in the host of JS. This it converted to UTF8 when writing to a file.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives