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!
Load from string |
Post Reply |
Author | |
Paul Richardson
Beginner Joined: 12 May 08 Location: United Kingdom Status: Offline Points: 3 |
Post Options
Thanks(0)
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; |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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 |
|
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