0% found this document useful (0 votes)
182 views1 page

How To Save A PDF Document To A Database

This document describes how to save a PDF document to a database BLOB field using TBlobStream. It explains that PDFtoolkit can save a PDF to a memory stream, which can then be copied to a TBlobStream to store in the database. The code sample shows loading a PDF file into a memory stream, then copying that stream to a TBlobStream connected to a database field to save the PDF in the database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
182 views1 page

How To Save A PDF Document To A Database

This document describes how to save a PDF document to a database BLOB field using TBlobStream. It explains that PDFtoolkit can save a PDF to a memory stream, which can then be copied to a TBlobStream to store in the database. The code sample shows loading a PDF file into a memory stream, then copying that stream to a TBlobStream connected to a database field to save the PDF in the database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

How To Save a PDF Document To A Database

“I want to save a PDF document to a BLOB (Binary Large Object) field.”

By Suraj C. B.

TBlobStream is used to read or write to a BLOB field in a dataset. If you can write a PDF document to a
BLOB field, then you can store the PDF document in an RDBMS database.

PDFtoolkit allows you to save a PDF document to a memory stream. You can then use the memory stream
to copy the PDF document to a TBlobStream instance. The code snippet below shows you how.

procedure TForm1.SavetoBlobClick(Sender: TObject);


var
blob: TBlobStream;
TempStrm: TMemoryStream;
begin
// Create a blob stream for writing
blob := YourDataset.CreateBlobStream(
YourDataset.FieldByName('YOUR_BLOB_FIELD_NAME'),
bmWrite);
try
// Move to the beginning of the blob stream for read operations
blob.Seek(0, soFromBeginning);
// Create a memory stream
TempStrm := TMemoryStream.Create;
// Load a PDF document
gtPDFDocument1.LoadFromFile('C:\Input.pdf');

// Steps for modifying the PDF omitted.

// Save the PDF document to the stream


gtPDFDocument1.SaveToStream(TempStrm);

// Move to the beginning of the memory stream for read operations


TempStrm.Position := 0;
// Copy the stream to the blob
try
blob.CopyFrom(TempStrm, TempStrm.Size)
finally
TempStrm.Free
end;
finally
blob.Free
end;
end;

You might also like