Print Page | Close Window

(Delphi 7) How to open PDF from Oracle Database?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2653
Printed Date: 22 Nov 24 at 1:35PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: (Delphi 7) How to open PDF from Oracle Database?
Posted By: jhsj
Subject: (Delphi 7) How to open PDF from Oracle Database?
Date Posted: 23 May 13 at 8:50PM
Hi!

I have an Oracle Database with blob fields used to store some pdf files.

I am trying to use Debenu Quick PDF to read these PDF blobs from Oracle and save them into PDF files (C:\ folder).

I have the following Delphi 7 code:

procedure TForm1.Button3Click(Sender: TObject);
var i, DocumentID, OK: Integer;
    blob: TStream;
begin
// snipped some code used to open the object QryStream (TQuery type) and to create
// the QP object

         while not QryStream.Eof do
           begin
             Inc(i);
             blob := QryStream.CreateBlobStream(QryStream.FieldByName('Content'),bmRead);
             OK := QP.LoadFromStream(blob,'');
             if OK <> 0 then
               begin
                 DocumentID := QP.SelectedDocument();
                 QP.DASaveAsFile(DocumentID,'C:\File_' + IntToStr(i) + '.pdf');
               end
             else
                 ShowMessage('Error: ' + IntToStr(QP.LastErrorCode));
             QryStream.Next;
           end;
       end;

The code below:
OK := QP.LoadFromStream(blob,'');
gives an Access violation error at address XXXXXXX

What am I doing wrong here?
I really need to read these PDFs stores and to save them as files!

Thank you!
Henrique



Replies:
Posted By: jhsj
Date Posted: 24 May 13 at 8:11PM
OK, I was using TQuery object (instead of DBExpress) and found out it was giving me the errors I mentioned in the opening post. So, I changed to dbexpress object and the errors vanished  :)

Also I changed the source code to:

         while not ClientDataSet1.Eof do
           begin
             Inc(i);
             blob := ClientDataSet1.CreateBlobStream(ClientDataSet1.FieldByName('Content'),bmRead);
             blob.Seek(0,soFromBeginning);
             OK := QP.DAOpenFromStream(blob,'');
             if OK <> 0 then
               begin
                 DocumentID := QP.SelectedDocument();
                 QP.DASaveAsFile(DocumentID,'C:\File' + IntToStr(i) + '.pdf');
               end
             else
               begin
                 ShowMessage('Error: ' + IntToStr(QP.LastErrorCode));
                 Exit;
               end;
             ClientDataSet1.Next;
             blob.Free;
           end;
       end;

The program runs without errors but it DOES NOT CREATE ANY of the pdf files (whose names would be File1.pdf, File2.pdf, ..., FileXXX.pdf) on my C:\ folder.

I am running it with admin privileges. Disk space is not a problem, of course.

Any help?
Thank you!


Posted By: Ingo
Date Posted: 25 May 13 at 1:11PM
Sure that you have enough access-/writing rights to write directly at c:\?!
The other thing: First try it more easy with only one file to make it easier
finding the problem...
What's the returning value from DASaveAsFile?

Cheers and welcome here,
Ingo


Posted By: jhsj
Date Posted: 25 May 13 at 3:49PM
Yes, now I see I forgot to test the returning value of DASaveAsFile.
I'll test it only on Monday (May 27th) and then I'll return here to post the results (and more doubts, if it's the case).
Thank you for your reply!
Henrique



Posted By: jhsj
Date Posted: 27 May 13 at 2:18PM
Well,

I tested the returning value of DASaveAsFile (as Ingo suggested) and it's returning zero. And the files aren't being created on C:\ folder.

I rewrote the code using only Delphi instructions:
     i := 0;
     while not ClientDataSet1.Eof do
       begin
         Inc(i);
         blob := ClientDataSet1.CreateBlobStream(ClientDataSet1.FieldByName('Content'),bmRead);
         blob.Seek(0,soFromBeginning);
         NewFile := TFileStream.Create('C:\File' + IntToStr(i) + '.pdf',fmCreate or fmShareDenyRead);
         try
           NewFile.CopyFrom(blob,blob.Size);
         finally
           FreeAndNil(NewFile);
         end;
         ClientDataSet1.Next;
       end;

And the files File1.pdf, File2.pdf, FileXXX.pdf are being created on C:\ folder.
I can open'em and read'em normally in Adobe Reader. It means I do have admin privileges to write files to the C:\ folder, as I already expected.
Where is the error on my Delphi code which uses Debenu functions?
I know I can stick to the "pure" Delphi code to read and write the files from blob to disk, but I want to use quickpdf to do that.
My intention is to read a bunch of pdf's in blob fields, merge them all in one pdf file and open this one file using Adobe or other PDF viewer.
From what I've read (please, anyone here can correct me if I'm wrong), in order to do that I must:
-First: save these blob files separately on disk, one at a time;
-Second: merge them using MergeFiles or MergeFileList;
-Third: save this one big file (result of merged files) to disk;
-Finally: open it with PDF viewer
I also know these operations above may bring other doubts which will be posted here if it's the case.

Thanks!
Henrique


Posted By: Wheeley
Date Posted: 27 May 13 at 10:23PM
Why not try the non-direct access functions as well. Maybe your stream can't be used with the direct access functions since it is not on the disk drive yet.

Wheeley


Posted By: jhsj
Date Posted: 28 May 13 at 3:09PM
It worked!

I changed the instruction DAOpenFromStream to LoadFromStream and also changed DASaveAsFile to SaveToFile and it finally worked!
The code now is:
while not ClientDataSet1.Eof do
           begin
             Inc(i);
             blob := ClientDataSet1.CreateBlobStream(ClientDataSet1.FieldByName('Content'),bmRead);
             blob.Seek(0,soFromBeginning);
             OK := QP.LoadFromStream(blob,'');
             if OK = 0 then
               begin
                 ShowMessage('File could not be read! Error: ' + IntToStr(QP.LastErrorCode));
                 Exit;
               end
             else
               begin
                 DocumentID := QP.SelectedDocument();
                 FileSaved  := QP.SaveToFile('C:\File' + IntToStr(i) + '.pdf');
                 if FileSaved = 0 then
                   begin
                     ShowMessage('Error: file could not be created!');
                     Exit;
                   end;
               end;

Now, to the task of merging the files just created!

Thanks to everyone who helped me!
Henrique



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk