2017-08-29 8 views
0

Ich baue Dokument mit Aspose.Word. Ich versuche Seitenzahl am rechten Rand hinzuzufügen. Bild besser erklären:Aspose.Word Seitennummer im rechten Rand

My result pdf preview

Wie es zu tun?

Mein aktueller Code:

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

Antwort

0

In Ihrem Fall müssen Sie Textfeld in der Fußzeile des Dokuments hinzuzufügen, in dem Seitenzahlenfeld einfügen, und ihre Position festgelegt. Verwenden Sie das folgende modifizierte Codebeispiel, um die gewünschte Ausgabe zu erhalten.

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

Ich arbeite mit Aspose als Entwickler Evangelist.

Verwandte Themen