Print Page | Close Window

Render PDF page does not match bitmap

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: General Discussion
Forum Description: Discussion board for Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2429
Printed Date: 26 Nov 24 at 8:41AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Render PDF page does not match bitmap
Posted By: Rene
Subject: Render PDF page does not match bitmap
Date Posted: 09 Oct 12 at 3:59PM
Hi all,
 
In have tried to render PDF to a bitmap, but this seems to be a quite sophisticated task. We want to render the PDF exact in a bitmap which size is calculated by PageWidth and PageWidth
 
For landscape formats I do not get exact results. Could depend on the fact that DPI is a long value and the calculated DPI is a rational number.
 
The code:
 
        wp = scaleX(PDF.PageWidth, vbPoints, vbPixels)
        hp = scaleY(PDF.PageHeight, vbPoints, vbPixels)
       
        ratioScreen = ScaleWidth / ScaleHeight
       
        Dim DPI_H As Long, DPI_V As Long, DPI As Long
       
        If wp > hp Then
            ratioPDF = wp / hp
            'Landscape
            w = ScaleWidth * mZoom
            h = ScaleHeight * (1 / ratioPDF) / (1 / ratioScreen) * mZoom
            pXOffset = 0
            pYOffset = (ScaleHeight * mZoom - h) / 2
            DPI = w / (PDF.PageWidth / 72)
        Else
            ratioPDF = wp / hp
            h = ScaleHeight * mZoom
            w = ScaleWidth * ratioPDF / ratioScreen * mZoom
            pXOffset = (ScaleWidth - w) / 2
            pYOffset = 0
            DPI = h / (PDF.PageHeight / 72)
        End If
       
        SetRect pbmpRect, 0, 0, w, h
       
        If Not pImg.gdiToken Then pImg.gdiToken = pImg.CreateGDIplusToken
        pImg.ManageOwnDC = True
           
        If pImg.Width = w And pImg.Height = h Then
            pImg.EraseDIB
        Else
            pImg.InitializeDIB w, h
        End If
           
        mDC = pImg.LoadDIBinDC(True)
           
        PDF.RenderPageToDC DPI, mPageIndex, mDC
 
What's going wrong? Any samples for perfect drawing results available?
Wouldn't it be better to get a function RenderToRect with parameters dc,page,x,y,w,h and DPI is calculated internally?
 
Cheers
 
RenĂ© 

 



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