How To Ceate and Use Graphics Templates in PDF Mosaic .NET Library

This sample shows how to create and use graphics templates in PDFMosaic library.

PDF Graphics Template

C# :

using PDFMosaic;
using System;

namespace Template
{
  class Template
  {
    static void Main()
    {
      PDFDocument document = new PDFDocument();
      PDFGraphicsTemplate template = new PDFGraphicsTemplate(500, 800);

      PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 16);
      PDFSolidBrush brush = new PDFSolidBrush(new PDFColorRGB(255, 0, 0));

      template.DrawRectangle(brush, 100, 50, 300, 30);
      brush.Color = new PDFColorRGB(0, 0, 0);
      template.DrawString("Template", font, brush, 200, 55);

      for (int i = 0; i < 2; ++i)
      {
        PDFPage page = new PDFPage(PDFPaperFormat.A4);
        page.Canvas.DrawTemplate(template, 0, 0);
        document.Pages.Add(page);
      }

      document.Save("Template.pdf", true);
    }
  }
}

VB.NET :

Imports PDFMosaic
Imports System

Module Template
  Sub Main()
    Dim document As New PDFDocument()
    Dim template As New PDFGraphicsTemplate(500, 800)

    Dim font As New PDFFont(PDFStandardFont.Helvetica, 16)
    Dim brush As New PDFSolidBrush(New PDFColorRGB(255, 0, 0))

    template.DrawRectangle(brush, 100, 50, 300, 30)
    brush.Color = New PDFColorRGB(0, 0, 0)
    template.DrawString("Template", font, brush, 200, 55)

    For i As Single = 0 To 1
      Dim page As New PDFPage(PDFPaperFormat.A4)
      page.Canvas.DrawTemplate(template, 0, 0)
      document.Pages.Add(page)
    Next

    document.Save("Template.pdf", True)
  End Sub
End Module