Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - (Delphi 7) How to open PDF from Oracle Database?
  FAQ FAQ  Forum Search   Register Register  Login Login

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

 Post Reply Post Reply
Author
Message
jhsj View Drop Down
Beginner
Beginner


Joined: 23 May 13
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote jhsj Quote  Post ReplyReply Direct Link To This Post Topic: (Delphi 7) How to open PDF from Oracle Database?
    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
Back to Top
jhsj View Drop Down
Beginner
Beginner


Joined: 23 May 13
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote jhsj Quote  Post ReplyReply Direct Link To This Post 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!
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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


Edited by Ingo - 25 May 13 at 1:11PM
Back to Top
jhsj View Drop Down
Beginner
Beginner


Joined: 23 May 13
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote jhsj Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
jhsj View Drop Down
Beginner
Beginner


Joined: 23 May 13
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote jhsj Quote  Post ReplyReply Direct Link To This Post 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


Edited by jhsj - 27 May 13 at 2:21PM
Back to Top
Wheeley View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Oct 05
Location: United States
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote Wheeley Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jhsj View Drop Down
Beginner
Beginner


Joined: 23 May 13
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote jhsj Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store