Skip to main content
webmandman8
Inspiring
September 23, 2014
Answered

[Coldfusion 10] convert SQL image data type to pdf file

  • September 23, 2014
  • 1 reply
  • 2873 views

The data is of image type in my database table. How do I save this data as a pdf file. The data in the table is already pdf type 0x151C240002000000080008001400... I tried select boxid, datapdf from records where datapdf is not null FileWrite("data.pdf", records.datapdf[1]); It did save the file as a pdf, but upon opening the file is said "it is either not a supported file type or because the file has been damaged".

This topic has been closed for replies.
Correct answer Carl Von Stetten

Maybe, maybe not.  Access unfortunately has a way of screwing up binary (blob) data that is stored in it by adding a wrapper around the data.  I've run across this before, but I don't recall the specifics of what was happening - I think it had something to do with OLE objects versus actual image file data (JPG photos).  I ended up having to have the contractor who was putting data in go back and reinsert the images correctly.

In my case, some of the JPGs were loaded correctly (and migrated into SQL Server correctly), but others were not.  You may have to resort to opening the records in Access and saving the images out to files, then running a separate process to load the images into your database system (you haven't specified which one you are using).

-Carl V.

1 reply

Carl Von Stetten
Legend
September 23, 2014

By "image type", do you just mean that it's a SQL image column (rather than varchar() or int or other column type)?  If so, you still have to know what the data being stored in there is (e.g. TIF, JPG, PDF, etc.).  If the content in that column didn't come from a valid PDF, then you can't write it to a file and expect it to be a valid PDF.

-Carl V.

webmandman8
Inspiring
September 24, 2014

Perhaps you should know that I imported this database data from an access database. In Access I can double click the cell and it opens up the PDF. In the SQL column the data looks like this:  0x151C390002000001100140014002500FFFFFFFF... Yes, it is a SQL image column and I'm pretty sure its pdf data.

Carl Von Stetten
Carl Von StettenCorrect answer
Legend
September 24, 2014

Maybe, maybe not.  Access unfortunately has a way of screwing up binary (blob) data that is stored in it by adding a wrapper around the data.  I've run across this before, but I don't recall the specifics of what was happening - I think it had something to do with OLE objects versus actual image file data (JPG photos).  I ended up having to have the contractor who was putting data in go back and reinsert the images correctly.

In my case, some of the JPGs were loaded correctly (and migrated into SQL Server correctly), but others were not.  You may have to resort to opening the records in Access and saving the images out to files, then running a separate process to load the images into your database system (you haven't specified which one you are using).

-Carl V.