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 - Load from string
  FAQ FAQ  Forum Search   Register Register  Login Login

Load from string

 Post Reply Post Reply
Author
Message
Paul Richardson View Drop Down
Beginner
Beginner
Avatar

Joined: 12 May 08
Location: United Kingdom
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote Paul Richardson Quote  Post ReplyReply Direct Link To This Post Topic: Load from string
    Posted: 13 May 08 at 7:10AM
Hello
 
I'm trying to load a PDF file from an URL however I don't appear to be making any progress.  I'm assuming there isn't a LoadFromUrl function available.
I'm loading the URL into a string and trying to load the pdf using LoadFromString however it doesn't appear to work.  It will happily load the PDF from file so there isn't a problem with the file.  If I load the pdf from file and use the saveasstring option the string only differes from the string I am trying to use in terms of non-printable characters i.e. #$D and #$A.  Does anyone have anyideas as to how to fix the string so it can be loaded?
NB In the code that follows I've just loaded a file directly into a text string from a file it produces the same problem / string but I've included the code to load the URL into a string form completeness.
 
Thanks
 
Paul
 
Code as follows :-
 
procedure TForm1.Button1Click(Sender: TObject);
var
  DefaultPrnName, instr , outstr : string;
  a,b : TQuickPDF;
  opt, res : integer;
  pdfvar : variant;
begin
    res := -1;
  //  pdffile :=  FetchURL('[insert valid http:// url here!]');
    with TStringList.Create do
      try
        LoadFromFile('C:\testin.pdf');
        instr := Text;
      finally
        Free;
      end;
 //   instr := StringReplace(instr,#$D,'',[rfReplaceAll]);
    a := TQuickPDF.Create(nil);
    a.UnlockKey('32363445205D56F99BB6B52279189F55'); // DEMO key!!
    res := a.LoadFromString(instr,length(instr));
    showmessage(IntToStr(res));
    opt := a.PrintOptions(1,1,'EMACS PDF Print');
    showmessage(IntToStr(res));
    a.SaveToFile('c:\test.pdf');
    a.free;
end;
 
function TForm1.FetchURL(const sURL: String): String;
var AmtRead : Cardinal;
  Buffer : array[0..1023]  of char;
  {bufferlength, dwreserv : dword;}
  i:integer;   
  SizeString, WebPage : string;
  SomeName : string;   hHttpSession, hReqUrl : HInternet;   Count : integer;
begin
    WebPage := ''; {a big string where the webpage will go}
    SomeName := 'Web page grabber 1.0';  {whatever ID you want to show up in the servers log}
    hHttpSession := InternetOpen(PChar(SomeName),  {open a handle to the net}
      INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
   hReqUrl := InternetOpenURL (hHttpSession, PChar(SUrl), {request the url from the net}
     nil, 0,0,0);
   try
     Count := 0;
     repeat
               InternetReadFile (hReqUrl, @Buffer,  {read file into 1 KB buffer}
                       sizeof (Buffer), AmtRead);
               If AmtRead <> 0 then begin {code loops through that one last time}
                     If AmtRead = sizeof(Buffer) then
                               WebPage := WebPage + string(Buffer) {store in the big string}
                     else begin {if Amt is less than sizeof(Buffer) on the last go round
                                and you simply append the whole buffer, you will get
                                the end of the file plus whatever crap is left over in
                                the buffer from the previous kilobyte downloaded}
                         for i := 0 to AmtRead - 1 do
                             Webpage := Webpage + Buffer; {the crude way}
                     end; {else begin}
                     Count := Count + AmtRead; {keep track of the bytes read}
                     SizeString := 'Retrieved ' + IntToStr (Count) +
                          ' of ' + SUrl;  {a string you can display of the bytes retrieved}
                end; {AMTread <> 0}
     until AmtRead = 0;  {the file is downloaded}
   finally
     InternetCloseHandle (hReqUrl);
   end;
 finally
   InternetCloseHandle (hHttpSession);
 end;
 result := webpage;
end;
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: 13 May 08 at 8:27AM
Hi!

Loading a pdf via url like you described won't work with QuickPDF.
Why not download (you have a browser unit in your ide) and then using one of the options you have with ShellExecute?

Best regards,
Ingo

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