Create PDF Files with asp and a stored procedure
This section makes it possible to gather a whole of techniques or scripts which have the originality to manage to solve a difficulty with the least effort or which are particularly effective...
Techniques / PDF : Create a PDF from a stored procedure
Original version from Masar Ivica - Visit our sponsors
This article explains how to create a stored procedure and to call it from ASP or directly from SQL Server. The stored procedure will in turn create a simple column based report in PDF without using any external tools or libraries (and their associated licensing costs!).
- How to call the stored procedure from ASP with ADO :
The stored procedure is called SQL2PDF, in order to execute it from ASP the simple way but not the best is to create a connection object to your database and then called the Execute method of this objec, just as follow :
filename = "myPDF"
'Create ADODB connection object
Set cn = Server.CreateObject("ADODB.Connection")
'open db with the connection string
cn.Open "data source name", "userid", "password"
'Execute the procedure in order to create
'the pdf file with no argument
'The same by passing argument:
cn.Execute("SQL2PDF '" & filename & "'")
Set cn = Nothing
SQL2PDF makes a PDF report from text inserted in the table psopdf ( nvarchar(80) ). First a table named psopdf should be created.
CREATE TABLE psopdf (code NVARCHAR(80))
After that create the stored procedure SQL2PDF.
And table psopdf has to be filled with your data as shown in examples below. At the end the stored procedure is called using the file name only (not extension).
Here is the script in order to create the sql2pdf procedure :Launch the procedure and generate a PDF report on the fly