Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Retrieve PDF data from database into a file. Expand / Collapse
Author
Message
Posted Friday, May 13, 2011 6:53 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 01, 2011 2:18 AM
Points: 8, Visits: 37
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



  Post Attachments 
sample.jpg (26 views, 25.08 KB)
Post #1108390
Posted Friday, May 13, 2011 6:59 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Thursday, January 16, 2014 12:03 PM
Points: 21,376, Visits: 9,594
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?
Post #1108391
Posted Friday, May 13, 2011 10:10 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:31 PM
Points: 11,949, Visits: 10,982
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 Moden's 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)
Post #1108603
Posted Tuesday, May 24, 2011 9:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 01, 2011 2:18 AM
Points: 8, Visits: 37
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
Post #1114113
Posted Tuesday, May 24, 2011 9:22 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:31 PM
Points: 11,949, Visits: 10,982
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 Moden's 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)
Post #1114137
Posted Tuesday, May 24, 2011 9:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:31 PM
Points: 11,949, Visits: 10,982
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 Moden's 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)
Post #1114140
Posted Tuesday, May 24, 2011 9:29 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 1:49 PM
Points: 32,768, Visits: 14,929
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
Post #1114144
Posted Tuesday, May 24, 2011 9:48 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 3:43 AM
Points: 4,903, Visits: 8,585
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

Get your two-cent-answer quickly
spaghettidba.com
@spaghettidba
Post #1114170
Posted Wednesday, June 01, 2011 2:22 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 01, 2011 2:18 AM
Points: 8, Visits: 37
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
Post #1117915
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse