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!
(Delphi 7) How to open PDF from Oracle Database? |
Post Reply |
Author | |
jhsj
Beginner Joined: 23 May 13 Status: Offline Points: 5 |
Post Options
Thanks(0)
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 |
|
jhsj
Beginner Joined: 23 May 13 Status: Offline Points: 5 |
Post Options
Thanks(0)
|
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! |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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 |
|
jhsj
Beginner Joined: 23 May 13 Status: Offline Points: 5 |
Post Options
Thanks(0)
|
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 |
|
jhsj
Beginner Joined: 23 May 13 Status: Offline Points: 5 |
Post Options
Thanks(0)
|
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 |
|
Wheeley
Senior Member Joined: 30 Oct 05 Location: United States Status: Offline Points: 146 |
Post Options
Thanks(0)
|
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 |
|
jhsj
Beginner Joined: 23 May 13 Status: Offline Points: 5 |
Post Options
Thanks(0)
|
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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store