diff --git a/.gitignore b/.gitignore
index 491e385..71e185c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,5 @@ __history
*.tds
.backup
__recovery
-/Chromium88.2
-/Chromium88
+/Chromium*
/Releases
diff --git a/cefHtmlSnapshot.dpr b/cefHtmlSnapshot.dpr
index cd02041..ff999e8 100644
--- a/cefHtmlSnapshot.dpr
+++ b/cefHtmlSnapshot.dpr
@@ -59,7 +59,7 @@ uses
{$ELSE}
SysUtils,
{$ENDIF }
- uCEFApplication, uCEFApplicationCore,
+ uCEFApplication, uCEFApplicationCore, TypInfo, uCEFTypes,
{$ifdef USE_BUNDLE} UChromiumBundle,{$endif}
uEncapsulatedBrowser in 'uEncapsulatedBrowser.pas',
uCEFBrowserThread in 'uCEFBrowserThread.pas',
@@ -139,12 +139,15 @@ begin
try
{$ifdef USE_BUNDLE}
vChromiumBundleQuickCheck := True;
- CreateGlobalCEFApp(parameters, ChromiumUnBundledPath);
+ if CreateGlobalCEFApp(parameters, ChromiumUnBundledPath) then begin
{$else}
- CreateGlobalCEFApp(parameters);
+ if CreateGlobalCEFApp(parameters) then begin
{$endif}
- if WaitForMainAppEvent then
- WriteResult;
+ if WaitForMainAppEvent then
+ WriteResult;
+ end else begin
+ Writeln(GlobalCEFApp.LastErrorMessage);
+ end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
diff --git a/cefHtmlSnapshot.dproj b/cefHtmlSnapshot.dproj
index fa97949..a3211b6 100644
--- a/cefHtmlSnapshot.dproj
+++ b/cefHtmlSnapshot.dproj
@@ -89,7 +89,7 @@
true
false
3
- https://www.delphitools.info/ --javascript Scripts\cookie-law-buster.js snapshot.jpg
+ https://www.google.com test\test1.pdf
true
cefHtmlSnapshot_Icon.ico
true
diff --git a/cefHtmlSnapshot.res b/cefHtmlSnapshot.res
index 8c7bbd8..60b24fc 100644
Binary files a/cefHtmlSnapshot.res and b/cefHtmlSnapshot.res differ
diff --git a/uCEFBrowserThread.pas b/uCEFBrowserThread.pas
index 45ddb17..b7e353e 100644
--- a/uCEFBrowserThread.pas
+++ b/uCEFBrowserThread.pas
@@ -804,7 +804,7 @@ function TCEFBrowserThread.TakeSnapshot : boolean;
try
FBrowserInfoCS.Acquire;
- if FParameters.OutputFormat = sofPDF then begin
+ if FParameters.OutputFormat in [ sofPDF, sofPrinter ] then begin
FBrowser.PDFPrintOptions.page_width := FParameters.PDFOptions.page_width;
FBrowser.PDFPrintOptions.page_height := FParameters.PDFOptions.page_height;
FBrowser.PDFPrintOptions.margin_type := FParameters.PDFOptions.margin_type;
@@ -817,7 +817,9 @@ function TCEFBrowserThread.TakeSnapshot : boolean;
FBrowser.PDFPrintOptions.landscape := FParameters.PDFOptions.landscape <> 0;
FBrowser.PDFPrintOptions.header_footer_enabled := (FParameters.PDFTitle <> '') or (FParameters.PDFURL <> '');
FBrowser.PDFPrintOptions.backgrounds_enabled := FParameters.PDFOptions.backgrounds_enabled <> 0;
- FBrowser.PrintToPDF(FParameters.OutputFilePath, FParameters.PDFTitle, FParameters.PDFURL);
+ if FParameters.Print then
+ FBrowser.Print
+ else FBrowser.PrintToPDF(FParameters.OutputFilePath, FParameters.PDFTitle, FParameters.PDFURL);
end else begin
if assigned(FPanel.Buffer) and not(FPanel.Buffer.Empty) then
begin
diff --git a/uCEFSnapshotParameters.pas b/uCEFSnapshotParameters.pas
index cb92325..916ada7 100644
--- a/uCEFSnapshotParameters.pas
+++ b/uCEFSnapshotParameters.pas
@@ -7,11 +7,11 @@ interface
uCEFTypes, uCEFMiscFunctions;
const
- cChromiumSubFolder = 'Chromium88.2';
+ cChromiumSubFolder = 'Chromium89.15';
cDLLSubfolder = 'Libraries';
type
- TSnapshotOutputFormat = ( sofUnknown, sofBMP, sofJPG, sofPNG, sofPDF );
+ TSnapshotOutputFormat = ( sofUnknown, sofBMP, sofJPG, sofPNG, sofPDF, sofPrinter );
TSnapshotParameters = record
ErrorText : String; // if not empty, parsing ended up with errors
@@ -30,6 +30,7 @@ TSnapshotParameters = record
Cookies : array of String;
IgnoreCertificateErrors : Boolean;
NoSandbox : Boolean;
+ Print : Boolean;
procedure SaveBitmap(bmp : TBitmap);
function URLSchemeDomain : String;
@@ -48,14 +49,15 @@ implementation
uses LibTurboJPEG, Vcl.Imaging.pngimage, System.StrUtils;
const
- cHelp = 'cefHtmlSnaphot utility v0.3.88 - Html to image or pdf coversion using Chromium Embedded Framework'#10
- + 'Using CEF 88.0.4324.150, CEF4Delphi, TurboJPEG see https://github.com/EricGrange/cefHtmlSnapshot'#10#10
+ cHelp = 'cefHtmlSnaphot utility v0.4.89 - Html to image or pdf coversion using Chromium Embedded Framework'#10
+ + 'Using CEF 89.0.15, CEF4Delphi, TurboJPEG see https://github.com/EricGrange/cefHtmlSnapshot'#10#10
+ 'cefHtmlSnapshot.exe url_or_file [-arg1 value1] [-arg2 value2] ... output_file'#10
+ #10
+ ' -?, -h, --help This inline documentation'#10
+ ' url_or_file URL of the website or file to be snapshotted (required)'#10
+ ' If a .url file is specified, the URL will be read from it'#10
+ ' output_file Output file pathname, extension determines format (default snapshot.bmp)'#10
+ + ' If the printing mode is enabled, this is the name of the printer.'#10
+ #10
+ ' -w, --width Width of the snapshot, between 1 and 2048 (default 1024)'#10
+ ' -h, --height Height of the snapshot, between 1 and 2048 (default 768)'#10
@@ -85,6 +87,8 @@ implementation
+ ' margin-bottom bottom margin in points (default 20)'#10
+ ' landscape portait (default, 0) or landscape (1)'#10
+ ' backgrounds enable backgrounds (1) or not (default, 0)'#10
+ + #10
+ + ' --print If this option 1 then output_file is the name of a printer (by default 0)'#10
;
// ParseCommandLineParameters
@@ -177,11 +181,7 @@ function ParseCommandLineParameters : TSnapshotParameters;
else if ext = '.png' then
Result.OutputFormat := sofPNG
else if ext = '.pdf' then
- Result.OutputFormat := sofPDF
- else begin
- Result.ErrorText := 'Unsupported output file format "' + Result.OutputFilePath + '"';
- Exit;
- end;
+ Result.OutputFormat := sofPDF;
// parse arguments in between
@@ -256,6 +256,12 @@ function ParseCommandLineParameters : TSnapshotParameters;
// property scale_factor : integer read Fscale_factor write Fscale_factor default 0;
// property header_footer_enabled : boolean read Fheader_footer_enabled write Fheader_footer_enabled default False;
// property selection_only : boolean read Fselection_only write Fselection_only default False;
+ end else if lastP = '-print' then begin
+ if p = '1' then begin
+ Result.Print := True;
+ Result.OutputFormat := sofPrinter;
+ end else if p <> '0' then
+ Result.ErrorText := 'Unsupported option "' + p + '" for print';
end else begin
Result.ErrorText := 'Unsupported parameter "' + p + '"';
end;
@@ -266,7 +272,9 @@ function ParseCommandLineParameters : TSnapshotParameters;
if lastP <> '' then begin
Result.ErrorText := 'Argument missing for parameter "' + lastP + '"';
- end else if Result.URL = '' then begin
+ end else if Result.OutputFormat = sofUnknown then begin
+ Result.ErrorText := 'Unsupported output file format "' + Result.OutputFilePath + '"';
+ end else if (Result.URL = '') and not Result.Print then begin
Result.ErrorText := 'Missing URL parameter, it is required';
end;
end;
diff --git a/uEncapsulatedBrowser.pas b/uEncapsulatedBrowser.pas
index dda67c7..a16ed9a 100644
--- a/uEncapsulatedBrowser.pas
+++ b/uEncapsulatedBrowser.pas
@@ -68,7 +68,7 @@ TEncapsulatedBrowser = class
property ErrorText : ustring read FErrorText;
end;
-procedure CreateGlobalCEFApp(const parameters : TSnapshotParameters; const chromiumPath : String = '');
+function CreateGlobalCEFApp(const parameters : TSnapshotParameters; const chromiumPath : String = '') : Boolean;
function WaitForMainAppEvent : boolean;
procedure WriteResult;
@@ -111,7 +111,7 @@ procedure WriteResult;
WriteLn('Snapshot saved successfully as ' + EncapsulatedBrowser.Parameters.OutputFilePath);
end;
-procedure CreateGlobalCEFApp(const parameters : TSnapshotParameters; const chromiumPath : String = '');
+function CreateGlobalCEFApp(const parameters : TSnapshotParameters; const chromiumPath : String = '') : Boolean;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.WindowlessRenderingEnabled := True;
@@ -135,6 +135,7 @@ procedure CreateGlobalCEFApp(const parameters : TSnapshotParameters; const chrom
GlobalCEFApp.EnableUsermediaScreenCapturing := False;
GlobalCEFApp.EnablePrintPreview := False;
GlobalCEFApp.DisableJavascriptAccessClipboard := True;
+ GlobalCEFApp.DisableJavascriptDomPaste := True;
GlobalCEFApp.DisableSpellChecking := True;
GlobalCEFApp.MuteAudio := True;
GlobalCEFApp.AllowFileAccessFromFiles := True;
@@ -148,7 +149,7 @@ procedure CreateGlobalCEFApp(const parameters : TSnapshotParameters; const chrom
GlobalCEFApp.PersistSessionCookies := False;
GlobalCEFApp.PersistUserPreferences := False;
- GlobalCEFApp.StartMainProcess;
+ Result := GlobalCEFApp.StartMainProcess;
end;
constructor TEncapsulatedBrowser.Create(const aParameters : TSnapshotParameters);