HiQPdf Documentation

PDF Repeat Canvas

HiQPdf Client for .NET Core

A Repeat Canvas is a canvas repeated on each page of the PDF document in the same position. The repeat canvas is represented by the HiQPdfClientPdfRepeatCanvas class.

A repeat canvas can be created using the PdfDocumentCreateRepeatedCanvas(RectangleFloat) method. The parameter of this method is the canvas bounding box, the same in all PDF pages.

Below is an example of creating a repeat canvas taken from the Edit PDF Documents demo application:

Create Repeat Canvas Sample Source Code

#region Layout HTML in a canvas to be repeated on each page of the loaded PDF document

PdfPage pdfPage1 = document.Pages[0];
float pdfPageWidth = pdfPage1.Size.Width;
float pdfPageHeight = pdfPage1.Size.Height;

// the width of the HTML logo in pixels
int htmlLogoWidthPx = 400;
// the width of the HTML logo in points
float htmlLogoWidthPt = PdfDpiTransform.FromPixelsToPoints(htmlLogoWidthPx);
float htmlLogoHeightPt = 100;

// create a canvas to be repeated in the center of each PDF page
// the canvas is a PDF container that can contain PDF objects ( HTML, text, images, etc )
PdfRepeatCanvas repeatedCanvas = document.CreateRepeatedCanvas(new RectangleFloat((pdfPageWidth - htmlLogoWidthPt) / 2, (pdfPageHeight - htmlLogoHeightPt) / 2,
            htmlLogoWidthPt, htmlLogoHeightPt));

// the HTML file giving the content to be placed in the repeated canvas
string htmlFile = "http://www.hiqpdf.com/ClientDemo" + @"/DemoFiles/Html/Logo.Html";

// the HTML object to be laid out in repeated canvas
PdfHtml htmlLogo = new PdfHtml(0, 0, repeatedCanvas.Width, repeatedCanvas.Height, htmlFile);
// the browser width when rendering the HTML
htmlLogo.BrowserWidth = htmlLogoWidthPx;
// the HTML content will fit the destination hight which is the same with repeated canvas height
htmlLogo.FitDestHeight = true;

// layout the HTML object in the repeated canvas

See Also

Other Resources