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!
ShellExec and a bit more (delphi) |
Post Reply |
Author | |
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
Posted: 01 Nov 05 at 12:13AM |
Often i've read questions about how to show/open a pdf-file with QuickPDF. Why you want to do this with QuickPDF? Everybody who's working with pdf-files have installed a pdf-reader... so why not use it? For this you can use ShellExecute or (better) ShellExec ('cause it supports long file names and offers you more features).
If you don't want to work with the real name "acrord32" you can use my second example as well. All in Delphi but i think other languages offers the same. Some more special code is "Keybd_Event...". You know pressing the shift-key while opening a pdf-file supress the loading of many dlls (from the acrobat reader) which you often don't need. So in my code first i simulate a pressed shift key and after ShellExec i simulate a released shift key. Best regards, Ingo . . . uses ShellAPI . . . function ShellExec( op, fn, par, dir: PChar; show: Word; wait: Boolean): LongInt; var ih: Word; OK: Boolean; Info: TShellExecuteInfo; begin FillChar(Info, SizeOf(Info), Chr(0)); Info.cbSize := SizeOf(Info); Info.fMask := SEE_MASK_NOCLOSEPROCESS; Info.lpVerb := op; Info.lpFile := fn; Info.lpParameters := par; Info.lpDirectory := dir; Info.nShow := show; OK := Boolean(ShellExecuteEx(@Info)); if OK then begin if wait then begin while WaitForSingleObject(Info.hProcess,100) = WAIT_TIMEOUT do Application.ProcessMessages; OK := GetExitCodeProcess( Info.hProcess, DWord(Result)); end else Result := 0; end; if not OK then Result := -1; end; . . . // Anywhere in your program ... perhaps at an onclick-event: . . . Keybd_Event(vk_Shift,0,0,0); ShellExec('open',PChar('acrord32.exe'),PChar('/s ' + ExtractFilePath(Application.ExeName) + 'example.pdf'),nil,SW_SHOWNORMAL,True); Keybd_Event(vk_Shift,0,KEYEVENTF_KEYUP,0); // and a second solution... . . . ShellExec('open',PChar(GetProgramAssociation('pdf')),PChar('/s ' + ExtractFilePath(Application.ExeName) + 'example.pdf'),nil,SW_SHOWNORMAL,True); . . . Edited by Ingo |
|
Cheers,
Ingo |
|
DafCorpX
Beginner Joined: 06 Dec 05 Location: Sweden Status: Offline Points: 1 |
Post Options
Thanks(0)
|
Nice code just wanted to show abnother way to open or print the pdf file. uses ShellAPI ShellExecute( Form1.Handle, 'OPEN', PChar(TheFullPDFFilenameWithPath), nil, nil, sw_shownormal);
This will either OPEN the file with it's associated progranm or PRINT it with the same program Saves the tedious way to find AcroRead or whatever program that's associated with PDF files. Goodluck |
|
//Dan
|
|
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