monikapatelIT
monikapatelIT

Reputation: 1007

Page Control while HTML to PDF Conversion using Select PDF

I am trying to convert large HTML file to PDF. but just want to set first page and following page number.

I have used following code

        converter = New HtmlToPdf()
        Dim file As String = "C:\TEMP\Document5.pdf"

        converter.Options.PdfPageSize = PdfPageSize.A4
        converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait
        converter.Options.MarginTop = 20
        converter.Options.MarginBottom = 20
        converter.Options.MarginLeft = 10
        converter.Options.MarginRight = 10
        converter.Options.DisplayFooter = True

        Dim doc As PdfDocument = converter.ConvertHtmlString(htmlString)

        converter.Footer.TotalPagesOffset =2  
        converter.Footer.FirstPageNumber = 2

         doc.Save(file)

            ' close pdf document
         doc.Close()

but this part not working,

        converter.Footer.TotalPagesOffset =2  
        converter.Footer.FirstPageNumber = 2 

and Is there any what to know total pages?

Upvotes: 1

Views: 2660

Answers (1)

Carlos Z
Carlos Z

Reputation: 11

Here's how I handle my page numbering using SelectPDF and ASP.NET MVC Razor.

for (int x = 0; x < PDF.Pages.Count; x++) {
    if (x > 0 && x != PDF.Pages.Count - 1) { // will not number first/last page
        PdfPage page = PDF.Pages[x];
        PdfTemplate customFooter = PDF.AddTemplate(page.PageSize.Width, 33f);
        page.DisplayFooter = true;
        PdfHtmlElement customHtml = new PdfHtmlElement(domain + "/template/_pagenumber?pageNum=" + x.ToString() + "&totalPages=" + PDF.Pages.Count.ToString());
        customFooter.Add(customHtml);
        page.CustomFooter = customFooter;
    }
}

And here's what my _pagenumber.cshtml file looks like...

<div style="margin-right:48px;margin-left:48px;height:46px;position:relative;top:-4px;z-index:999;">
    <div class="row">
        <div class="col-xs-6">
            <small>Company info goes here</small>
        </div>
        <div class="col-xs-6 text-right">
            <small><strong>Page @(Request.QueryString["pageNum"]) of @(Request.QueryString["totalPages"])</strong></small>
        </div>
    </div>
</div>

Upvotes: 1

Related Questions