We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use a large image in header?

Platform: WinForms |
Control: PDF |
Published Date: February 4, 2015 |
Last Revised Date: June 23, 2021
Tags: header, pdf

PdfPageTemplateElement is used for creating a template object for the header. Large images are first drawn in this template, then the template object of the header is applied to PdfDocuement header. You can also reuse the image for all pages in the header. By reusing the image you can reduce page size.

C#

//Creates a new Pdf Document
PdfDocument document = new PdfDocument();
//Sets the font
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20f);
//Creates brush
PdfBrush brush = PdfBrushes.Black;
//Create PdfPageTemplateElement by setting width and height
PdfPageTemplateElement template = new PdfPageTemplateElement(510, 100);
PdfBitmap image = new PdfBitmap(filePath);
//Draw image from the page template graphics
template.Graphics.DrawImage(image, 0, 0, template.Width, template.Height);
//Draw string from the page template graphics
template.Graphics.DrawString("Welcome to First Page", font, brush, 40, 50);
//Set image drawn template to document template's top position which makes image to appear in header
document.Template.Top = template;
//Adds page
PdfPage page = document.Pages.Add();
//Save the document and dispose it
document.Save("sample.pdf", Response, HttpReadType.Save);
document.Close();

Sample Link:

https://www.syncfusion.com/downloads/support/directtrac/general/PdfHeader365101069.zip

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile