Can I convert a database field from binary to a PDF file in SQL Server?

Romelfanger, Matt 20 Reputation points
2023-06-23T17:56:16.4533333+00:00

I have a SQL Server database in which there are PDF documents stored in a column with the binary data type. I need to figure out how to get the actual PDF document out.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,494 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rosa Alden 110 Reputation points
    2023-06-23T18:14:04.33+00:00

    Hi@Romelfanger, Matt,

    Yes, I faced a similar issue where I needed to convert a binary field in a SQL Server database to a PDF file. To solve this problem, I used a combination of SQL Server functions and programming. First, I extracted the binary data from the database using a SELECT statement.

    Then, I used a programming language like C# to convert the binary data into a PDF file by writing the binary data to a file with a .pdf extension. This allowed me to retrieve the actual PDF document from the binary field in the SQL Server database.


1 additional answer

Sort by: Most helpful
  1. J Gonzalez 46 Reputation points
    2025-04-23T23:46:18.2666667+00:00

    Hi @Rosa Alden ,

    How did you manage to convert them to pdf? If the .bin is encrypted how can this be done? I have a server I can see the .bins in the volume E of the server, however when I edit the .bin its just gibberish. I would need these converted to pdfs. Thank you for your help.

    0 comments No comments

Your answer