Print Page | Close Window

Load from string

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=895
Printed Date: 14 May 24 at 2:39PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Load from string
Posted By: Paul Richardson
Subject: Load from string
Date 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;



Replies:
Posted By: Ingo
Date 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




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