Binary data in to pdf file

Hi All,
I wanted to convert binary data from database to pdf. Following are the detailed steps

  1. Fetch the data from database which is in binary format. Eg In table ABC i have coloumn name as XYZdata which is binary data.
  2. Read each of the binary data and convert in to PDFfile.
    It would be really great if any of you provide me a detailed solution as i am struggling to do from past two days.

Thanks in Advance

1 Like

Hi @sangeethasudha,

  • First, install database activities from manage package
  • Get the table from the database using database activity
  • Use for each activity to loop the datatable
  • Get the binary data and convert to byte
  • Use invoke code activity and pass the converted byte and file name as arguments
  • Inside invoke code write the below code
 File.WriteAllBytes("filename.pdf", binaryVariable);
1 Like

Hi @aanandsanraj
Thank you for the response. I am actually looking for the 4th step “Get the binary data and convert to byte” . It would be great if you brief it more.

Thank you

From database you will get the binary data as string in a column. We cannot directly use that as string, so we need to convert that string to byte. Then only we can save that byte as pdf file.

I understood the logic but I am not able to implement. Below is the sample table

ItemID ItemData
1 0100100 (Binary format)
2 0100100 (Binary format)
3 0100100 (Binary format)
Now i need to fetch the data under the column item data and need to convert in to bytes and then in to PDF not sure how to implement. WHen i tried to fetch the coloumn details its just printing me “” in write line instead of content in each cell.

can you help me how to convert the binary data from string to bytes. so that from there i can try to convert it to PDF

Does binary code holds any pdf file? I thought entire pdf file stored as binary data in database. Please clarify the requirement I might understand it wrongly.

yes your understanding is correct. The entire PDFfile is stored as binary data in database.

You have mentioned as to convert from string in to bytes. I am not able to get that coloumn in to string. Could you provide me the steps for this part. so that i can take it from there.

Thank you

Please find the attachment
Main.xaml (6.6 KB)

Thankyou very much . I incorporated your code and I am sucessfuly able to download the PDF. BUt i am unable to open the file "Its thorwing me a error message as " could not open xyz.pdf becuase it either supported file type or because the file has been damaged(For example it was sent as an email attchment or wasnt correctly decoded). This is the mesage I am getting .

Thank You


Did you try to open that file in notepad++? If not please try it and check the result meanwhile I will try myself

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.