1. Faisal Hayat
  2. PowerBuilder
  3. Friday, 17 May 2019 10:15 AM UTC

Hi All

I am trying to save a pdf file in database and then fetching pdf data from database to create pdf file from it. BUT the created pdf file is not being opened showing message that it damaged or corrupt. Here are the implementation details

PowerBuilder: 2017 R3

Database: Informix

PDF data holding column type: TEXT

Saving Data:

long ll_file, ll_bytes, ll_pdf_key = 1
blob lblob_file


ll_file = FileOpen("C:\test.pdf", StreamMode!)
ll_bytes = FileReadEx(ll_file, lblob_file) /* ll_bytes value is 7982565*/
FileClose(ll_file)
if ll_bytes > 0 then

Updateblob table_pdf
set pdf_data = :lblob_file
where pdf_key = :ll_pdf_key
using SQLCA;


end if

Fetching Data and write to PDF

blob lb
long ll_file, ll_count, ll_pdf_key = 1
selectblob pdf_data
into :lb
from table_pdf
where pdf_key = :ll_pdf_key;

ll_file = FileOpen("C:\generate.pdf", StreamMode!, Write!, LockReadWrite!, Replace!)
ll_count = FileWriteEx(ll_file, lb) /* ll_count value is 7982564 */
FileClose(ll_file)

 

As I have highlighted counts above I think I am missing or having extra BOM character or I am using wrong column data type. Your help will be highly appreciated. Thanks

Accepted Answer
Faisal Hayat Accepted Answer Pending Moderation
  1. Friday, 17 May 2019 11:33 AM UTC
  2. PowerBuilder
  3. # Permalink

I was able to sort out the issue after changing datatype from TEXT to Binary in database.

Comment
  1. Armeen Mazda @Appeon
  2. Friday, 17 May 2019 15:28 PM UTC
Thanks for posting the solution!
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.