SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Retrieve PDF data from database into a file.


Retrieve PDF data from database into a file.

Author
Message
wgrimm
wgrimm
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 53
Hi,
I have read many of the posts about retrieving image data from a table but I must be missing something.

I have a table with invoices stored as PDF image data. I now have to retrieve the binary invoice data and write it to a PDF file so it can be read with Adobe Reader or send via email.
How do I go about achieving this using TSQL ? Or do I have to use CLR (of which I'm not sure yet what that is).
The sample.jpg shows an example of the stored data.

Thanks,
Walter
Attachments
sample.jpg (51 views, 25.00 KB)
Ninja's_RGR'us
Ninja's_RGR'us
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28889 Visits: 9671
I'm not 100% sure of the context.

I've done this a few times in a web application to show the pdf to the web users (no differences there... materialized pdf can be shown or sent).


I don't understand if and why you want to do this on the server.

So what's the full story about this business requirement?
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26121 Visits: 17539
Presumably you want to send this to the front end? What language? This is usually pretty simple.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
wgrimm
wgrimm
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 53
Thanks for your replies.

We have several applications that need to retrieve the PDF from the database. In some cases the PDF must be mailed or presented on a website or downloaded as a file. Not all the applications are web-based and one of the options is to have some of the PDF files ready on the server in which case I'd have to create the files from the SQL data.
For this I want to know how to recreate the PDF file from the database data.
I'm hoping it's straightforward.

kind regards,
Walter Grimm
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26121 Visits: 17539
So do you have pdf or images stored? either way it is basically the same thing. You can pull it out of the db into a byte array. From there you can stream it to where ever it needs to go. What language(s) are you trying to do this in? Web based, windows based?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26121 Visits: 17539
Also there is no need to have store these as a file on the server for the chance that somebody wants to view it. It is really quick and easy to assemble on demand. For your windows app you will probably have to save the byte stream to a file on disc. For you web app you can stream it directly to the response (and set the response mime type), no need to save it to disc at all.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Steve Jones
Steve Jones
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: Administrators
Points: 62588 Visits: 19110
This might help: http://geekswithblogs.net/pakistan/archive/2005/04/19/36884.aspx

You need to SELECT the data from the table, but the client has to deal with the stream.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Gianluca Sartori
Gianluca Sartori
SSCrazy Eights
SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)

Group: General Forum Members
Points: 9868 Visits: 13350
Every time I had to do something similar to this, I used Crystal Reports.
You can create a report with an Image field and read it from a binary column in your db.
Once you have the report object ready, you can export it to PDF and stream it to the client.
You can do it with a web app or with a web service (I'm using the latter to achieve maximum flexibility).
I think you could also do it via CLR, but I don't see the need for such a feature in the database.

--Gianluca Sartori

How to post T-SQL questions
spaghettidba.com
@spaghettidba
wgrimm
wgrimm
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 53
Thanks everyone,

It's now clear that my approach is wrong. I had a look at Steve's link and that will help me
with the other applications/languages we use over here.
I'm familiar with several languages but just not with SQL Server.

kind regards,
Walter Grimm
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search