My task is to create ready-to-print invoices from a .NET web app.
I am already generating the printer-friendly HTML for an invoice - it consists of an invoice header (that will actually need to appear on each printed page) and invoice positions (that may span multiple printed pages).
Now, my task is to generate a PDF server-side, populate a header on each of its pages, then populate its pages with invoice positions. I need to generate the PDF from the existing HTML data - by simply passing HTML input to the PDF generator library.
I've started using ABCPDF - I am using the AddImageHtml method. The problem I have is that ABCPDF seems to expect me to supply HTML content already paged. So, it won't work correctly when I feed it HTML content that would span on more than 1 PDF page.
So, my question is - do you have any suggestions on making this work with ABCPDF? Or, more generally speaking, what other tools/approaches would you use for this - generating PDF doc with headers/footers from HTML input?
Thanks
Found an answer for my ABCPDF-specific question. I am now passing the contents of my generated HTML file as a string to the method below:
private void GeneratePdf(string output)
{
var theDoc = new Doc();
theDoc.Rect.Inset(72, 144);
int theID = theDoc.AddImageHtml(output, true, 800, true);
while (true)
{
theDoc.FrameRect();
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
string fileLocation = Server.MapPath("testAbcPdf.pdf");
theDoc.Save(fileLocation);
// send file to browser as downloadable PDF here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With