INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

PDF file stored as blob in the database

PDF file stored as blob in the database

(OP)
Hello, I have PDF file which is stored in a blob column in an SQL Server database. The blob was created by a .Net web service (WCF) as a byte array.
In my Delphi XE application I am supposed to "decode" the byte array blob and show the PDF file as it looked originally.
Is this possible to do and if so: How do I do it?
I have a component which can display PDF files but I don't know how to convert it from the blob field!
Thanks!
/Kenbla

RE: PDF file stored as blob in the database

The PDF component you have - Can it load a PDF from a Stream? If not, then you'll have to extract the PDF from the DB, save it to file, then load it into your component. (Also, since you don't have control over how the pdf file is saved to the database, there's no guarantee the code below will save the file as a valid pdf.

CODE

procedure TForm1.GetBlobField;
var
   BS: TBlobStream;
   FS: TFileStream;
begin
   BS := YouQuery.CreateBlobStream(YourQuery.FieldByName('BlobFieldName'), bmRead);
   try
      FS := TFileStream.Create('FilePath\FileName.pdf>' fmCreate);
      try
         FS.CopyFrom(BS, BS.Size);
      finally
         FS.Free;
      end;
   finally
      BS.Free;
   end;
end; 

Now the PDF is in the file you just created, and you can load it into your component, or if the pdf component can use a stream directly, then you don't need the create the FileStream, and read the pdf directly from the BlobStream.

Remember to add the declaration for this method to your form.

CODE

TForm1 = class(TForm)
  ...
private
  procedure GetBlobField;
  ...
end; 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close