Page Break Issues
Hi all,
I've added a page-break-after: always attribute to a div element in the HTML string/snippet, to separate content and paging. The PDF converted should produce multiple pages, however, it does not. Is anyone able to see whether page break are handled, especially page-break-after CSS?
Thanks in advanced!
Regards,
Rahmadhy
Hi Rahmadhy
At the moment page-break-after property is not supported. As well as page-break-before
Hi gyfke,
Is there a way to include the handling of page-break-after and page-break-before properties?
Any news on this feature? Adding forced page breaks after tables is necessary for my project.
I haven't received a reply yet from Andrey. I've contacted the main contributor (Arthur) and he has responded by not being able to support the forced page break functionality.
On Mon, Oct 3, 2016 at 11:33 PM, Azimov Aleksandr [email protected] wrote:
Any news on this feature? Adding forced page breaks after tables is necessary for my project.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ArthurHub/HTML-Renderer/issues/49#issuecomment-251094394, or mute the thread https://github.com/notifications/unsubscribe-auth/AS46yGZC99JN5fX4GzEqwT-cgvF0bLoyks5qwPYfgaJpZM4Jl-HR .
I made my own implementation by cutting big htmls into small ones, creating several pdf files from them and adding pages from these files into 1 pdf. Not an elegant approach, but the only one I could use for now.
I haven't received a reply yet from Andrey. I've contacted the main contributor (Arthur) and he has responded by not being able to support the forced page break functionality.
Sounds like a good solution. Is there any way you could guide me to getting that done? I need to implement that for my project also.
On Tue, Oct 4, 2016 at 7:56 PM, Azimov Aleksandr [email protected] wrote:
I made my own implementation by cutting big htmls into small ones, creating several pdf files from them and adding pages from these files into 1 pdf. Not an elegant approach, but the only one I could use for now.
I haven't received a reply yet from Andrey. I've contacted the main contributor (Arthur) and he has responded by not being able to support the forced page break functionality.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ArthurHub/HTML-Renderer/issues/49#issuecomment-251332349, or mute the thread https://github.com/notifications/unsubscribe-auth/AS46yPiS79RIpP2ya2JM74QCCdho1LPRks5qwhTOgaJpZM4Jl-HR .
PdfDocument doc = new PdfDocument();
foreach (NBElement htmlString in arrayOfStrings)
{
PdfDocument tempDoc = getPdfDocFrom(htmlString.GetString());
addPagesToPdf(ref doc, tempDoc);
}
private PdfDocument getPdfDocFrom (string htmlString)
{
PdfGenerateConfig config = new PdfGenerateConfig();
config.PageOrientation = PdfSharp.PageOrientation.Landscape;
config.PageSize = PdfSharp.PageSize.A4;
PdfDocument doc = PdfGenerator.GeneratePdf(htmlString, config);
return doc;
}
private static void addPagesToPdf(ref PdfDocument mainDoc, PdfDocument sourceDoc)
{
MemoryStream tempMemoryStream = new MemoryStream();
sourceDoc.Save(tempMemoryStream, false);
PdfDocument openedDoc = PdfReader.Open(tempMemoryStream, PdfDocumentOpenMode.Import);
foreach (PdfPage page in openedDoc.Pages)
{
mainDoc.AddPage(page);
}
}
How you cut your html - is up to you.
Yes, I set the page size by the configuration options they offer (A4, A5, etc). However, it does not force a page break when I add a div element with the page-break-after: always CSS property. Is there any way to handle this?
Example:
"
Page One
Page Two
"
This should show a PDF document with two pages and Page One/Two on the top of each page.
On Tue, Oct 4, 2016 at 9:25 PM, Azimov Aleksandr [email protected] wrote:
How you cut your html - is up to you.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ArthurHub/HTML-Renderer/issues/49#issuecomment-251351672, or mute the thread https://github.com/notifications/unsubscribe-auth/AS46yLvqd7Q2-H0vMibHOCqijvxhhH8rks5qwimYgaJpZM4Jl-HR .
I told you, make them 2 different html strings:
string a = "<p>Page One</p>
<div style="page-break-after: always;"><span style="display: none;">some
text</span></div>"
string b = "<p>Page Two</p>"
Insert them into some array of strings and then just use my code. You will get what you need. (Oh and you can get rid of the "page-break-after: always;" as it doesn't work here).
Oh okay, thank you so much Azimov. I'll let you know if I need further assistance. Appreciate your help! :)
On Tue, Oct 4, 2016 at 9:36 PM, Azimov Aleksandr [email protected] wrote:
I told you, make them 2 different html strings: string a = "
Page One
some text "
string b = "
Page Two "
Insert them into some array of strings and then just use my code. You will get what you need. (Oh and you can get rid of the "page-break-after: always;" as it doesn't work here).
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ArthurHub/HTML-Renderer/issues/49#issuecomment-251353715, or mute the thread https://github.com/notifications/unsubscribe-auth/AS46yFmXmacxvObpIuMjh_N42cTAzR12ks5qwiwrgaJpZM4Jl-HR .