Articles in this section
Category / Section

How to use a large image in header?

2 mins read

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

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion:

I hope you enjoyed learning about how to use a large image in header.

 

You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied