0

I have the following textual binary representation: "0x255044462D312E340D0A25FFFFFFF..." I know it's a pdf. I know it's the textual represantation from a sql server column (image data type).

But im lost to find out how to save this binary to a pdf file on my disk and view the content.

Maybe someone can hint me in the right direction.

Best Regards and Thanks in Advance

esc0ba
  • 1
  • 2

3 Answers3

1

You're correct that it is a PDF file (at least it masquerades like on. You have hexadecimally encoded bytes; the first read:

255044462D312E340D0A

%PDF-1.4<CR><LF>

So you appear to have a PDF 1.4 string.

Just take two characters from the string, treat them as hex, convert them to the correct byte and write them to a file. Write binary, not textually (you don't want to add additional line-breaks in there, PDF is too binary to let that work.

(I did the conversion using this site: http://www.dolcevie.com/js/converter.html)

David van Driessche
  • 6,602
  • 2
  • 28
  • 41
0

I'm not sure what database you are working with or how you are getting your string that you have above.

Many databases allow you to save binary data as a blob or some other byte array type. I believe in MSSQL this is called an "image" but I am not 100% on that. I would start by looking into the two following links in order. The first link talks about how to pull byte array data from a database. The example is in Visual Basic but should be easily changed to C# if that is what you are using.

The second link contains an example of how to save that byte array data to the file system.

I would also suggest posting some of the code you have tried as well so that the community may comment and point out areas you possibly had misunderstandings on.

1.) http://support.microsoft.com/kb/308042
2.) Save and load MemoryStream to/from a file

Community
  • 1
  • 1
Frito
  • 1,423
  • 1
  • 15
  • 27
  • Thanks for the reply! Its a Microsoft SQL Database. The point is, i do not have access directly to the database. i just got this "String". and i want to save this binary data to my disk as a pdf. – esc0ba Dec 21 '12 at 22:16
  • How did you get the string? You may also want to look at this StackOverflow question. http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa – Frito Dec 21 '12 at 22:19
  • i got it through a select statement in the output window of the microsoft sql management studio. – esc0ba Dec 21 '12 at 22:24
  • So if you can connect to the DB through the MS SSMS window, why can you not connect to the database programmatically and pull the blob / image that way? – Frito Dec 21 '12 at 22:26
  • This is party of my evaluation... so is it not possible just with this hexadecimal binary(?) string to rebuild the pdf? – esc0ba Dec 21 '12 at 22:32
0

http://www.pdfsharp.com/PDFsharp/ can read in binary data and you can call .Save() and it will make the PDF file to disk for you.

Cubicle.Jockey
  • 3,288
  • 1
  • 19
  • 31