HTML-Renderer
HTML-Renderer copied to clipboard
HTML being cut off in PDF
I am rendering a very simple invoice and it is cutting off HTML in the middle of the page when I set page top and bottom margins. When the margin is removed it seems to sort itself out. Can send html it's trying to parse if that would help
On latest nuget package of tmlRenderer.PdfSharp
Attached test method, most noticably the table headers wont appear. Any help is hugely appreciated,
Thanks.
Fixed. See example. Notice that it requires prerelease version of PdfSharp and this changes are not included in nuget-package yet
thank you! I will upgrade to pre-release
Are there still plans to update the nuget package to include these changes?
Thanks, Pam
Where can I get that prelelese version that you talking about?
Thanks
Hey guys. I just uploaded a pre-release version of the packages to nuget (*-beta1). That is the most up to date code and includes the fix gyfke made for page breaks.
Cheers!
PawelMaj thank you so much!! I'm not seeing it when I search within NuGet though, even though I have "Include Prerelease" selected.
https://www.nuget.org/packages/HtmlRenderer.Core/1.5.1-beta1
Thanks very much, I wasn't familiar with the package manager console.
One other question - is this compatible with the HtmlRenderer.PdfSharp library? When I try to generate a PDF in my application after updating the core to the beta release, it's blank except for the footer and one horizontal rule. Interestingly, it has that correct spacing/number of pages for the text that should be there.
Thanks, Pam
@pdreid I am currently using it in a large project specifically with PdfSharp. Make sure you have the right version of PdfSharp installed. You need the beta version.
Hello, I'm getting the same with the prerelease version, simple <p>
's with LOL text, margins top-bottom 60, left-right 10, pageSize Letter and Orientation Landscape:
Result:
Any ideas?
@darkguy2008 Hey! I have recently decided to join this project and started looking into the page-breaking code in specific. That being said, I think the words will break a page correctly if the immediate parent element has that attribute on it and if the parent element is smaller than the size of the page.
Should work
Should fail
If you only really care about making sure words are not split in half you can change the following code:
CssRect.cs ln307
From:
if (!box.IsFixed && box.PageBreakInside == CssConstants.Avoid) { word.BreakPage(); }
To:
if (!box.IsFixed) { word.BreakPage(); }
If I am correct (I may be wrong, I have only started to get into this code) this change will make sure that no words will ever be split on a page break. I am a bit busy right now, but if I find time I will try to push these changes in and get a new version into nuget.
Hello @PawelMaj ! Thanks for your answer!. While I would love to help you in this endeavor, the library's code is huge for my timeframe and I'm also surprised on how were you able to find that out. I made the change and I can say it's working nicely, at least for one-line paragraphs. Now I'm working with a table using rowspans and the split is happening again :( see!
I tried to look at the code in that function but it's hard to understand for me, what do you think it could be? thanks again for your time! it would be great if you can make a nuget package out of that fix too :)
+1
@darkguy2008 The table code uses different logic unfortunately....
Edit:
The fix I am suggesting will work for any single word/image.
+1
This is still having problems. I'm using this for a production application and this is the last remaining bug. Please fix this.
@KthProg I solved it by using WxHTMLToPDF (another project) by just making an HTML and rendering it through Webkit... it might be unrelated but it solved my problem, this renderer has a lot of issues regarding line breaks and so on, and the code is too convoluted for me to understand :(
@darkguy2008 How did you do "rendering through WebKit"?
@KthProg that project does it, there's a NuGet package called TuesPechkin ( https://www.nuget.org/packages/TuesPechkin/ ) which is a wrapper for that project, you just make an HTML and supply it to the wrapper and it works kinda like PhantomJS, but with PDF output built-in.
@darkguy2008 I'll take a look thank you!
So I can implement the quick fix I mentioned earlier. I will not push it to a Nuget package just yet because I am afraid that the change may have some side affects. This quick fix would be changing the code:
From: if (!box.IsFixed && box.PageBreakInside == CssConstants.Avoid) { word.BreakPage(); }
To: if (!box.IsFixed) { word.BreakPage(); }
From what I have seen, this will make sure that each INDIVIDUAL word/picture will not be cut in half on page breaks. This will introduce a possible smaller issue. If the words in a single line have different line heights, here is a possibility of some words being placed on the next page while others stay on the previous page.
Now I have thought of doing a more complex fix to this. Unfortunately the entire process seems to be using recursion to determine where to place each small element(aka word/image). I would have to redo a large/important part of the code base. I am not comfortable doing this, since I did not write any of the code, nor do I have time to do that. Thus, I will just make a commit with my simple fix for now and hope it does not cause other problems. I will try to do this tonight...
@PawelMaj That fix would do the trick for me. If you add this fix how would I pull it down/build from it? (I know I should know this, but I use TFS at work...)
@PawelMaj I made the change you suggested and did my own build. When I used the updated DLLs my problem was fixed. Thanks 👍
Yes, I can confirm that the above change fixes this problem for my simple test case as well.
@PawelMaj can this fix be merged to master and pushed to nuget?
@PawelMaj As mentioned, could you possibly merge your fix to master and update the nuget package? This is the last of the issues with my PDF generation project, would be good to see it fixed.
Hey guys, just to let all solution more clear following the step-by-step below: 1 - Add to your project https://www.nuget.org/packages/HtmlRenderer.Core/1.5.1-beta1 2 - Add to your project https://www.nuget.org/packages/HtmlRenderer.PdfSharp/1.5.1-beta1 3 - After that, if you wanna to break table, td, h3 .. just put td {page-break-inside: avoid; } will work. 4 - if you wanna to break imgs just put the tag img inside a span and in span add page-break-inside: avoid;
Cheers Guys.
Hi guys, I'm new to HTML-Renderer but its use as been until now simple et straightforward. I'm still having one issue, the page break one... I've updated to beta1 both core and pdfsharp libs, added the page-break-inside css rule too, but I'm still having lines appearing cut between 2 pages. Has anyone any idea why ? It appears inside a
for example or an h3.
I really need this to work and can't use a solution like TuesPechkin since my app is running as an Azure wep app.
Here's how I create the pdf from some simple html. Again, page-breaking appears even in
tags...
The sample code i downloaded is working perfectly but when i move the same thing to my actual code it is breaking the line like below image. Please suggest what is missed. Appreciate your help in advance.