|
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.
|
|
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.aspxHope this helps. Thanks!
|
|
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.
|
|
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!
|
|
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 :)
|
|
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!
|
|
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.
|
|