Create PDF file - how to create page HTML content in advance?

My task is to create print-ready invoices from a .NET web application.

I am already creating HTML code for printing for an invoice — it consists of an invoice header (which should really appear on each printed page) and invoice items (which can span several printed pages).

Now my task is to create a server on the PDF side, fill in the header on each of its pages, and then fill its pages with account positions. I need to create a PDF from existing HTML data - just passing the HTML input to the PDF generator library.

I started using ABCPDF - I am using the AddImageHtml method . The problem is that ABCPDF seems to expect me to put HTML content already on the page. Thus, it will not work correctly when I feed it with HTML content, which will cover more than 1 page of PDF.

So my question is: do you have any suggestions for creating this work with ABCPDF? Or, more generally, what other tools / approaches would you use for this - creating a PDF document with headers / tabs from HTML input?

thanks

+3
source share
4 answers

, ABCPDF. HTML :

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
}
+4

, - html. - ...

pdf , html. xsl-fo pdf.

+1

-CSS - HTML PDF. , "page-break-after", , , , ( -).

, !

0

PDF Duo.NET - component of converting HTML to PDF for .NET - Unlike ABC pdf PDF Duo.NET has its own html parser. The following is an example of adding a header and footer:

     string string _ html = @"Or you can point here the html file. Put your image <img src='pic.jpg' widtd='140' height='70'>";
     string file _ pdf = @"K:\new.pdf";

     try
     {
         DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf();
         conv.Header = "Invoce Document";
         conv.Footer = "* If payment made by Bank transfer kindy please forward to us the copy of the bank transfer slip";
         conv.OpenHTML(file _ html);
         conv.SavePDF(file _ pdf);
         conv.ShowPDF(file _ pdf, Response)
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
0
source

Source: https://habr.com/ru/post/1711971/


All Articles