Welcome Guest Search | Active Topics | Sign In | Register

Call to HtmlToPdf.ConvertHtml different - file Vs stream Options
Phil
Posted: Tuesday, September 1, 2020 6:50:15 AM
Rank: Advanced Member
Groups: Member

Joined: 11/8/2017
Posts: 66
Hello - I am using the latest versions of EO.PDF and EO.WebBrowser (v20.2.34). I have EO.Base.Runtime.EnableEOWP=true and HtmlToPdf.MaxConcurrentTaskCount=4 (I've included eowp.exe in the bin folder at compile-time). I have included the 4 files EO.Pdf, EO.WebBrowser, EO.Base, EO.WebEngine as VS Project References (directly from the DLL's)

I have a .NET Core 3.1 Web API that is generating a PDF as expected when I issue the following command

Code: C#
HtmlToPdf.ConvertHtml(myHtml, @"c:\temp\myPdf.pdf");

- this generates a file of above 100K

...however when I issue the following I get a PDF with just one page which is blank

Code: C#
byte[] bytes = null;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
    HtmlToPdf.ConvertHtml(myHtml, stream);
    stream.Position = 0;
    bytes = stream.ToArray();
    stream.Position = 0;
}

- this generates a byte array of around 40K length

...I have also tried the following with the same result (PDF generated with just one page which is blank)

Code: C#
byte[] bytes = null;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
var pdfDocument = new EO.Pdf.PdfDocument();
HtmlToPdf.ConvertHtml(myHtml, pdfDocument);
pdfDocument.Save(@"c:\temp\myPdfUsingPdfDocument.pdf"); //check if pdfDocument contains anything - it doesn't - file is about 40K in size
pdfDocument.Save(stream);
stream.Position = 0;
bytes = stream.ToArray();
stream.Position = 0;

- this also generates a byte array of around 40K length

Notes
====
(i) I'm trying to generate an Angular template - all of the above strategies work when I use the code in .NET Framework however as mentioned only the first works in .NET Core
(ii) I generate the Angular template before passing through to the above PDF generate steps and all resolves in a browser without any console errors
(iii) if I use a very simple HTML snippet (eg. "<span>Hello</span>") the generate works in all scenarios - I have tried to dumb down the Angular template to bare bones but it ultimately it has all of the Angular wrapping (main, polyfills, syles, etc)

Do you have any ideas why the first code snippet works but the other two don't
eo_support
Posted: Tuesday, September 1, 2020 9:13:32 AM
Rank: Administration
Groups: Administration

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

The problem can not be file or stream. It is somewhere else. When you call ConvertHtml(html, fileName), internally it creates a FileStream object first, then call the same method as ConvertHtml(html, stream).

You can try to call the following code to convert:

Code: C#
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertHtml(html, doc);


Then try call

Code: C#
doc.Save(fileName);


and

Code: C#
doc.Save(stream);


And you should not see any difference with the result size.

Thanks!
Phil
Posted: Tuesday, September 1, 2020 9:50:35 AM
Rank: Advanced Member
Groups: Member

Joined: 11/8/2017
Posts: 66
Thanks for the reply - what you have mention is what I tried in the third snippet of the original post. You're right, both doc.Save(filename) and doc.Save(stream) result in the same (40KB file and 40K byte array resp.) however they both resolve to a blank one page PDF - do you know why the results of these two snippets differ from the result of the first snippet in the original post which saves the full HTML file to PDF
eo_support
Posted: Tuesday, September 1, 2020 10:27:53 AM
Rank: Administration
Groups: Administration

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

We have no way to tell you why the result is blank without being able to reproduce it here first. However we can tell you for certain that it does not have anything to do with stream or file. If you wish us to investigate further, you can try to isolate the problem into a test project and send the test project to us:

https://www.essentialobjects.com/forum/test_project.aspx

Once we have the test project we will test it here and see what we can find.

Thanks!


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.