Print Page | Close Window

Render at high DPI with max width

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2204
Printed Date: 27 Apr 24 at 5:36AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Render at high DPI with max width
Posted By: Rowan
Subject: Render at high DPI with max width
Date Posted: 30 Mar 12 at 9:39AM
int outputDPI = 200;
int maxWidth = 1000;

for (int page = 1; page <= totalIMGS; page++)
{
    lib.SelectPage(page);

    double pageWidth = lib.PageWidth();
    double pageHeight = lib.PageHeight();
    double scale = 1;

    int imgWidth = Convert.ToInt32((pageWidth / 72) * outputDPI);
    int imgHeight = Convert.ToInt32((pageHeight / 72) * outputDPI);

    if (imgWidth > maxWidth)
    {
        scale = (double)maxWidth / (double)imgWidth;
        imgWidth = maxWidth;
        imgHeight = Convert.ToInt32(imgHeight * scale);
    }

    using (Bitmap dcBmp = new Bitmap(imgWidth, imgHeight))
    {
        using (Graphics g = Graphics.FromImage(dcBmp))
        {
IntPtr hdc = g.GetHdc();
lib.SetRenderScale(scale);
lib.RenderPageToDC(outputDPI, page, hdc);
g.ReleaseHdc(hdc);
        }
        // dcBmp.Save("page" + page.ToString() + ".bmp");
    }
}




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk