Print Page | Close Window

Problem SaveToString / LoadFromString

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=413
Printed Date: 25 May 24 at 1:28PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Problem SaveToString / LoadFromString
Posted By: ECPVFR
Subject: Problem SaveToString / LoadFromString
Date Posted: 17 May 06 at 8:56AM
I need to write/read PDF files into/from a database (Interbase/Firebird).

The best way I see with quicPDF is to convert the PDF into a string (SaveToString), then write this into a BLOB. With LoadFromString it should be possible to recreate the PDF.

The first step was no problem (I created a text file as output, and this really contained the content of the PDF). But when I try to load the "text-PDF", the LoadFromString functions returns an error and the TiSEDQuickPDF is empty.

Where is my mistake?



Replies:
Posted By: JanN
Date Posted: 17 May 06 at 10:29AM
Just a thought: Did you try to save that string to file? Is that pdf file accessible by Adobe Reader?


Posted By: ECPVFR
Date Posted: 17 May 06 at 10:58AM
Hello Jan!

My project exported and saved the original PDF to an ASCII string. This file is accessible with Acrobat/Acrobat Reader (both are complaining the 'file is damaged', but they do open correctly).

I think I found another (WORKING) way saving PDFs into database (RenderDocumentToFile -> JPG and ExtractFilePageText -> TXT); when reading the "PDF", the JPG will be displayed instead...

Main problem is increase of file size (PDF 4kb, JPG 135kb with 150dpi).
__________________
Best Regards,
Volker

-------------
Best Regards,
Volker


Posted By: ECPVFR
Date Posted: 17 May 06 at 11:59AM
Finally I found the solution for my problem:

1) Saving each page of the PDF as ASCII with function ExtractFilePageText(sFileName, '', iPage, 2)
-> infos for text position, fontsize/font are exported too!
2) Writing this string into database.
3) When reading from database, each line of PDF is added with DrawText.
-> a virtual copy of original PDF is displayed!

This works fine for me, because my PDF do not contain pictures!

-------------
Best Regards,
Volker


Posted By: cpri
Date Posted: 18 May 06 at 8:59AM

Why don't you save the pdf as a BLOB in your database with SaveToStream.

code for reading and writing the pdf to and from the database

/code

procedure TMydbase.read_datasheet(indexnummer:integer);
var  blob : tstream;
begin
query_open('select * from Table where indexnummer = '+ ''''+inttostr(indexnummer)+'''');
blob:=query.createblobstream(query.Fieldbyname('datasheet'),bmread);
blob.seek(0,sofrombeginning);  //I always save the current pdf to my HD but you cal load it in your quickpdf object as well
with tfilestream.create('c:\default.pdf',fmcreate) do
     try
     copyfrom(blob,blob.size);
     finally
     free;
     end;
blob.free;
query.Close;
end;

procedure TMydbase.write_datasheet(type_meting,tekeningnr,operator,datum,tijd,bewerking,kommentaar:string;pijp_nr,array_nr,indexnummer_meting:integer);
var sql_:string;
begin
sql_:='insert into Tabel(indexnummer,datasheet) ';
sql_:=sql_+'values(:indexnummer,:datasheet)';
Query.SQL.Clear;
query.sql.add(sql_);
query.prepare;
query.parambyname('indexnummer_meting').value:=indexnummer;
Query.ParamByName('datasheet').LoadFromFile('c:\default.pdf',ftblob); //you should use load fromstream instead
execute_sql;
end;


code



Posted By: ECPVFR
Date Posted: 18 May 06 at 10:03AM
Thanks Christian, I'll try that next!

-------------
Best Regards,
Volker


Posted By: ECPVFR
Date Posted: 18 May 06 at 12:56PM
Hello Christian!

The importing with "SaveToStream"/"LoadFromStream" did NOT work at all, but I sneaked through Interbase/FireBird/IBO documentation and found another possibility...
Now I don't need QuickPDF for writing/saving; I can do this like

with IB_QWORK do
TRY
   active := FALSE;
   ParamByName('aID').AsInteger := IDX;
   ParamByName('aFNAME').AsString := ExtractFileName(sTMP);
   ParamByName('aDATA').LoadFromFile(sTMP);
   execSQL;
   ...
EXCEPT
   ...
END;

For loading the PDF I can act similar ( FieldByName('DATA').SaveToFile(...))

But Your idea was the final solution (writing BLOB directly)!
THANKS!

-------------
Best Regards,
Volker


Posted By: cpri
Date Posted: 23 May 06 at 1:33AM

Ok glad you worked it out.

I will try the SaveToFile as well. It takes less code and memory

So thanks for the tip



Posted By: cpri
Date Posted: 23 May 06 at 4:18AM

Hello

ParamByName('Data').LoadFormFile works great but I can't find the function FieldByName('Data').SaveToFile.

am I missing something. I'm using the standard Interbase components



Posted By: ECPVFR
Date Posted: 23 May 06 at 6:33AM
Hello!

Our company is using Interbase/FireBird as default SQL server database. For database access we have Jason Wharton's great 'IBO' components (InterBase Objects) and these allow FieldByName('xx').SaveToFile.


-------------
Best Regards,
Volker


Posted By: cpri
Date Posted: 23 May 06 at 8:36AM

ok

It's a pitty the standard interbase components from borland don't support the function. But the methode I use works fine

Thanks anyway



Posted By: swb1
Date Posted: 23 May 06 at 1:33PM

I have never used the interbase components… so I ignorantly ask… Couldn’t you just cast the field component as TBlobfield? i.e.:

 

Table.FieldByName(‘xyz’) as TBlobField.SaveToFile(FileName);



Posted By: ECPVFR
Date Posted: 30 May 06 at 2:41AM
Hi swb1,

of course I could. But inside our BLOBs there are/can be german special characters and with IBO I'm sure (has been tested!) the input and output is correct without additional work.

Besides: IBO is very stable, quick and well supported!!!

We have been using the "BDE" for some (horrible) years and since we have (mostly) replced BDE with IBO, things have become much better!


-------------
Best Regards,
Volker


Posted By: ECPVFR
Date Posted: 01 Jun 06 at 5:06AM
Hi swb1,

I have tested TBlobField(Query.FieldByName('PDFBLOB')).SaveToFile(sFileName) (with BDE components) and it doesn't work at all!
It is showing 'cannot transliterate characters between character sets' even if I set 'transliterate' to FALSE!

So I have to use the IBO components (or waste hours/days to get BDE components working somehow...)

-------------
Best Regards,
Volker



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