Welcome Guest Search | Active Topics | Sign In | Register

Webbrowser print bugs & enhancements Options
PS
Posted: Wednesday, May 8, 2019 9:28:58 AM
Rank: Advanced Member
Groups: Member

Joined: 10/24/2018
Posts: 97
Hello,

We are currently implementing the print and print preview functionality, the former is supported by EO, the latter is not, so we convert the HTML to PDF and then we show/print it via another component.

We noticed the following:
1. We want to ensure that images are not cut in half, so we found a CSS option for it and tried to apply it HtmlToPdfOptions.UserStyleSheet, except this style sheet does not seem to be used, it does not matter what CSS we put inside. What might be relevant is that we are displaying HTML and not a website.
2. We noticed that the regular WebView.Print option does not show background graphics, apparently Chrome has a "Background graphics" option in their print functionality that needs to be explicitly enabled, how do we enable this in our WebView.Print call?

We're looking forward to your answer.
eo_support
Posted: Wednesday, May 8, 2019 3:41:49 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

We are not aware of any issue with HtmlToPdfOptions.UserStyleSheet. Please try this feature in a simple test app and see if it works for you. If that still does not work for you, you can send us the test app and we will be happy to investigate further.

We are not aware of "background graphics" option either. What Chrome does is it switches to print media for print. Print media has a different set of default CSS rules (the page itself can have a different set of CSS rules for print media as well). By default our HTML to PDF converter does NOT use print media. You can turn this option on by setting this property to true:

https://www.essentialobjects.com/doc/eo.pdf.htmltopdfoptions.useprintmedia.aspx

Hope this helps.

Thanks!
PS
Posted: Monday, May 13, 2019 7:32:39 AM
Rank: Advanced Member
Groups: Member

Joined: 10/24/2018
Posts: 97
1) We made a small test app as follows, you only need to add references to the relevant EO projects and to System.Drawing.

Quote:
using System.IO;
using EO.Pdf;

namespace EOTestPdf
{
class Program
{
static void Main(string[] args)
{
var session = HtmlToPdfSession.Create();
session.LoadHtml(@"<html><head><title>Test</title></head><body>Test</body></html>");
session.Options.PageSize = PdfPageSizes.FromName("A4");
session.Options.UserStyleSheet = @"body { font-size: 100px; }";

using (var memoryStream = new MemoryStream())
{
session.RenderAsPDF(memoryStream);

memoryStream.Seek(0, SeekOrigin.Begin);
using (var fileStream = new FileStream("test.pdf", FileMode.OpenOrCreate))
{
memoryStream.CopyTo(fileStream);
fileStream.Flush();
}
}
}
}
}


Please observe that something as simple as increasing the font size does nothing at all.

2) We mean the following option: (Please see your email for the actual image, as work does not allow me to upload it.)
You can find it on Chrome > Print > Advanced options/More settings > Background graphics.
eo_support
Posted: Wednesday, May 15, 2019 2:18:19 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

For issue #1, please pass the options in through HtmlToPdfSession.Create. For example:

Code: C#
HtmlToPdfOptions options = new HtmlToPdfOptions();
options.UserStyleSheet = @"body { font-size: 100px; }";
var session = HtmlToPdfSession.Create();

....load HTML and render as PDF.....


We do not have any options to support issue #2. This option does exists in the browser engine but is almost hardcoded between the print preview UI and the code that renders the page contents. It is technical possible for us to break into this connection somewhere in the middle and allows you to set this option programmatically but the change needed is not trivial. We will look into it and see what we can do.

Thanks!
PS
Posted: Thursday, May 16, 2019 11:05:39 AM
Rank: Advanced Member
Groups: Member

Joined: 10/24/2018
Posts: 97
Thank you for your response!

For issue #1: Is there a reason that it does not work when changing the passed Options? We would rather be able to set the options at all times if possible. Though this workaround should work, though we have not tested it yet.
For issue #2: We'll wait to see if anything will change :)
eo_support
Posted: Friday, May 17, 2019 10:35:08 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

There is no particular reason why it would not work afterwards beside implementation details. There are multiple copies of options maintained at various places due to the need to change/override the options. For example, the converter would apply default values at certain points, and such default value can NOT propagate back to the original options object (in case the user wish to pass the same options object to another conversion). The same applies in case you modify HtmlToPdfSession.Options. This results in multiple copies being maintained and the disconnection between these copies. Setting a value on the second copy would not have any impact on the conversion when the value have already been taken off from the "original" copy. For this reason, HtmlToPdfSession.Options is primarily for you to "view" the conversion options and it does not work for changing options.

Thanks!
PS
Posted: Friday, May 24, 2019 10:26:52 AM
Rank: Advanced Member
Groups: Member

Joined: 10/24/2018
Posts: 97
Thank you, this indeed does work! Now the UserStyleSheet property is working again as intended in our application.


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.