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 - How to read the string made by RenderPageToString
  FAQ FAQ  Forum Search   Register Register  Login Login

How to read the string made by RenderPageToString

 Post Reply Post Reply
Author
Message
Mitchell Hu View Drop Down
Beginner
Beginner
Avatar

Joined: 09 Dec 14
Location: Taiwan
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mitchell Hu Quote  Post ReplyReply Direct Link To This Post Topic: How to read the string made by RenderPageToString
    Posted: 09 Dec 14 at 2:50AM
My requirement is try to use RenderPageToString to convert many PDFs to many BMP Strings for keeping all BMP Strings into a Text file, and then read each BMP Strings to memorystream for make bmp which can show in Image for user;
At fisrt try, I use the String  data from  RenderPageToString write in Memorystream, then show bmp in Image, It is fine, But if save the strings form RenderPageToString into files, and read the strings from then saved txt file, seems ansstring data were changed by strings, I can not show those BMP Strings to Image!!!!
Part of code:
//save BMP Strings to txt file
var : renderString : AnsiString;
renderString := ViewPrintQP.RenderPageToString(DPI, ViewPrintPageNum, 0);
MS.Write(PAnsiChar(renderString)^, Length(renderString));
MS.Seek(0,soFromBeginning);
Image1.Picture.Bitmap.LoadFromStream(MS); =======> Here show BMP is fine
if not FileExists('c:\my.txt') then
begin
     AssignFile(Myfile,'c:\my.txt');
      ReWrite(Myfile);
end
else
begin
    AssignFile(Myfile,'c:\my.txt');
    Append(Myfile);
end;
WriteLn(Myfile,renderString);  => write into txt file as Ansistring, but I think it will be                                                                       changed by string!!!
CloseFile(Myfile);

//read saved BMP string for txt file then  to show BMP
  AssignFile(Myfile,'c:\my.txt');
  ReSet(Myfile);
  ReadLn(Myfile,renderString);
  CloseFile(Myfile);
  Ms := TMemoryStream.Create;
  Ms.Write(PAnsiChar(renderString)^,Length(renderString));
  MS.Seek(0,soFromBeginning);
  Image2.Picture.Bitmap.LoadFromStream(MS);=> raise error: Bitmap image is not vaild!!!
  Ms.Free;

Thanks for Any suggestion

Mitchell Hu 

Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 09 Dec 14 at 12:08PM
My suggestion is to stop using strings!  Render the page to stream instead, either direct to a filestream which you can create as a BMP file, or to a memorystream which you can either SaveToFile or load directly into a bitmap.  This will fix your problem; it works for me.
Back to Top
Mitchell Hu View Drop Down
Beginner
Beginner
Avatar

Joined: 09 Dec 14
Location: Taiwan
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mitchell Hu Quote  Post ReplyReply Direct Link To This Post Posted: 09 Dec 14 at 3:15PM
Hi  tfrost:
   thanks for your replay!
 First, I should tell about my requirement! 
 There are  many PDF files ( name card size), user will pick up about 68 pdfs for make a new combine pdf file which size is about A1, so, in ui design , I set up a Pdf list for user pick up , once user pick up a PDF , program use RenderPageToStram let it became a BMP file and show it in TImage component
But, there are two problems:
1. the more big size of PDF, the  more time cost by Render, that means render 68 pdfs will cost more then 1 and half mins, user usually has thousands pdfs , it is unacceptable!!!
2. If user repeat click the 68 PDFs, the program will render those pdf again and again!!!
So, I thinks the only way to deal the requirement, is each PDF only Render to bmp once,  after the Redner the BMP should be stroe in some kind stroe container! and my client do accept save BMP files in a directory for some reason that it is can not ensure user maybe update/delete it!!! so, I think RenderPageToString is the best practice for rendering  PDFs to BMPs, and save each BMP string into a text file at very begging! later, once user pick up a PDF , program can get the PDF's BMP String form saved txt file, and write the string into stram, so the BMP will show in a TImage very soon, because skip rendering process !!!

 
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 09 Dec 14 at 7:02PM
My advice to avoid strings was solely to avoid the issues of string conversions, Unicode, and code pages which are clearly causing your problem.  It does not change your workflow in any way.

If you render each one to stream (in BMP format as would have been in the string) and then savetofile the stream, you will end up with a file that contains exactly what you hoped to find there.  You can even name the file with a .TXT extension if you wish, though that would give its own problems.  Or use PMB instead of BMP if it has to be disguised, and only you will read it.  Or save the BMP content in a database blob.  It will contain the same content as the string but it will work, and will be faster, too.  Do try it!
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