Forum Discussion
Read pdf file stored in SQL Server DB
Hi ,
We have a requirement to read the pdf file which is stored in SQL Server and display it on Power BI Report.
Hi Anonymous
Are you PDF files stored in a table in binary format, or can you otherwise connect to the binary data?
If so, you can load the binary data, convert to Base64 with Power Query, then display using the PDF Viewer visual.
There are some limitations on text length in Power Query (32,766 characters) and DAX (2.1 million characters)
so you may have to split the Base64 strings up.
I ran a quick test myself with the binary contents of PDF files stored in a SQL Server table varbinary(max) column.
The steps I had to follow:
- Load SQL Server table into Power Query.
- Convert to Base64 using Binary.ToText.
- User Splitter function to split text into lengths of < 32,766 characters, and add an Index column.
- Load the resulting table to the data model.
- Create a DAX calculated table which concatenates the segments of Base64 string for each PDF file.
- Display using the PDF Viewer visual. This visual only accepts a column, not a measure (hence the need for step 5).
Sample PBIX attached.
Let me know if this helps in your situation.
Note: The author of the PDF Viewer visual also provides a sample PBIX file.
Regards,
Owen
1 Reply
- OwenAugerSuper User
Hi Anonymous
Are you PDF files stored in a table in binary format, or can you otherwise connect to the binary data?
If so, you can load the binary data, convert to Base64 with Power Query, then display using the PDF Viewer visual.
There are some limitations on text length in Power Query (32,766 characters) and DAX (2.1 million characters)
so you may have to split the Base64 strings up.
I ran a quick test myself with the binary contents of PDF files stored in a SQL Server table varbinary(max) column.
The steps I had to follow:
- Load SQL Server table into Power Query.
- Convert to Base64 using Binary.ToText.
- User Splitter function to split text into lengths of < 32,766 characters, and add an Index column.
- Load the resulting table to the data model.
- Create a DAX calculated table which concatenates the segments of Base64 string for each PDF file.
- Display using the PDF Viewer visual. This visual only accepts a column, not a measure (hence the need for step 5).
Sample PBIX attached.
Let me know if this helps in your situation.
Note: The author of the PDF Viewer visual also provides a sample PBIX file.
Regards,
Owen