Search code examples
t-sqlpdfreporting-servicesautomationfile-manipulation

Manipulate PDF via SQL


what I want to do is automatically create PDFs with data from SQL Server 2008 R2. After creation a string shall be added in the first line of the file. This "header" has to be clear text (right click PDF -> edit -> write string in the first line) and therefore can't be added in the pdf-creation process. The codes in the header are beeing used by another job for further processing.

Is there a way to do that via SQL?

Sample data looks like:

   Name   |   Date   |   Time   |   Place   |   Appointment
John Doe  |2014-09-15|   11:00  |   Narnia  |   12:30

I already found ways to create the PDF, using SSRS and subscription or the procedure mentioned here: http://www.sqlservercentral.com/articles/Miscellaneous/creatingapdffromastoredprocedure/1104/

But I wasn't able to write text to first line, just appended it at the end of the file.

Any help is much appreciated!


Solution

  • This can not be done in SQL. There are a few options that I now of that you can look into to see if it will suite your needs.

    NOTE : These are not trivial tasks.

    1. Implement your own device renderer, falling back on the default pdf render.
    2. Override the built in pdf renderer to add your custom header.
    3. Use the SSRS web service api and implement the Render method allowing the access to the Pdf as byte[] and further manipulate it to your needs.

    The 3rd method would be the most straightforward and ideal method and would work in both web and windows apps.