PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Page break problem using PDFSharp with plain HTML
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3799
Page 1 of 1

Author:  cfrieg [ Fri Jun 08, 2018 5:18 pm ]
Post subject:  Page break problem using PDFSharp with plain HTML

Hello! I've searched all the terms I could think of to find an existing question (and googled for hours) but didn't find anyone using plain HTML and not MigraDoc.

I'm trying to get PDFSharp PdfGenerator to automatically split HTML out into multiple pages as the content overflows. I have gotten this to work by setting the margins to 60. My code is here:

Code:
byte[] res = null;
        using (MemoryStream ms = new MemoryStream())
        {
            var pdf = PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4, 60);
            pdf.Save(ms);
            res = ms.ToArray();
            File.WriteAllBytes(@"C:\temp\test.pdf", res);
        }
        return res;

Setting the margins is the only way to get the content to overflow to the next page, but it looks ugly like so:
Image

When I don't specify a margin and allow the default, it does not continue to the next page but looks like this:
Image

The HTML I'm using is this:
Code:
<!DOCTYPE html><html><head><style>body {  page-break-inside: auto; }</style></head> <body><h1>1.0.0.0.0.0.0.0 General Information</h1><p>&nbsp;</p><h2>1.1.0.0.0.0.0.0 Purpose</h2><p><p>The purpose of this functional and technical requirements document is to provide documentation to prospective HMIS solution providers on the requirements of &lt;<span style="background-color: rgb(247, 218, 100);">this Continuum of Care (or Implementing Jurisdiction)</span>&gt; to implement and operate a Homeless Management Information System.</p></p><h2>1.2.0.0.0.0.0.0 Scope</h2><p><p><span>This Functional and Technical Requirements Document will outline the functional, performance, security and other system requirements identified by the <span>&lt;CoC or Collaborative Name&gt;</span> as the proposed information system solution for a Homeless Management Information System.</span></p></p><h2>1.3.0.0.0.0.0.0 Project References</h2><p><p><span>Key documents needed as supporting references to this document are listed below and must be taken into consideration by prospective solution providers while responding to the details outlined in this document:</span></p><ul><li><span>Housing and Urban Development (HUD) Homeless Management Information System (HMIS) Data and Technical Standards, July 2004</span></li><li>Forced Transient Relocation <em><u><strong>Specification 8.2.3.443</strong></u></em></li></ul></p><h2>1.4.0.0.0.0.0.0 Acronyms and Abbrevs</h2><p><p><span>&lt;Provide a list of the acronyms and abbreviations unique to your HMIS implementation (a CoC name, Collaborative Name, acronyms commonly used by your community) that are used in this document and the meaning of each.&gt;</span></p></p><h3>1.4.1.0.0.0.0.0 More TLAs</h3><p><table><tbody><tr><td>data</td><td>testing</td><td>23</td><td>455</td></tr><tr><td><br></td><td><br></td><td><br></td><td><br></td></tr></tbody></table>Here are some more TLAs<br><br></p><h2>1.5.0.0.0.0.0.0 Points of Contact</h2><p>&nbsp;</p><h3>1.5.1.0.0.0.0.0 Information and Coordination</h3><p><p><em><span>Provide a list of the point(s) of organizational contact (POCs) that may be needed by the prospective solution provider for informational and coordination purposes.</span></em><span>&nbsp;&nbsp;</span><em><span>Include type of contact, contact name, department, telephone number, and e-mail address (if applicable), and project oversight function. &nbsp;POCs may include HMIS Lead Agency Staff, CoC Lead Agency Staff, or CoC subcommittee member (if any portion of the implementation process is going to be overseen by the subcommittee member). &nbsp;Oversight responsibilities include software implementation and training, financial administrator, problem resolutions, etc.</span></em><em><span>&nbsp;&nbsp;</span></em></p><p><br></p><p><span>Below is a list of Point of Contacts relevant to this project:</span></p><p><br></p><table border="1" cellpadding="0" cellspacing="0"><tbody><tr><td valign="top" width="15.336463223787167%"><p><span>Contact Name</span></p></td><td valign="top" width="13.458528951486699%"><p><span>Contact Type</span></p></td><td valign="top" width="14.86697965571205%"><p><span>Department&nbsp;</span></p></td><td valign="top" width="19.561815336463223%"><p><span>Telephone Number</span></p></td><td valign="top" width="9.859154929577464%"><p><span>Email</span></p></td><td valign="top" width="26.917057902973397%"><p><span>Oversight Function</span></p></td></tr><tr><td valign="top" width="15.336463223787167%"><p><br></p></td><td valign="top" width="13.458528951486699%"><p><span>HMIS Lead Agency</span></p></td><td valign="top" width="14.86697965571205%"><p><br></p></td><td valign="top" width="19.561815336463223%"><p><br></p></td><td valign="top" width="9.859154929577464%"><p><br></p></td><td valign="top" width="26.917057902973397%"><p><span>Implementation</span></p><p><span>Financial</span></p><p><span>Training</span></p></td></tr><tr><td valign="top" width="15.336463223787167%"><p><br></p></td><td valign="top" width="13.458528951486699%"><p><span>CoC Lead Agency</span></p></td><td valign="top" width="14.86697965571205%"><p><br></p></td><td valign="top" width="19.561815336463223%"><p><br></p></td><td valign="top" width="9.859154929577464%"><p><br></p></td><td valign="top" width="26.917057902973397%"><p><span>General Governance</span></p><p><span>High Level Decisions</span></p><p><span>Problem Resolution</span></p></td></tr></tbody></table></p></body></html>


I'm not sure what the problem is here. Any answers to point me in the right direction would be appreciated!

Author:  TH-Soft [ Fri Jun 08, 2018 5:28 pm ]
Post subject:  Re: Page break problem using PDFSharp with plain HTML

This is the PDFsharp forum. PDFsharp does not handle HTML and does not have a PdfGenerator class, so the question is off topic here.
Maybe try Stack Overflow using the [HTML-Renderer] tag.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/