2016-08-09 2 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

... 내 _pagenumber.cshtml 파일처럼 보이는 무엇인가? –

+0

SelectPDF 커뮤니티 에디션 – monikapatel

답변

1

SelectPDF 및 ASP.NET MVC 면도기를 사용하여 페이지 번호 매기기를 처리하는 방법은 다음과 같습니다.

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

그리고 여기 당신이 사용하고있는 계산기

<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> 
관련 문제