unit PdfViewer
experimental;
interface
type
TParams =
record
public type
TPageMode = (none, bookmarks, thumbs);
public var
forceNewInstance: Boolean;
filePath:
String;
startPage: Word;
pageMode: TPageMode;
/// <remarks>
/// Scheint in Acrobat Reader DC keine Auswirkung zu haben sondern
/// sich die Einstellung für jedes Dokument einzeln zu merken
/// </remarks>
showToolbar: Boolean;
showStatusBar: Boolean;
showNavPanes: Boolean;
public
procedure reset();
end;
{TODO -oJM -cCleanup : Umbenennen in TAcroLauncher oder sowas}
TPdfViewer =
class(TObject)
protected
class function getCmdLineArguments(
const forParams: TParams): PChar;
virtual;
public const
executableName = '
AcroRd32';
public
class procedure ShowAsync(
const params: TParams);
virtual;
end;
implementation uses
System.SysUtils, System.Types,
WinApi.ShellApi,
WinApi.Windows,
Spring.Utils
;
type
/// <summary>
/// Schreibt Booleans als '0' oder '1'
/// </summary>
TStringBuilderHelper =
class helper
for System.SysUtils.TStringBuilder
function Append(
const Value: Boolean): TStringBuilder;
overload;
end;
{ TPdfViewer }
class procedure TPdfViewer.ShowAsync(
const params: TParams);
var
info: SHELLEXECUTEINFO;
begin
info :=
Default(SHELLEXECUTEINFO);
info.cbSize := SizeOf(SHELLEXECUTEINFO);
info.fMask := SEE_MASK_DEFAULT;
info.lpVerb := '
open';
info.lpFile := executableName;
info.nShow := SW_SHOWNORMAL;
info.lpParameters := getCmdLineArguments(params);
Win32Check( ShellExecuteEx( Addr(info)) );
end;
class function TPdfViewer.getCmdLineArguments(
const forParams: TParams): PChar;
var
stringBuilder: TStringBuilder;
begin
stringBuilder := TStringBuilder.Create();
try
if forParams.forceNewInstance
then stringBuilder.Append('
/n ');
stringBuilder.Append('
/A ');
stringBuilder
.Append('
"')
.Append('
page=') .Append(forParams.startPage)
.Append('
&toolbar=') .Append(forParams.showToolbar)
.Append('
&statusbar=') .Append(forParams.showStatusBar)
.Append('
&navpanes=') .Append(forParams.showNavPanes)
.Append('
&pageMode') .Append( TEnum.GetName(forParams.pageMode) )
.Append('
"').Append(Space);
stringBuilder.Append('
"').Append(forParams.filePath).Append('
"');
Result := PChar( stringBuilder.ToString() );
finally
stringBuilder.Destroy();
end;
end;
{ TParams }
procedure TParams.reset();
begin
filePath := EmptyStr;
startPage := 1;
showToolbar := False;
showStatusBar := False;
showNavPanes := False;
forceNewInstance := True;
pageMode := TPageMode.none;
end;
{ TStringBuilderHelper }
function TStringBuilderHelper.Append(
const Value: Boolean): TStringBuilder;
begin
Result := Append( Value.ToString(TUseBoolStrs.False) );
end;
end.