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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PDF custom handler. Image size equals to Page size

Thread ID:





123718 Apr 13,2016 10:45 PM UTC Apr 14,2016 09:10 AM UTC ASP.NET Web Forms (Classic) 1
Tags: PDF
Carlos Carranza
Asked On April 13, 2016 10:45 PM UTC

I have a "Custom handler" which returns a pdf. In the pdf I import an image. I want the page size is the size of the page.

This is the source code:

public void ProcessRequest(HttpContext context)
            PdfDocument doc = new PdfDocument();
            doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen;

            //read image
            PdfBitmap image = new PdfBitmap("C:\\Users\\ccarranza\\Pictures\\Sin título.png");
            System.Drawing.SizeF size = new System.Drawing.SizeF(image.Width, image.Height);
            System.Drawing.PointF location = new System.Drawing.PointF(0, 0);
            System.Drawing.RectangleF rect = new System.Drawing.RectangleF(location, size);

            PdfSection section = doc.Sections.Add();
            //Page Size
            section.PageSettings.Width = image.Width;
            section.PageSettings.Height = image.Height;
            PdfPage page = section.Pages.Add();            
As I can insert an image that fills the entire page created?
            PdfGraphics g = page.Graphics;
            PdfLayoutFormat format = new PdfLayoutFormat();
            format.Layout = PdfLayoutType.Paginate;
            image.Draw(page, rect, format);

            doc.Save("Sample.pdf", context.Response, HttpReadType.Open);


But when you open the PDF page size is larger than the image inserted.

Attached PDF output on screen

Thank you very much for your help

Attachment: test_198a9383.zip

Chinnu Muniyappan [Syncfusion]
Replied On April 14, 2016 09:10 AM UTC

Hi Carlos,

Thank you for contacting Syncfusion support.

We have created a sample for your requirements, could you please refer the below code snippet and sample for more details.
Convert the image width and height to points using PdfUnitConvertor and set it to the page size.

            //Create PDF unit converter

            PdfUnitConvertor converter = new PdfUnitConvertor();

            //Covert pixel to point

            float width = converter.ConvertFromPixels(image.Width, PdfGraphicsUnit.Point);

            float height = converter.ConvertFromPixels(image.Height, PdfGraphicsUnit.Point);

            //Add a section

            PdfSection section = doc.Sections.Add();

            //Set margin


            //Page Size

            section.PageSettings.Width = width;

            section.PageSettings.Height = height;

            //Add new page

            PdfPage page = section.Pages.Add();

Sample link:

Please let us know if you have any concern.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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