Aspose PDF - Page Border and Page Template

Hi,

  1. How to add page border. In below page, it says to use Generator, but it looks like in latest V17.10, generator API doesn’t exist.
    To add background color and border for Pdf page other than header and footer - #2 by codewarior

  2. How to add page template. Want to use Spawn capability of Acrobat. I’m looking for a hidden template using Aspose.pdf.

We are using Aspose Total license.

@dotnet14

Thanks for contacting support.

Please use following code snippet, in order to use DOM approach for adding page border, header and background color of page (other than header and border area).

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
Aspose.Pdf.Page page = doc.Pages.Add();
            
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph((float)page.PageInfo.Width, (float)page.PageInfo.Height);
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
page.Paragraphs.Add(graph);
Aspose.Pdf.Drawing.Line bottomline = new Aspose.Pdf.Drawing.Line(new float[] { 10, 10, (float)page.PageInfo.Width - 10, 10 });
Aspose.Pdf.Drawing.Line topline = new Aspose.Pdf.Drawing.Line(new float[] { 10, (float)page.PageInfo.Height - 10, (float)page.PageInfo.Width - 10, (float)page.PageInfo.Height - 10 });
Aspose.Pdf.Drawing.Line rightline = new Aspose.Pdf.Drawing.Line(new float[] { (float)page.PageInfo.Width - 10, 10, (float)page.PageInfo.Width - 10, (float)page.PageInfo.Height - 10 });
Aspose.Pdf.Drawing.Line leftline = new Aspose.Pdf.Drawing.Line(new float[] { 10, 10, 10, (float)page.PageInfo.Height - 10 });
graph.Shapes.Add(topline);
graph.Shapes.Add(bottomline);
graph.Shapes.Add(rightline);
graph.Shapes.Add(leftline);

graph.ZIndex = 0;

HeaderFooter header = new HeaderFooter();
header.Paragraphs.Add(new TextFragment("This is header text"));
header.Margin = new MarginInfo(15, 15, 15, 15);

// Width = (Right and Left margin of page border => 10 + 10) + (Right and left distance from page border => 10 + 10)
// Height = (Top and Bottom margin of page border => 10 + 10) + (Top and Bottom distance from page border => 10 + 10) + (Height of Header and Footer => 15 + 15)
FloatingBox fb = new FloatingBox((float)(page.CropBox.Width - 40), (float)(page.CropBox.Height - 70));
fb.BackgroundColor = Color.Yellow;
fb.Paragraphs.Add(new TextFragment("This is body"));
fb.ZIndex = 2;
// Height/2 = 35
fb.Top = 35;
// Width/2 = 20
fb.Left = 20;

page.Header = header;
page.Paragraphs.Add(fb);

doc.Save(dataDir + "PageBorder.pdf");

For your reference, a sample output PDF is also attached. PageBorder.pdf (2.1 KB)

We have logged an investigation ticket as PDFNET-43689 in our issue tracking system, for your requirement. Our product team will further look into the details of the issue and we will keep you updated with the status of its resolution. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hi,

is there any update from Development team on PDFNET-43689. on how to create templates and spawn pages?

@dotnet14,

The linked feature request (PDFNET-43689) has just been logged in the issue tracking system. Our product team will investigate as per their development schedules. We will let you know once a significant progress has been made in this regard.