2016-08-09 9 views
1

大きなHTMLファイルをPDFに変換しようとしています。最初のページとそれに続くページ番号を設定したいだけです。ページHTMLをPDFに変換中にPDFを選択して変換する

私は、次のコード

 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() 

を使用しているが、この部分は機能していない、

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

し、任意のは、総ページを知るために何がありますか?

+0

? –

+0

SelectPDFコミュニティエディション – monikapatel

答えて

1

SelectPDFと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; 
    } 
} 

そして、ここに私の_pagenumber.cshtmlファイルは次のようになります...あなたは、コンバータを使用している

<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> 
関連する問題