Skip to content

Commit

Permalink
Add option and extra logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees committed Oct 21, 2021
1 parent b3f72cb commit dfdfba4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ChromeHtmlToPdfConsole/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public class Options
/// of images when the option <see cref="ImageResize"/> and/or <see cref="ImageRotate"/>
/// is being used
/// </summary>
[Option("imageloadtimeout", Required = false, Default = 30000,
[Option("image-load-timeout", Required = false, Default = 30000,
HelpText = "The timeout in milliseconds before this application aborts the downloading " +
"of images when the option --ImageResize and/or --ImageRotate is being used")]
public int? ImageLoadTimeout { get; set; }
Expand Down
1 change: 1 addition & 0 deletions ChromeHtmlToPdfConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ private static void SetConverterSettings(Converter converter, Options options)
converter.SetDiskCache(options.DiskCacheDirectory, options.DiskCacheSize);

converter.DiskCacheDisabled = options.DiskCacheDisabled;
converter.ImageLoadTimeout = options.ImageLoadTimeout;

}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion ChromeHtmlToPdfConsole/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"ChromeHtmlToPdf": {
"commandName": "Project",
"commandLineArgs": "--input \"d:\\test.htm\" --output d:\\test.pdf --log-network-traffic --media-load-timeout 5000 --image-resize true"
"commandLineArgs": "--input \"d:\\test.htm\" --output d:\\test.pdf --log-network-traffic --media-load-timeout 5000 --image-resize true --image-load-timeout 5000"
}
}
}
7 changes: 6 additions & 1 deletion ChromeHtmlToPdfLib/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,19 @@ internal void NavigateTo(
// waiting for stylesheets, images, and sub frames to finish loading (the load event can be used to
// detect a fully-loaded page).
case "Page.lifecycleEvent" when page.Params?.Name == "DOMContentLoaded":

WriteToLog("The 'Page.lifecycleEvent' with param name 'DomContentLoaded' has been fired, the dom content is now loaded and parsed, waiting for stylesheets, images and sub frames to finish loading");

if (mediaLoadTimeout.HasValue && !mediaTimeoutTaskSet)
{
try
{
WriteToLog($"Media load timeout has a value of {mediaLoadTimeout.Value} milliseconds, setting media load timeout task");

Task.Run(async delegate
{
await Task.Delay(mediaLoadTimeout.Value, mediaLoadTimeoutCancellationTokenSource.Token);
WriteToLog($"Media load timed out after {mediaLoadTimeout.Value} milliseconds");
WriteToLog($"Media load timeout task timed out after {mediaLoadTimeout.Value} milliseconds");
waitEvent?.Set();
}, mediaLoadTimeoutCancellationTokenSource.Token);

Expand Down
3 changes: 1 addition & 2 deletions ChromeHtmlToPdfLib/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,7 @@ private void Convert(

if (pageSettings.PaperFormat == PaperFormat.FitPageToContent)
{
WriteToLog(
"The paper format 'FitPageToContent' is set, modifying html so that the PDF fits the HTML content");
WriteToLog("The paper format 'FitPageToContent' is set, modifying html so that the PDF fits the HTML content");
if (documentHelper.FitPageToContent(inputUri, out var outputUri))
{
inputUri = outputUri;
Expand Down

0 comments on commit dfdfba4

Please sign in to comment.