« Company's 23rd Birthd… | Home | Windows PDF Classes »

Load PDF from MS SQL Server and display it

We got this sample code for a client combining an example for MS SQL Server with SQLDatabaseMBS class and some sample code for rendering a picture via DynaPDFMBS class from PDF data. Please note that we use ImportPDFPage to only import the page we like to render.

Dim con As New SQLDatabaseMBS Try // we used Microsoft SQL Server via ODBC data source and run app on Windows to test this con.Option("UseAPI") = "ODBC" con.DatabaseName = "ODBC:test" con.RaiseExceptions = True // if you like to get exceptions instead of checking error property con.Scrollable = False // disabling scrolling cursors is much faster for Microsoft SQL Server... con.Connect // go to database test con.SQLExecute "use test" // select PDFData from test table via some ID Dim p As SQLPreparedStatementMBS = con.prepare("SELECT PDFData FROM dbo.test WHERE ID=:ID") p.Bind("ID", 12345) Dim r As RecordSet = p.SQLSelect If r.EOF Then MessageBox "Not found" Else Dim data As String = r.Field("PDFData").StringValue Dim pdf As New DynaPDFMBS // For this example you can use a Pro or Enterprise License pdf.SetLicenseKey "Pro" // create in memory Call pdf.CreateNewPDF Nil // set import flags Call pdf.SetImportFlags pdf.kifImportAsPage + pdf.kifImportAll // open the PDF file Call pdf.OpenImportBuffer(data) // import page to render Call pdf.ImportPDFPage(1) // and render first page Dim out As Picture = pdf.RenderPagePicture(1) // display in window window1.Canvas1.Backdrop = out r.MoveNext End If catch r as SQLErrorExceptionMBS // show error message MsgBox r.message end try
The biggest plugin in space...
08 04 23 - 11:11