![]() |
wxIScan
|
A class to handle PDF files using libpoppler. More...
#include <wxpoppler.h>
Public Member Functions | |
wxPoppler () | |
Standard constructor. | |
virtual | ~wxPoppler () |
Virtual destructor. | |
virtual bool | Open (const wxString &strFileName) |
Opens a PDF file. | |
virtual bool | Open (char *pcData, const int nLength) |
Opens a PDF file in memory. | |
virtual int | GetPageCount () |
Get the number of pages in the PDF document. | |
virtual bool | SelectPage (int nIndex) |
Select the given page number to render by a consecutive call to RenderPage(). | |
virtual bool | RenderPage () |
Render the (previously selected) PDF page and store the result in m_oImage. | |
virtual int | SetDpi (int nDpi) |
Set the dpi parameter to the given value. Returns the old dpi value. | |
virtual wxImage | GetImage () |
Get the rendered PDF page as wxImage object. | |
Static Public Attributes | |
static int | m_nGlobalDpi = 300 |
Holds the standart image resolution in dots per inch for presetting m_nDpi. | |
Protected Member Functions | |
bool | Open (char *pcData, const int nLength, const wxString &strFileName) |
Opens a PDF stream from file or memory depending on the parameterization. | |
Protected Attributes | |
wxImage | m_oImage |
Image object rendered by RenderPage(). | |
int | m_nDpi |
Holds the image resolution in dots per inch. | |
PopplerPage * | m_pPdfPage |
A pointer to the current PDF page. | |
PopplerDocument * | m_pPdfDocument |
A pointer to the current PDF document. | |
Private Types | |
typedef PopplerDocument * | t_poppler_document_new_from_data (char *, int, const char *, GError **) |
typedef PopplerDocument * | t_poppler_document_new_from_file (const char *, const char *, GError **) |
typedef PopplerPage * | t_poppler_document_get_page (PopplerDocument *, int) |
typedef void | t_poppler_page_render_to_pixbuf (PopplerPage *, int, int, int, int, double, int, GdkPixbuf *) |
typedef void | t_poppler_page_get_size (PopplerPage *, double *, double *) |
typedef int | t_poppler_document_get_n_pages (PopplerDocument *) |
Static Private Attributes | |
static wxDynamicLibrary | m_oWxPopplerDynamicLibrary |
static t_poppler_document_new_from_data * | poppler_document_new_from_data = NULL |
static t_poppler_document_new_from_file * | poppler_document_new_from_file = NULL |
static t_poppler_document_get_page * | poppler_document_get_page = NULL |
static t_poppler_page_render_to_pixbuf * | poppler_page_render_to_pixbuf = NULL |
static t_poppler_page_get_size * | poppler_page_get_size = NULL |
static t_poppler_document_get_n_pages * | poppler_document_get_n_pages = NULL |
typedef int wxPoppler::t_poppler_document_get_n_pages(PopplerDocument *) [private] |
Definition at line 138 of file wxpoppler.h.
typedef PopplerPage* wxPoppler::t_poppler_document_get_page(PopplerDocument *, int) [private] |
Definition at line 135 of file wxpoppler.h.
typedef PopplerDocument* wxPoppler::t_poppler_document_new_from_data(char *, int, const char *, GError **) [private] |
Definition at line 133 of file wxpoppler.h.
typedef PopplerDocument* wxPoppler::t_poppler_document_new_from_file(const char *, const char *, GError **) [private] |
Definition at line 134 of file wxpoppler.h.
typedef void wxPoppler::t_poppler_page_get_size(PopplerPage *, double *, double *) [private] |
Definition at line 137 of file wxpoppler.h.
typedef void wxPoppler::t_poppler_page_render_to_pixbuf(PopplerPage *, int, int, int, int, double, int, GdkPixbuf *) [private] |
Definition at line 136 of file wxpoppler.h.
wxPoppler::wxPoppler | ( | ) |
Standard constructor.
Definition at line 48 of file wxpoppler.cpp.
References m_nDpi, m_nGlobalDpi, m_oWxPopplerDynamicLibrary, m_pPdfDocument, m_pPdfPage, poppler_document_get_n_pages, poppler_document_get_page, poppler_document_new_from_data, poppler_document_new_from_file, poppler_page_get_size, poppler_page_render_to_pixbuf, and WXPOPPPLER_LIBPOPPLER.
{ // Initialize normal members; m_pPdfPage= NULL; m_pPdfDocument= NULL; m_nDpi= m_nGlobalDpi; #if __WXPOPPLER_DYNAMIC__ if( !m_oWxPopplerDynamicLibrary.IsLoaded() ) { if( m_oWxPopplerDynamicLibrary.Load( wxDynamicLibrary::CanonicalizeName( wxT( WXPOPPPLER_LIBPOPPLER ) ) ) ) { poppler_document_new_from_data= (t_poppler_document_new_from_data *)m_oWxPopplerDynamicLibrary.GetSymbol( wxT( "poppler_document_new_from_data" ) ); poppler_document_new_from_file= (t_poppler_document_new_from_file *)m_oWxPopplerDynamicLibrary.GetSymbol( wxT( "poppler_document_new_from_file" ) ); poppler_document_get_page = (t_poppler_document_get_page *)m_oWxPopplerDynamicLibrary.GetSymbol( wxT( "poppler_document_get_page" ) ); poppler_page_render_to_pixbuf = (t_poppler_page_render_to_pixbuf *)m_oWxPopplerDynamicLibrary.GetSymbol( wxT( "poppler_page_render_to_pixbuf" ) ); poppler_page_get_size = (t_poppler_page_get_size *)m_oWxPopplerDynamicLibrary.GetSymbol( wxT( "poppler_page_get_size" ) ); poppler_document_get_n_pages = (t_poppler_document_get_n_pages *)m_oWxPopplerDynamicLibrary.GetSymbol( wxT( "poppler_document_get_n_pages" ) ); } else { // Log error message. wxLogError( wxString( wxT( "wxPoppler::wxPoppler -- " ) ) + _( "Cannot load poppler library." ) ); } } #endif // __WXPOPPLER_DYNAMIC__ }
wxPoppler::~wxPoppler | ( | ) | [virtual] |
Virtual destructor.
Definition at line 79 of file wxpoppler.cpp.
References m_pPdfDocument, and m_pPdfPage.
{ // If exists delete the PDF page. if( m_pPdfPage ) { g_object_unref( m_pPdfPage ); } // If exists delete the PDF document. if( m_pPdfDocument ) { g_object_unref( m_pPdfDocument ); } }
virtual wxImage wxPoppler::GetImage | ( | ) | [inline, virtual] |
Get the rendered PDF page as wxImage object.
Definition at line 96 of file wxpoppler.h.
References m_oImage.
{ return m_oImage; }
virtual int wxPoppler::GetPageCount | ( | ) | [inline, virtual] |
Get the number of pages in the PDF document.
Definition at line 67 of file wxpoppler.h.
References m_pPdfDocument, and poppler_document_get_n_pages.
{ return poppler_document_get_n_pages( m_pPdfDocument ); }
virtual bool wxPoppler::Open | ( | char * | pcData, |
const int | nLength | ||
) | [inline, virtual] |
Opens a PDF file in memory.
pcData | A pointer to the buffer containing the PDF document. |
nLength | The length (in Byte) of the PDF document. |
Definition at line 61 of file wxpoppler.h.
References Open().
{ return Open( pcData, nLength, wxEmptyString ); }
bool wxPoppler::Open | ( | char * | pcData, |
const int | nLength, | ||
const wxString & | strFileName | ||
) | [protected] |
Opens a PDF stream from file or memory depending on the parameterization.
pcData | A pointer to the memory buffer. |
nLength | The length of the PDF data in the memory buffer. |
strFileName | The name of the PDF file. |
If there is both a memory buffer (in pcData parameter) and its lenght (in nLength parameter) given the PDF stream is read from the memory buffer. Otherwise it is read from the file given in the strFileName parameter.
Note: This function is protected. It is implicitely called by the public overloaded Open() functions.
Definition at line 96 of file wxpoppler.cpp.
References m_pPdfDocument, poppler_document_new_from_data, and poppler_document_new_from_file.
{ GError *pGError= NULL; if( pcData && nLength ) { m_pPdfDocument= poppler_document_new_from_data( pcData, nLength, "", &pGError ); } else { wxFileName oFileName( strFileName ); wxString strFileNameAsUri= wxFileSystem::FileNameToURL( oFileName ); // // Add the "file://" protocol-identifier. // wxString strFileNameAsUri= wxT( "file://" ) + strFileName; // // // Replace backslashes by slashes to confirm to the "file://" URI rules. // strFileNameAsUri.Replace( wxT( "\\" ), wxT( "/" ) ); // // Open the file. m_pPdfDocument= poppler_document_new_from_file( strFileNameAsUri.char_str(), "", &pGError ); } if( !m_pPdfDocument ) { // Log error message from poppler library. if( pGError ) { wxLogError( wxT( "wxPoppler::Open -- GError: %s" ), wxString( pGError->message, wxConvLibc ).c_str() ); g_clear_error( &pGError ); } // Signal error. return false; } return true; }
virtual bool wxPoppler::Open | ( | const wxString & | strFileName | ) | [inline, virtual] |
Opens a PDF file.
strFileName | The name of the PDF file. |
Definition at line 50 of file wxpoppler.h.
Referenced by Open().
{ return Open( NULL, 0, strFileName ); }
bool wxPoppler::RenderPage | ( | ) | [virtual] |
Render the (previously selected) PDF page and store the result in m_oImage.
Definition at line 150 of file wxpoppler.cpp.
References m_nDpi, m_oImage, m_pPdfPage, poppler_page_get_size, and poppler_page_render_to_pixbuf.
{ if( !m_pPdfPage ) { // Signal error. wxLogError( wxString( wxT( "wxPoppler::RenderPage -- " ) ) + _( "PDF page is not valid." ) ); return false; } double dblWidth, dblHeight; double dblDpiBy72= (double)m_nDpi / 72.0; poppler_page_get_size( m_pPdfPage, &dblWidth, &dblHeight ); int nWidth= (int)( dblWidth * dblDpiBy72 ); int nHeight= (int)( dblHeight * dblDpiBy72 ); GdkPixbuf *pGdkPixBuf= gdk_pixbuf_new( GDK_COLORSPACE_RGB, false, 8, nWidth, nHeight ); if( !pGdkPixBuf ) { // Signal error. wxLogError( wxString( wxT( "wxPoppler::RenderPage -- " ) ) + _( "Cannot create GdkPixbuf object." ) ); return false; } poppler_page_render_to_pixbuf( m_pPdfPage, 0, 0, nWidth, nHeight, dblDpiBy72, 0, pGdkPixBuf ); if( ( gdk_pixbuf_get_colorspace( pGdkPixBuf ) != GDK_COLORSPACE_RGB ) || ( gdk_pixbuf_get_bits_per_sample( pGdkPixBuf ) != 8 ) || ( gdk_pixbuf_get_has_alpha( pGdkPixBuf ) ) || ( gdk_pixbuf_get_n_channels( pGdkPixBuf ) != 3 ) ) { // Signal error. wxLogError( wxString( wxT( "wxPoppler::RenderPage -- " ) ) + _( "Got wrong bitmap format from libpoppler." ) ); g_object_unref( pGdkPixBuf ); return false; } int nPixBufRowSize= gdk_pixbuf_get_rowstride( pGdkPixBuf ); guchar *pPixBufData= gdk_pixbuf_get_pixels( pGdkPixBuf ); int nImageBufRowSize= 3 * nWidth; unsigned char *pImageBuf= (unsigned char *)malloc( nImageBufRowSize * nHeight ); if( !pImageBuf ) { // Signal error. wxLogError( wxString( wxT( "wxPoppler::RenderPage -- " ) ) + _( "Cannot allocate a buffer for wxImage object." ) ); g_object_unref( pGdkPixBuf ); return false; } unsigned char *pImageBufLine= pImageBuf; for( int y= 0; y < nHeight; y++ ) { memcpy( pImageBufLine, pPixBufData, nImageBufRowSize ); pPixBufData += nPixBufRowSize; pImageBufLine += nImageBufRowSize; } // Create an wxImage object an set resolution information. m_oImage= wxImage( nWidth, nHeight, pImageBuf ); m_oImage.SetOption( wxIMAGE_OPTION_RESOLUTIONUNIT, wxIMAGE_RESOLUTION_INCHES ); m_oImage.SetOption( wxIMAGE_OPTION_RESOLUTION, m_nDpi ); m_oImage.SetOption( wxIMAGE_OPTION_RESOLUTIONX, m_nDpi ); m_oImage.SetOption( wxIMAGE_OPTION_RESOLUTIONY, m_nDpi ); g_object_unref( pGdkPixBuf ); return true; }
bool wxPoppler::SelectPage | ( | int | nIndex | ) | [virtual] |
Select the given page number to render by a consecutive call to RenderPage().
nIndex | Zero based page number. |
Definition at line 135 of file wxpoppler.cpp.
References m_pPdfDocument, m_pPdfPage, and poppler_document_get_page.
{ PopplerPage *pPdfPageTemp= poppler_document_get_page( m_pPdfDocument, nIndex ); if( !pPdfPageTemp ) { return false; } m_pPdfPage= pPdfPageTemp; g_object_ref( m_pPdfPage ); return true; }
virtual int wxPoppler::SetDpi | ( | int | nDpi | ) | [inline, virtual] |
Set the dpi parameter to the given value. Returns the old dpi value.
nDpi | The new dpi value. |
Definition at line 87 of file wxpoppler.h.
References m_nDpi.
int wxPoppler::m_nDpi [protected] |
Holds the image resolution in dots per inch.
Definition at line 125 of file wxpoppler.h.
Referenced by RenderPage(), SetDpi(), and wxPoppler().
int wxPoppler::m_nGlobalDpi = 300 [static] |
Holds the standart image resolution in dots per inch for presetting m_nDpi.
Definition at line 121 of file wxpoppler.h.
Referenced by wxPoppler().
wxImage wxPoppler::m_oImage [protected] |
Image object rendered by RenderPage().
Definition at line 124 of file wxpoppler.h.
Referenced by GetImage(), and RenderPage().
wxDynamicLibrary wxPoppler::m_oWxPopplerDynamicLibrary [static, private] |
Definition at line 131 of file wxpoppler.h.
Referenced by wxPoppler().
PopplerDocument* wxPoppler::m_pPdfDocument [protected] |
A pointer to the current PDF document.
Definition at line 127 of file wxpoppler.h.
Referenced by GetPageCount(), Open(), SelectPage(), wxPoppler(), and ~wxPoppler().
PopplerPage* wxPoppler::m_pPdfPage [protected] |
A pointer to the current PDF page.
Definition at line 126 of file wxpoppler.h.
Referenced by RenderPage(), SelectPage(), wxPoppler(), and ~wxPoppler().
wxPoppler::t_poppler_document_get_n_pages * wxPoppler::poppler_document_get_n_pages = NULL [static, private] |
Definition at line 145 of file wxpoppler.h.
Referenced by GetPageCount(), and wxPoppler().
wxPoppler::t_poppler_document_get_page * wxPoppler::poppler_document_get_page = NULL [static, private] |
Definition at line 142 of file wxpoppler.h.
Referenced by SelectPage(), and wxPoppler().
wxPoppler::t_poppler_document_new_from_data * wxPoppler::poppler_document_new_from_data = NULL [static, private] |
Definition at line 140 of file wxpoppler.h.
Referenced by Open(), and wxPoppler().
wxPoppler::t_poppler_document_new_from_file * wxPoppler::poppler_document_new_from_file = NULL [static, private] |
Definition at line 141 of file wxpoppler.h.
Referenced by Open(), and wxPoppler().
wxPoppler::t_poppler_page_get_size * wxPoppler::poppler_page_get_size = NULL [static, private] |
Definition at line 144 of file wxpoppler.h.
Referenced by RenderPage(), and wxPoppler().
wxPoppler::t_poppler_page_render_to_pixbuf * wxPoppler::poppler_page_render_to_pixbuf = NULL [static, private] |
Definition at line 143 of file wxpoppler.h.
Referenced by RenderPage(), and wxPoppler().