PoDoFo PDF Library
PoDoFo is a portable C++ library for manipulating (creating, editing and reading) PDF files. SPT uses PoDoFo to extract text content from PDF documents and feed to the Xapian search engine library for site search.
Building PoDoFo using Oracle SolarisStudio compiler suite requires quite a few modifications to the source tree. Most of the changes are trivial, and are related to the fact that other software we use needs to be built using the stlport4 library which does not support the cxxx include syntax for including standard system c libraries.
Core API
The files listed here need to be updated to build using SolarisStudio CC compiler. All these source files are under the src/base directory of the source distribution.
src/base/podofoapi.h - add defines for CC compiler
154 #else
155 #define PODOFO_DEPRECATED
156 #define PODOFO_PURE_FUNCTION
157 #define PODOFO_NOTHROW __declspec(nothrow)
158 #endif
to
154 #elif defined( __SUNPRO_CC )
155 #define PODOFO_DEPRECATED
156 #define PODOFO_PURE_FUNCTION
157 #define PODOFO_NOTHROW
158 #else
159 #define PODOFO_DEPRECATED
160 #define PODOFO_PURE_FUNCTION
161 #define PODOFO_NOTHROW __declspec(nothrow)
162 #endif
src/base/PdfDefines.h - remove the trailing comma on line 162 to remove warnings.
160 enum EPdfWriteMode {
161 ePdfWriteMode_Compact = 0x01, ///< Try to write the PDF as compact as possible (Default)
162 ePdfWriteMode_Clean = 0x02, ///< Create a PDF that is readable in a text editor, i.e. insert spaces and linebreaks between tokens
163};
to
160 enum EPdfWriteMode {
161 ePdfWriteMode_Compact = 0x01, ///< Try to write the PDF as compact as possible (Default)
162 ePdfWriteMode_Clean = 0x02 ///< Create a PDF that is readable in a text editor, i.e. insert spaces and linebreaks between tokens
163};
src/base/PdfError.h
30 #include <cstdarg>
to
30 #if defined( __SUNPRO_CC )
31 #include <stdarg.h>
32 #else
33 #include <cstdarg>
34 #endif
src/base/PdfVariant.h
24 #include <cmath>
to
24 #if defined( __SUNPRO_CC )
25 #include <math.h>
26 #else
27 #include <cmath>
28 #endif
src/base/PdfCompilerCompatPrivate.h
8 #if defined(__BORLANDC__) || defined( __TURBOC__)
to
8 #if defined(__BORLANDC__) || defined( __TURBOC__) || defined( __SUNPRO_CC )
Note:
The current implementation (version 0.9.1 and latest version checked out from subversion) seem to have issues when built on Solaris 11 using SolarisStudio. The issue seems like they should affect other platforms as well, however the pre-built package from macports do not exhibit the issue, so assuming it is somehow Solaris related.
The
PdfInputDevice
header file provides an implementation of Eof()
method that does not check whether the instance was constructed and initialised to use a FILE* or a istream*. The Eof implementation assumes the instance was initialised with an istream* which is not the case when using the supplied podofotxtextract
tool, which crashes when run on Solaris. The following modifications will address this issue.src/base/PdfInputDevice.h
25 #if defined( __SUNPRO_CC )
26 #include <stdio.h>
27 #else
28 #include <cstdio>
29 #endif
187 bool PdfInputDevice::Eof() const
188 {
189 if ( m_pStream )
190 return m_pStream->eof();
191 else
192 return feof( m_pFile );
193 }
src/base/PdfInputDevice.cpp
35 PdfInputDevice::PdfInputDevice( const char* pszFilename )
36 {
37 this->Init();
38
39 if( !pszFilename )
40 {
41 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
42 }
43
44 try {
45 m_pFile = fopen(pszFilename, "rb");
46 //m_pStream = new std::ifstream( pszFilename, std::ios::binary );
47 if( !m_pFile)
48 {
49 PODOFO_RAISE_ERROR_INFO( ePdfError_FileNotFound, pszFilename );
50 }
51 m_StreamOwned = true;
52 }
53 catch(...) {
54 // should probably check the exact error, but for now it's a good error
55 PODOFO_RAISE_ERROR_INFO( ePdfError_FileNotFound, pszFilename );
56 }
57 //PdfLocaleImbue(*m_pStream);
58 }
to
35 PdfInputDevice::PdfInputDevice( const char* pszFilename )
36 {
37 this->Init();
38
39 if( !pszFilename )
40 {
41 PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
42 }
43
44 try {
45 m_pStream = new std::ifstream( pszFilename, std::ios::binary );
46 if( !m_pStream)
47 {
48 PODOFO_RAISE_ERROR_INFO( ePdfError_FileNotFound, pszFilename );
49 }
50 m_StreamOwned = true;
51 }
52 catch(...) {
53 // should probably check the exact error, but for now it's a good error
54 PODOFO_RAISE_ERROR_INFO( ePdfError_FileNotFound, pszFilename );
55 }
56 PdfLocaleImbue(*m_pStream);
57 }
Test Sources
Most of the test sources under the test/xyx directory include cstdio and in some cases cstdlib. For Solaris CC when using library=stlport4 option these are not supported and need to reference the older stdio.h and stdlib.h files. instead.
The following files need to be edited with the usual check for __SUNPRO_CC and including the appropriate variant of the system header.
The following files need to be edited with the usual check for __SUNPRO_CC and including the appropriate variant of the system header.
- test/CreationTest/CreationTest.cpp
- test/FilterTest/FilterTest.cpp
- test/FormTest/FormTest.cpp
- test/LargeTest/LargeTest.cpp
- test/SignatureTest/SignTest.cpp
- test/VariantTest/VariantTest.cpp
- test/WatermarkTest/WatermarkTest.cpp
Tools
Most of the tools sources under the tools/xyx directory include cstdio and in some cases cstdlib. For Solaris CC when using library=stlport4 option these are not supported and need to reference the older stdio.h and stdlib.h files. instead.
The following files need to be edited with the usual check for __SUNPRO_CC and including the appropriate variant of the system header.
The following files need to be edited with the usual check for __SUNPRO_CC and including the appropriate variant of the system header.
- tools/podofocountpages/countpages.cpp
- tools/podofocrop/podofocrop.cpp
- tools/podofoencrypt/podofoencrypt.cpp
- tools/podofoimgextract/ImageExtractor.cpp
- tools/podofomerge/podofomerge.cpp
- tools/podofopages/podofopages.cpp
- tools/podofopdfinfo/podofopdfinfo.cpp
- tools/podofotxt2pdf/podofotxt2pdf.cpp
- tools/podofotxtextract/TextExtractor.h
- tools/podofouncompress/Uncompress.cpp
- tools/podofouncompress/podofouncompress.cpp
- tools/podofoimpose/impositionplan.h
- tools/podofoincrementalupdates/incrementalupdates.cpp
Building
PoDoFo uses the CMake system to build the library. The following shell script may be used to build and install PoDoFo (note the script builds PoDoFo in debug mode).
#!/bin/ksh export CC=cc export CXX=CC export CFLAGS="-m64" export CXXFLAGS="-features=extensions -filt=stdlib -library=stlport4 -sync_stdio=no $CFLAGS" mkdir build-podofo ( cd build-podofo cmake -Wno-dev -DCMAKE_INSTALL_PREFIX=/opt/podofo \ -DCMAKE_BUILD_TYPE:STRING=Debug \ -DPODOFO_BUILD_SHARED:BOOL=TRUE -DPODOFO_BUILD_STATIC:BOOL=FALSE .. gmake -j8 if [ $? -eq 0 ] then pfexec gmake install fi )
With these changes the library may be built and installed. The shell script displayed may be used to build and install PoDoFo.