473,416 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

How can I store a PDF file in a SQL database?

Hi!

Each week, we receive a two-page PDF file from UPS along with a separate
flat file (a CSV) The PDF file contains the overview of our weekly invoice
and the CSV contains the details of each shipment.

I download the file from UPS and then use DTS to import the data into
SQL. At that point, I have a Crystal report that prints what looks like a
regular UPS invoice. The only problem is that I wind up with having to print
two things: the overview PDF and my detailed report.

What I'd like to do is store the PDF in a field in SQL and then simply
include that field in the report header (or a subreport) of the crystal
report so that the PDF file displays as the first and second pages of the
report (it's always two pages).

My problem is that I have absolutely no clue how to use DTS or even
VB.Net to take this PDF file sitting in a folder on our network and load it
into a SQL field. I don't even know what kind of field it should be. An
Image field? Binary? I really don't even know where to begin.

I've seen code to upload images and even word docs, but nothing that
would tell me what file type to use or how to code storing a PDF file. I
can't even seem to find out from anyone if I can even display a stored PDF in
a Crystal report, though I know you can an image file.

Any specific suggestions, code snippets, or referrals to examples that
explictly describe how to upload and store a PDF file in a SQL field would be
greatly appreciated. Again, I'm already using DTS to upload the CSV of the
detail data. Might there be a way within DTS? If there is, I couldn't find
it. Perhaps there might be a little piece of VB Script code that I can
include in a field transformation that will upload the file.

Thanks!! I know I can always count on someone here having a great answer.

Karen Grube
kl*****@yahoo.com
Just hyperlinking to the pdf file stored on the network from within the
report won't work. The PDF file has to display fully and be printable the
moment the report opens. It can't depend on someone having to click on a
link.
Jul 21 '05 #1
3 13335
Hello Karen,

You should store the file in a image data type.

The binary data type only allows up to 8k of storage, whereas the image data
type allows up to 2GB of storage.

My first question would be:
1.) Are you sure you want to store the PDF's in the SQL table as opposed to
just a reference/link to the file? This could be quite cumbersome if you
have MANY rows of data.

If you do, then one way would be as follows:

1.) Create a MemoryStream
2.) Use a BinaryFormatter
3.) Call the Serialize method of the formatter and put the contents into
the stream
4.) close the stream
5.) Add to SQL

Here is a quick example.. for reference only..

MemoryStream myStream = new MemoryStream(); BinaryFormatter
myFormatter = new BinaryFormatter();
myFormatter.Serialize(myStream, obj);
long binaryLength = myStream.Length;
myStream.Close();
myCommand.Parameters.Add("@ObjectLen", binaryLength);
myCommand.Parameters.Add("@Object", myStream.ToArray());

Let me know if thats clear...

"Karen Grube" wrote:
Hi!

Each week, we receive a two-page PDF file from UPS along with a separate
flat file (a CSV) The PDF file contains the overview of our weekly invoice
and the CSV contains the details of each shipment.

I download the file from UPS and then use DTS to import the data into
SQL. At that point, I have a Crystal report that prints what looks like a
regular UPS invoice. The only problem is that I wind up with having to print
two things: the overview PDF and my detailed report.

What I'd like to do is store the PDF in a field in SQL and then simply
include that field in the report header (or a subreport) of the crystal
report so that the PDF file displays as the first and second pages of the
report (it's always two pages).

My problem is that I have absolutely no clue how to use DTS or even
VB.Net to take this PDF file sitting in a folder on our network and load it
into a SQL field. I don't even know what kind of field it should be. An
Image field? Binary? I really don't even know where to begin.

I've seen code to upload images and even word docs, but nothing that
would tell me what file type to use or how to code storing a PDF file. I
can't even seem to find out from anyone if I can even display a stored PDF in
a Crystal report, though I know you can an image file.

Any specific suggestions, code snippets, or referrals to examples that
explictly describe how to upload and store a PDF file in a SQL field would be
greatly appreciated. Again, I'm already using DTS to upload the CSV of the
detail data. Might there be a way within DTS? If there is, I couldn't find
it. Perhaps there might be a little piece of VB Script code that I can
include in a field transformation that will upload the file.

Thanks!! I know I can always count on someone here having a great answer.

Karen Grube
kl*****@yahoo.com
Just hyperlinking to the pdf file stored on the network from within the
report won't work. The PDF file has to display fully and be printable the
moment the report opens. It can't depend on someone having to click on a
link.

Jul 21 '05 #2
Hi!

Wow! What I ended up having to do is save each of the two pages of each
pdf as a jpg file, and then storing the jpg files in two SQL image fields!

Crystal reports just wouldn't work and play well with the pdf, whether it
was linked or not. I could never get the pdf to simply display as the first
two pages of the report the way I wanted. BUT, converting the pdf to a jpg,
storing the jpg's and then including those two image (blob) fields in 'group
headers' on the report allows them to display perfectly! I'm a tad bit
concerned about the quality of the jpg conversoin, but it actually prints out
really well and looks fine on the screen.

Thanks for your help! The sample code provided really pointed me in the
right direction.

Thanks again!
Karen

Jul 21 '05 #3
Sure thing, glad you got it figured out....

"Karen Grube" wrote:
Hi!

Wow! What I ended up having to do is save each of the two pages of each
pdf as a jpg file, and then storing the jpg files in two SQL image fields!

Crystal reports just wouldn't work and play well with the pdf, whether it
was linked or not. I could never get the pdf to simply display as the first
two pages of the report the way I wanted. BUT, converting the pdf to a jpg,
storing the jpg's and then including those two image (blob) fields in 'group
headers' on the report allows them to display perfectly! I'm a tad bit
concerned about the quality of the jpg conversoin, but it actually prints out
really well and looks fine on the screen.

Thanks for your help! The sample code provided really pointed me in the
right direction.

Thanks again!
Karen

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: cover | last post by:
The question is, we have two options to store images, either in a Database (MySQL, Postgres, ...) like blob data, or in the hard disk the file and the path in database. Which option is better?...
12
by: Pat A | last post by:
We have a dilemma. We are storing our database password in an include file that resides outside of the web root. The password is in plain text. So, no one can get that password because it can't...
5
by: Lars Behrens | last post by:
Hi there! For a web project I need a little expert help. I don't have written much code yet, just been fiddling around a bit, testing and planning. The web site will have a submission page for...
12
by: jacob nikom | last post by:
Hi, I would like to store XML files in MySQL. What is the best solution: 1. Convert it to string and store it as CLOB/text 2. Serialize it and store as byte array 3. Flatten it out and create...
6
by: Rudy | last post by:
Hello all! I am amazed how many posts I have read to store an image in SQL, and just as many against it. So I learned how to store an image in a SQL db and retrieve the image. A little tricky,...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
2
by: wschanks | last post by:
I have an .adp (Access 2003) file and I need to store files in a field on the database. I have figured out that I need the data type to be 'Image', so I have my table with the this datatype. ...
5
by: lawrence k | last post by:
I'm a little weak on my basic I/O. Help me out please. Is it right to say that I can just open any file with file(), get it as a string, and then store in a MySql database, in, say, a MediumText...
8
by: romayankin | last post by:
I'm making some kind of news-board site on PHP (tthat's why I guess it's the right place to post the question here). Each entry would have a small picture (less then 100kb). Taking into...
0
by: Brian Vanderburg II | last post by:
Lance Gamet wrote: Lance Gamet wrote: One way I've just started to use it to create a utility function to return the location of the user data folder, depending on the operating system: import...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.