Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have stored a pdf file into a varbinary column in sql server using powerbuilder, If I get the byte array in c# and write to a file I cannot open in pdf since pdf header%pdf is not at the start

What I have tried:

Tried reading the Byte array in c# and writing to a file
Posted
Updated 9-Dec-21 3:00am
Comments
Richard MacCutchan 9-Dec-21 8:11am    
If the header is missing then it is possible that something went wrong when you saved the file. You need to check the original against what you are saving.

At a guess - and since I have no idea what Powerbuilder has done, or what exactly you told it to do that is all it can be - the data is not complete, or is corrupt. I'd start with a small PDF (less than 1K, just basic text) created just for this exercise and save that. Then I'd use SSMS to look at exactly what was saved and compare that to the raw binary data in the original file. If that all looked OK, I'd look at the raw data as retrieved from the DB and compare that manually as well.

But the most likely reason is that your powerbuilder didn't store what you think it should have so that's where I'd start.
 
Share this answer
 
You can open the pdf file in an text editor like Notepad++, before saving it. A lot in a pdf file are just ASCII characters.

After retrieving, open also that version in the text editor and compare what has changed. That should give you an idea what went wrong.

I wrote a project on github, a C# sharp application, for viewing the actual pdf file content (i.e. the bytes it contains) and for extracting the text it contains (which is usually packed and can't be read with a text editor):

GitHub - PeterHuberSg/PdfParser
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900