2017-08-29 163 views
0

我使用Aspose.Word構建文檔。我嘗試在右邊添加頁碼。圖片更好地解釋它:Aspose.Word頁碼右邊距

My result pdf preview

怎麼辦呢?

我當前的代碼:

var document = new Document(); 
     _builder = new DocumentBuilder(document) 
     { 
      PageSetup = 
      { 
       Orientation = Orientation.Portrait, 
       PaperSize = PaperSize.A4, 
       RightMargin = ConvertUtil.MillimeterToPoint(20), 
       BottomMargin = ConvertUtil.MillimeterToPoint(35), 
       LeftMargin = ConvertUtil.MillimeterToPoint(35), 
       TopMargin = ConvertUtil.MillimeterToPoint(35) 
      } 
     }; 

     _builder.StartTable(); 
     _builder.InsertCell(); 
     _builder.Write("Test test test"); 
     _builder.EndTable(); 

     _builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary); 
     _builder.Write("Pages: "); 
     _builder.InsertField("PAGE", ""); 
     _builder.Write("/"); 
     _builder.InsertField("NUMPAGES"); 
     document.Save(stream, SaveFormat.Pdf); 

回答

0

在你的情況,你需要添加文本框的文檔頁腳,在其中插入頁碼領域,並設置其位置。請使用以下修改的代碼示例來獲取所需的輸出。

var document = new Document(); 
DocumentBuilder _builder = new DocumentBuilder(document) 
{ 
    PageSetup = 
    { 
     Orientation = Orientation.Portrait, 
     PaperSize = Aspose.Words.PaperSize.A4, 
     RightMargin = ConvertUtil.MillimeterToPoint(20), 
     BottomMargin = ConvertUtil.MillimeterToPoint(35), 
     LeftMargin = ConvertUtil.MillimeterToPoint(35), 
     TopMargin = ConvertUtil.MillimeterToPoint(35) 
    } 
     }; 

_builder.StartTable(); 
_builder.InsertCell(); 
_builder.Write("Test test test"); 
_builder.EndTable(); 

_builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary); 

Shape shape = new Shape(document, ShapeType.TextBox); 
shape.Stroked = false; 
shape.Width = _builder.CurrentSection.PageSetup.PageWidth; 
shape.Height = 50; 
shape.Left = 0; 
shape.Left = - _builder.CurrentSection.PageSetup.LeftMargin; 
shape.Top = 0; 

Paragraph paragraph = new Paragraph(document); 
shape.AppendChild(paragraph); 

_builder.InsertNode(shape); 
_builder.MoveTo(paragraph); 
_builder.ParagraphFormat.Alignment = ParagraphAlignment.Right; 
_builder.Write("Pages: "); 
_builder.InsertField("PAGE", ""); 
_builder.Write("/"); 
_builder.InsertField("NUMPAGES"); 
document.Save(MyDir + "output.pdf", SaveFormat.Pdf); 

我使用Aspose作爲Developer evangelist。