Skip to content

Commit

Permalink
Update to CEF 101.0
Browse files Browse the repository at this point in the history
Support .htm output as shortcut for .txt & --text html
Support frame parameter for text & html outputs
  • Loading branch information
Eric Grange committed May 11, 2022
1 parent d012a48 commit 6bfe1aa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
8 changes: 4 additions & 4 deletions cefHtmlSnapshot.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@
<DCC_Optimize>true</DCC_Optimize>
<DCC_GenerateStackFrames>false</DCC_GenerateStackFrames>
<DCC_MapFile>3</DCC_MapFile>
<Debugger_RunParams>https://www.google.com test\test1.pdf</Debugger_RunParams>
<Debugger_RunParams>D:\GC\cefHtmlSnapshot\test\report_4.mhtml test\snapshot4.txt</Debugger_RunParams>
<DCC_DebugInfoInTds>true</DCC_DebugInfoInTds>
<Icon_MainIcon>cefHtmlSnapshot_Icon.ico</Icon_MainIcon>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_MajorVer>0</VerInfo_MajorVer>
<VerInfo_MinorVer>7</VerInfo_MinorVer>
<VerInfo_Keys>CompanyName=delphitools.info;FileDescription=$(MSBuildProjectName);FileVersion=0.7.100.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Release>100</VerInfo_Release>
<VerInfo_MinorVer>8</VerInfo_MinorVer>
<VerInfo_Keys>CompanyName=delphitools.info;FileDescription=$(MSBuildProjectName);FileVersion=0.8.101.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Release>101</VerInfo_Release>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
Expand Down
Binary file modified cefHtmlSnapshot.res
Binary file not shown.
6 changes: 3 additions & 3 deletions uCEFBrowserThread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function TCEFBrowserThread.SaveSnapshotToFile(const aPath : ustring) : boolean;
FBrowserInfoCS.Acquire;

if FParameters.OutputFormat = sofTXT then begin
FParameters.SaveText(FSnapshotText);
Result := FParameters.SaveText(FSnapshotText);
end else begin
if assigned(FSnapshot) and not(FSnapshot.Empty) then begin
FParameters.SaveBitmap(FSnapshot);
Expand Down Expand Up @@ -849,7 +849,7 @@ function TCEFBrowserThread.TakeSnapshot : boolean;
end;
sofTXT : begin
case FParameters.TextSource of
stsHTML : FBrowser.RetrieveHTML();
stsHTML : FBrowser.RetrieveHTML(FParameters.TextFrame);
stsConsole : begin
FBrowserInfoCS.Acquire;
try
Expand All @@ -860,7 +860,7 @@ function TCEFBrowserThread.TakeSnapshot : boolean;
Browser_OnTextResultAvailable(Self, FSnapshotText);
end;
else
FBrowser.RetrieveText();
FBrowser.RetrieveText(FParameters.TextFrame);
end;
end;
else
Expand Down
32 changes: 26 additions & 6 deletions uCEFSnapshotParameters.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface
uCEFTypes, uCEFMiscFunctions;

const
cChromiumSubFolder = 'Chromium100.0';
cChromiumSubFolder = 'Chromium101.0';
cDLLSubfolder = 'Libraries';

type
Expand All @@ -18,7 +18,7 @@ interface
sofPNG, // PNG
sofPDF, // PDF
sofPrinter, // sent to printer
sofTXT // Text, affected by
sofTXT // Text, affected by TSnapshotTextSource
);

TSnapshotTextSource = (
Expand All @@ -41,14 +41,15 @@ TSnapshotParameters = record
PDFOptions : TCefPdfPrintSettings;
PDFTitle, PDFURL : String;
TextSource : TSnapshotTextSource;
TextFrame : String;
JavaScript : String;
Cookies : array of String;
IgnoreCertificateErrors : Boolean;
NoSandbox : Boolean;
Print : Boolean;

procedure SaveBitmap(bmp : TBitmap);
procedure SaveText(const txt : String);
function SaveText(const txt : String) : Boolean;

function URLSchemeDomain : String;
end;
Expand All @@ -65,6 +66,13 @@ implementation

uses LibTurboJPEG, Vcl.Imaging.pngimage, System.StrUtils, System.IOUtils;

// SaveText
//
function SaveText(const txt : String) : Boolean;
begin

end;

const
cHelp = 'cefHtmlSnaphot utility v0.7.100 - Html to image or pdf coversion using Chromium Embedded Framework'#10
+ 'Using CEF 100.0.23, CEF4Delphi, TurboJPEG see https://github.com/EricGrange/cefHtmlSnapshot'#10#10
Expand All @@ -74,7 +82,7 @@ implementation
+ ' 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.jpg)'#10
+ ' Supported formats are pdf, jpg, png, bmp & txt.'#10
+ ' Supported formats are pdf, jpg, png, bmp, htm & txt.'#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
Expand Down Expand Up @@ -112,6 +120,7 @@ implementation
+ ' text (default)'#10
+ ' html'#10
+ ' console'#10
+ ' --frame Specifies the name of the frame for text our html output (by default main frame)'#10
;

// ParseCommandLineParameters
Expand Down Expand Up @@ -206,7 +215,11 @@ function ParseCommandLineParameters : TSnapshotParameters;
else if ext = '.pdf' then
Result.OutputFormat := sofPDF
else if ext = '.txt' then
Result.OutputFormat := sofTXT
else if ext = '.htm' then begin
Result.OutputFormat := sofTXT;
Result.TextSource := stsHTML;
end;

// parse arguments in between

Expand Down Expand Up @@ -295,6 +308,8 @@ function ParseCommandLineParameters : TSnapshotParameters;
else if p = 'console' then
Result.TextSource := stsConsole
else Result.ErrorText := 'Unsupported option "' + p + '" for text';
end else if lastP = '-frame' then begin
Result.TextFrame := p;
end else begin
Result.ErrorText := 'Unsupported parameter "' + p + '"';
end;
Expand Down Expand Up @@ -383,9 +398,14 @@ procedure TSnapshotParameters.SaveBitmap(bmp : TBitmap);

// SaveText
//
procedure TSnapshotParameters.SaveText(const txt : String);
function TSnapshotParameters.SaveText(const txt : String) : Boolean;
begin
TFile.WriteAllText(OutputFilePath, txt);
try
TFile.WriteAllText(OutputFilePath, txt);
Result := True;
except
Result := False;
end;
end;

// URLSchemeDomain
Expand Down

0 comments on commit 6bfe1aa

Please sign in to comment.