in reply to extract pdf from blob

bobdole:

A few points:

1) If the blob contains a pdf file that's not encoded in any fashion, and you're doing a console app and just want a PDF file, then you'd just extract it and save it with a pdf extension.
2) If the blob contains a pdf file that's not encoded in any fashion, and you're doing a Web app and are returning a PDF file, set the mime type appropriately.
3) Not to be snide, but this is PerlMonks, and we generally want to talk about Perl-related topics. For database topics there are suitable forums. Please use them.
4) Your question is too vague to be able to expect any useful answers. You might want to examine How (Not) To Ask A Question.

--roboticus

Replies are listed 'Best First'.
Re^2: extract pdf from blob
by bobdole (Beadle) on May 18, 2006 at 14:18 UTC
    The pdf is encoded because you cant just export it with a pdf extensions. And maybe I should have been more clear in my post how do I convert the blob file with PERL into a readable pdf.
      That depends .... how is it encoded?
      Basically, the procedure would be something like:

      #!/usr/bin/perl -w use strict; use warnings; [code to open database] sub decode { my $encoded_data = shift; [code to decode $encoded_data to $decoded_data] return $decoded_data; } my $blob; [code to get column from database and put into $blob] my $pdf = &decode($blob); open(OUT_PDF, ">DOCUMENT.PDF") or die "Can't open file!"; print OUT_PDF $pdf; close(OUT_PDF);
      The chunks in the square brackets are the bits of Perl code that I can't specify because you didn't give enough clues.

      For the first one, you need to get access to your database. In the Perl community, it seems that the DBI package is the most popular (it's what I use). I don't know anything about DBISAM, so I don't know if there's a DBI driver module available for it. If not, then you could use the ODBC driver (again, that's what I usually use), providing you have an ODBC driver for your database.

      For the second item (the decode function), I can't help you with that as you haven't told me anything about the encoding scheme. If you know the encoding scheme, look on CPAN for a module that will decode the appropriate scheme, and plug in the appropriate code.

      In the final chunk, if you used DBI, you could use something like this:

      my $STH = $DBH->execute("SELECT [column] " . "FROM [table] " . "WHERE [condition]") or die "WTF? I can't find what you're looking for!"; my $array_ref = $STH->fetchrow_arrayref; $blob = $array_ref->[0];
      Of course, there are now a few new blanks to fill in which you'll have to determine, because you didn't say.

      --roboticus