Print Page | Close Window

Page dimensions

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3453
Printed Date: 01 May 24 at 2:25AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Page dimensions
Posted By: RaphQuin
Subject: Page dimensions
Date Posted: 17 Apr 17 at 9:13PM
Hi
I work with DebenuPDFLibraryDLL1212, Visual Studio on Windows 10 Pro.
I want to render pdf in a wpf image control.

I tried with : 

internal Bitmap GetDAImage( int page, float resolution = 150 )
{
  if ( _isOK ) // license OK
  {
    // on ouvre le fichier
    _pdfInHandle = _dpl.DAOpenFileReadOnly( pdfIn, null );

    // on récupère le nombre de page du fichier
    _pdfPageCount = _dpl.DAGetPageCount( _pdfInHandle );
    
    // on récupère la référence de la page du fichier
    int pageRefNo = _dpl.DAFindPage( _pdfInHandle, page );

    int Zoom = 72;
    _pageWidth = _dpl.DAGetPageWidth( _pdfInHandle, pageRefNo ) / Zoom;   ******** NOT OK
    _pageHeight = _dpl.DAGetPageHeight( _pdfInHandle, pageRefNo ) / Zoom; ******** NOT OK

    try
    {
      // on calcule les dimensions de l'image
      b = new Bitmap( Convert.ToInt32( _pageWidth * resolution ), Convert.ToInt32( _pageHeight * resolution ) );

      // on dessine l'image
      using ( Graphics g = Graphics.FromImage( b ) )
      {
        //int dc = (int)g.GetHdc();
        //_dpl.DARenderPageToDC( _pdfInHandle, pageRefNo, resolution, dc );
        //g.ReleaseHdc( (IntPtr)dc );

        IntPtr dc = g.GetHdc();
        _dpl.DARenderPageToDC( _pdfInHandle, pageRefNo, resolution, dc );
        g.ReleaseHdc( dc );
      }
    }
    catch { }
  }

  return b;
}

I convert the bitmap to BitmapImage.

It's ok but 1 file has a problem (it came from Ricoh Aficio multifuntion).
It's a A4 format, and with pdf readers, I see it as A4 (no landscape) 21x29.7cm document.
But _dpl.DAGetPageWidth and _dpl.DAGetPageHeight give me wrong values: 29.7x21cm, not 21x29.7cm, so in my image, document is truncated in the bottom.
I inserted a new function in the beginning of my GetDAImage, to get real dimensions of the page :

internal int LoadPdf( string fileName )
{
  _fileName = fileName;

  if ( _isOK ) // license OK
  {
    // on charge le fichier à copier
    _dpl.LoadFromFile( fileName, null );
    _dpl.SelectedDocument();

    // on redimensionne en A4
    _dpl.SetPageSize( "A4" );
    // on définit l'unité de mesure ( 1/72 inches per unit )
    _dpl.SetMeasurementUnits( 0 );
    // on définit l'origine en haut à gauche
    _dpl.SetOrigin( 1 );

    // on récupère le nombre de page du fichier
    _pdfPageCount = _dpl.PageCount();

    // on récupère les dimensions du document
    _pageWidth = _dpl.PageWidth();      ******** OK
    _pageHeight = _dpl.PageHeight();    ******** OK
    
    int rotation = _dpl.PageRotation();
    int test = _dpl.GetOrigin();
  }

  return _pdfPageCount;
}

Now it's ok.
So I tried without DA functions to avoid 2 openings :

internal Bitmap GetImage( int page, float resolution = 150 )
{
  Bitmap b = null;
  
  LoadPdf("myfile");

  if ( _isOK ) // license OK
  {
    // on fait les vérification de la plages des pages
    if ( page > _pdfPageCount )
      return null;

    int Zoom = 72;
    _pageWidth /= Zoom;
    _pageHeight /= Zoom;

    try
    {
      // on calcule les dimensions de l'image
      b = new Bitmap( Convert.ToInt32( _pageWidth * resolution ), Convert.ToInt32( _pageHeight * resolution ) );

      // on dessine l'image
      using ( Graphics g = Graphics.FromImage( b ) )
      {
        //int dc = (int)g.GetHdc();
        //_dpl.DARenderPageToDC( _pdfInHandle, pageRefNo, resolution, dc );
        //g.ReleaseHdc( (IntPtr)dc );

        IntPtr dc = g.GetHdc();
        _dpl.RenderPageToDC( resolution, page, dc );
        g.ReleaseHdc( dc );
      }
    }
    catch { }
  }

  return b;
}

And now I have got a new problem :
my left and top of the document is drawn with an surprising origin in my image control:
left = +200
top = -200
so I can see only the left bottom of my document.

The file seems to have a rotation of 270 with 21x29.7cm dimensions.
How can I fix this problem ?

Regards

Raph



Replies:
Posted By: Ingo
Date Posted: 17 Apr 17 at 9:23PM
Hi Raph,

you're right - there's a rotation setting.
So... before rendering the page was re-rotated into the original layout landscape.
The DIN A4 portrait is only the displayed state AFTER rotation.
Using the function NormalizePage you're telling the pdf that the actual displayed layout isn't made by rotation but it's the original layout.
After this function you won't have any problems while rendering:
http://www.debenu.com/docs/pdf_library_reference/NormalizePage.php

Cheers and welcome here,
Ingo



-------------
Cheers,
Ingo



Posted By: RaphQuin
Date Posted: 17 Apr 17 at 9:57PM
Hi Ingo,
thank you for your help.
I tried with 

_dpl.NormalizePage( 0 );

 and I still had my problem.
I finaly removed 

_dpl.SetPageSize( "A4" );

and my problem disappeared. Clap

Thank you from France.

Regards

Raph.



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