
Shen
Novice
May 13, 2010, 11:19 AM
Post #1 of 3
(3910 views)
|
Error on Writing to PDF
|
Can't Post
|
|
Hi Guys, I just recently started to use perl and found it very useful. However, I have encountered a problem which I cannot solve. So here it is. I am trying to extract a Blob file from a oracle database and input the data into a pdf file on my local machine. I have used DBI and FileHandle to do this. The code is like this: our $gen_db = "dbi:Oracle:host=59.0.0.12;sid=somename"; my $conn = DBI->connect($gen_db, "user", "password", { RaiseError=>1, PrintError=>1, AutoCommit=>1 }) ||die $DBI::errstr; $conn->{LongReadLen} = 2097152; $conn->{LongTruncOk} = 1; my $sql = qq(SELECT * FROM (select IMAGEID, FILENAME, PDFDOCUMENT from PIMAGECATALOG ORDER BY IMAGEID DESC) WHERE ROWNUM <=1); $sth = $conn->prepare($sql); $sth->execute(); my $filehandler = new FileHandle("container.pdf", "w") or die; my @data; if (@data = $sth->fetchrow_array()) { print $data[0]; print " "; print $data[1]; print "\n"; print $filehandler $data[2]; } $filehandler->close(); #############end of file##################### The oracle part went successfully, and it seems to input something into the pdf file. However, when I try to open the pdf file, it either give me a error "not enough information to display the image" or it display a blank page with nothing in there. I have checked the original file in the database is about 50k in size, but the file I got on my local machine is 51k. I also tried to just read a pdf file on my local machine and write all its content to another pdf file and the same thing occured. This is the code : open(MYINPUTFILE, "<mypdf.pdf");# open for input open(MYOUTFILE, ">container.pdf"); #open for write, append my(@lines) = <MYINPUTFILE>; # read file into list @lines = sort(@lines); # sort the list print MYOUTFILE @lines; close(MYOUTFILE); close(MYINPUTFILE); #############end of file##################### I suppose this is something to do with the filehandle. Has anyone ever encountered the same problem before?
|