Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Page dimensions
  FAQ FAQ  Forum Search   Register Register  Login Login

Page dimensions

 Post Reply Post Reply
Author
Message
RaphQuin View Drop Down
Beginner
Beginner


Joined: 17 Apr 17
Location: Toulouse
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote RaphQuin Quote  Post ReplyReply Direct Link To This Post Topic: Page dimensions
    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
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
RaphQuin View Drop Down
Beginner
Beginner


Joined: 17 Apr 17
Location: Toulouse
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote RaphQuin Quote  Post ReplyReply Direct Link To This Post 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.


Edited by RaphQuin - 17 Apr 17 at 9:58PM
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store