Cross Compiling static and shared Win32 version PoDoFo under Debian Lenny

I tried many times to compile Podofo 0.9 and svn trunk under Windows 7 + MinGW32, but always failed(I have successfully compiled static and shared version PoDoFo 0.84 under the same environment). So I decided to do the job under Linux with MinGW cross compiling environment.
After the job, Build MinGW Cross Compiling Environment under Debian Lenny, very first time, I tried to compile PoDoFo 0.9 and svn trunk(r1445), and finally both succeed.
download and unpack
wget http://ncu.dl.sourceforge.net/project/podofo/podofo/0.9/podofo-0.9.0.tar.bz2
tar jxf podofo-0.9.0.tar.bz2

Compile Win32 Static Version
mkdir podofo-0.9.0-win32-static
cd podofo-0.9.0-win32-static
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/mingw/usr/i686-pc-mingw32/share/cmake/mingw-cross-env-conf.cmake ../podofo-0.9.0 -DFREETYPE_INCLUDE_DIR_FT2BUILD:PATH=/opt/mingw/usr/i686-pc-mingw32/include/freetype2 -DFREETYPE_INCLUDE_DIR_FTHEADER:PATH=/opt/mingw/usr/i686-pc-mingw32/include -DFREETYPE_LIBRARY_RELEASE:FILEPATH=/opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a -DWIN32=1 -DCMAKE_INSTALL_PREFIX:PATH=/root/podofo-0.9.0-win32-static
make
make install

Maybe because of the bug of the podofo-0.9.0/cmake/modules/FindFREETYPE.cmake, I had to explicit add the freetype info to cmake, if you execute the following command,
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/mingw/usr/i686-pc-mingw32/share/cmake/mingw-cross-env-conf.cmake ../podofo-0.9.0-win32-static -DWIN32=1 -DCMAKE_INSTALL_PREFIX:PATH=/root/podofo-0.9.0-win32-static
you will get the following error message, even though you have already installed FreeType correctly,

CMake Error at /usr/share/cmake-2.6/Modules/FindPackageHandleStandardArgs.cmake:52 (MESSAGE):
Could NOT find FREETYPE
Call Stack (most recent call first):
cmake/modules/FindFREETYPE.cmake:75 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:354 (FIND_PACKAGE)

and because Linux is case sensitive, so I got the following two error messages,
Scanning dependencies of target ContentParser
[ 57%] Building CXX object test/ContentParser/CMakeFiles/ContentParser.dir/main.cpp.obj
Linking CXX executable ContentParser.exe
/opt/mingw/usr/lib/gcc/i686-pc-mingw32/4.5.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lWS2_32
/opt/mingw/usr/lib/gcc/i686-pc-mingw32/4.5.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lWS2_32
/opt/mingw/usr/lib/gcc/i686-pc-mingw32/4.5.2/../../../../i686-pc-mingw32/bin/ld: cannot find -lWS2_32
collect2: ld returned 1 exit status
make[2]: *** [test/ContentParser/ContentParser.exe] Error 1
make[1]: *** [test/ContentParser/CMakeFiles/ContentParser.dir/all] Error 2
make: *** [all] Error 2

(to solve it, just run the following command
ln -s /opt/mingw/usr/i686-pc-mingw32/lib/libws2_32.a /opt/mingw/usr/i686-pc-mingw32/lib/libWS2_32.a
)
and

Scanning dependencies of target helloworld-base14
[100%] Building CXX object examples/helloworld-base14/CMakeFiles/helloworld-base14.dir/helloworld-base14.cpp.obj
/opt/test/podofo-0.9.0/examples/helloworld-base14/helloworld-base14.cpp:31:21: fatal error: BaseTsd.h: No such file or directory
compilation terminated.
make[2]: *** [examples/helloworld-base14/CMakeFiles/helloworld-base14.dir/helloworld-base14.cpp.obj] Error 1
make[1]: *** [examples/helloworld-base14/CMakeFiles/helloworld-base14.dir/all] Error 2
make: *** [all] Error 2

(
to solve it, just run the following command
ln -s /opt/mingw/usr/i686-pc-mingw32/include/basetsd.h /opt/mingw/usr/i686-pc-mingw32/include/BaseTsd.h

)

and when compiled podofoimg2pdf, another error message met,

Scanning dependencies of target podofoimg2pdf
[ 86%] Building CXX object tools/podofoimg2pdf/CMakeFiles/podofoimg2pdf.dir/podofoimg2pdf.cpp.obj
[ 86%] Building CXX object tools/podofoimg2pdf/CMakeFiles/podofoimg2pdf.dir/ImageConverter.cpp.obj
Linking CXX executable podofoimg2pdf.exe
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_write_raw_data':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:321: undefined reference to `_jpeg_write_raw_data'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_finish_compress':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:328: undefined reference to `_jpeg_finish_compress'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_set_colorspace':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:288: undefined reference to `_jpeg_set_colorspace'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_create_compress':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:265: undefined reference to `_jpeg_CreateCompress'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_set_defaults':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:282: undefined reference to `_jpeg_set_defaults'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_write_tables':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:334: undefined reference to `_jpeg_write_tables'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_set_quality':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:294: undefined reference to `_jpeg_set_quality'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_suppress_tables':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:301: undefined reference to `_jpeg_suppress_tables'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_start_compress':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:307: undefined reference to `_jpeg_start_compress'
/opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a(tif_jpeg.o): In function `TIFFjpeg_write_scanlines':
/opt/mingw/tmp-tiff/tiff-3.9.4/libtiff/tif_jpeg.c:314: undefined reference to `_jpeg_write_scanlines'
collect2: ld returned 1 exit status
make[2]: *** [tools/podofoimg2pdf/podofoimg2pdf.exe] Error 1
make[1]: *** [tools/podofoimg2pdf/CMakeFiles/podofoimg2pdf.dir/all] Error 2
make: *** [all] Error 2

from the message, I know it need Jpeg library, checking podofo-0.9.0-win32-static/tools/podofoimg2pdf/CMakeFiles/podofoimg2pdf.dir/link.txt
/opt/mingw/usr/bin/i686-pc-mingw32-g++ -O3 -DNDEBUG CMakeFiles/podofoimg2pdf.dir/podofoimg2pdf.cpp.obj CMakeFiles/podofoimg2pdf.dir/ImageConverter.cpp.obj -o podofoimg2pdf.exe -Wl,--out-implib,libpodofoimg2pdf.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/opt/test/podofo-win32/src -lpodofo /opt/mingw/usr/i686-pc-mingw32/lib/libz.a /opt/mingw/usr/i686-pc-mingw32/lib/libjpeg.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lWS2_32 /opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a /opt/mingw/usr/i686-pc-mingw32/lib/libpng.a /opt/mingw/usr/i686-pc-mingw32/lib/libz.a /opt/mingw/usr/i686-pc-mingw32/lib/libjpeg.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lWS2_32 /opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a /opt/mingw/usr/i686-pc-mingw32/lib/libpng.a /opt/mingw/usr/i686-pc-mingw32/lib/libtiff.a
it already includes libjpeg.a, I do not know why, but have to append some code to let it works, and finally the content of link.txt is as following,
/opt/mingw/usr/bin/i686-pc-mingw32-g++ -O3 -DNDEBUG CMakeFiles/podofoimg2pdf.dir/podofoimg2pdf.cpp.obj CMakeFiles/podofoimg2pdf.dir/ImageConverter.cpp.obj -o podofoimg2pdf.exe -Wl,--out-implib,libpodofoimg2pdf.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/opt/test/podofo-win32/src -lpodofo /opt/mingw/usr/i686-pc-mingw32/lib/libz.a /opt/mingw/usr/i686-pc-mingw32/lib/libjpeg.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lWS2_32 /opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a /opt/mingw/usr/i686-pc-mingw32/lib/libpng.a /opt/mingw/usr/i686-pc-mingw32/lib/libz.a /opt/mingw/usr/i686-pc-mingw32/lib/libjpeg.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lWS2_32 /opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a /opt/mingw/usr/i686-pc-mingw32/lib/libpng.a -L/opt/mingw/usr/i686-pc-mingw32/lib -ltiff -ljpeg -lz .
and now, the Win32 static version PoDoFo 0.9.0 created and installed into /root/podofo-0.9.0-win32-static folder.
To compile shared version, we need do some modification, by default, /opt/mingw/usr/i686-pc-mingw32/share/cmake/mingw-cross-env-conf.cmake has set BUILD_SHARED_LIBS option as OFF, so you need set it ON
mkdir podofo-0.9.0-win32-shared
cd podofo-0.9.0-win32-shared
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/mingw/usr/i686-pc-mingw32/share/cmake/mingw-cross-env-conf.cmake ../podofo-0.9.0 -DFREETYPE_INCLUDE_DIR_FT2BUILD:PATH=/opt/mingw/usr/i686-pc-mingw32/include/freetype2 -DFREETYPE_INCLUDE_DIR_FTHEADER:PATH=/opt/mingw/usr/i686-pc-mingw32/include -DFREETYPE_LIBRARY_RELEASE:FILEPATH=/opt/mingw/usr/i686-pc-mingw32/lib/libfreetype.a -DWIN32=1 -DCMAKE_INSTALL_PREFIX:PATH=/root/podofo-0.9.0-win32-shared -DBUILD_SHARED_LIBS:BOOL=TRUE -DPODOFO_BUILD_SHARED=1
make
make install

and when Creating library file: libpodofo.dll.a will get the same error as podofoimg2pdf, and the solution is also same.

Be Sociable, Share!

PoDoFo used in 6 Open Source Projects

Recently I tried to compile PoDoFo on Windows using Mingw, so i did some researches, and found 6 projects that use PoDoFo as PDF editing library.

  • PoDoFoBrowser
  • PoDoFoBrowser is developed with Qt4 by the same author of PoDoFo, a gui for editing the object structur of PDF files directly.

  • Scribus
  • Scribus is an Open Source program that brings award-winning professional page layout to Linux/UNIX, Mac OS X, OS/2 Warp 4/eComStation and Windows desktops with a combination of “press-ready” output and new approaches to page layout.
    Underneath the modern and user friendly interface, Scribus supports professional publishing features, such as CMYK color, separations, Spot Colors, ICC color management and versatile PDF creation.

  • Calibre-ebook
  • calibre is a free and open source e-book library management application developed by users of e-books for users of e-books

  • Comment
  • Comment is a PDF annotator (tailored to the author’s needs as a mathematician who wants to comment articles and save the comments for later reference with the pdf files).

  • OkularAnnotMerge
  • OkularAnnotMerge is a quick and dirty hack to merge okularannotations (saved in a xml separate from the annotated file) into the pdf.

P.S.

PoDoFo is a library to work with the PDF file format. The name comes from the first letter of PDF (Portable Document Format). A few tools to work with PDF files are already included in the PoDoFo package.
The PoDoFo library is a free, portable C++ library which includes classes to parse PDF files and modify their contents into memory. The changes can be written back to disk easily. The parser can also be used to extract information from a PDF file (for example the parser could be used in a PDF viewer). Besides parsing PoDoFo includes also very simple classes to create your own PDF files. All classes are documented so it is easy to start writing your own application using PoDoFo.
PoDoFo is written in C++ and the code was sucessfully compiled under Unix, Mac OS X and Windows.

Be Sociable, Share!

PoDoFo-an open source library that parse PDF files and modify their contents into memory

What is PoDoFo?

PoDoFo is a library to work with the PDF file format. The name comes from the first letter of PDF (Portable Document Format). A few tools to work with PDF files are already included in the PoDoFo package.

The PoDoFo library is a free, portable C++ library which includes classes to parse PDF files and modify their contents into memory. The changes can be written back to disk easily. The parser can also be used to extract information from a PDF file (for example the parser could be used in a PDF viewer). Besides parsing PoDoFo includes also very simple classes to create your own PDF files. All classes are documented so it is easy to start writing your own application using PoDoFo.

PoDoFo is written in C++ and the code was sucessfully compiled under Unix, Mac OS X and Windows.

Included Tools

The PoDoFo tools are simple tools build around the PoDoFo library. These tools are first of all examples on how to use the PoDoFo library in your own
projects. But secondly they offer also features for working with PDF files. More tools will come with future release and the existing tools will gain more features.
Currently there are the following tools:

  • podofoimgextract extracts all jpeg images from a given PDF file
  • podofouncompress removes all compression filters from a PDF file, this is useful for debugging existing PDF files
  • podofopdfinfo provides some basic info about a PDF – metadata, page details, etc.
  • podofotxt2pdf converts a text file to a PDF

Additionally there is the external tool PoDoFoBrowser which is not included in this package, but can be downloaded from the PoDoFo webpage. PoDoFoBrowser is a Qt application for browsing the objects in a PDF file and modifying their keys easily. It is very useful if you want to look on the internal structure of PDF files. Please take a look at the screenshots of PoDoFoBrowser in our gallery.

Requirements

To build PoDoFo you need besides a working GNU toolchain and a C++ compiler the following libraries:

  • fontconfig (Unix only)
  • freetype2
  • zlib
  • cmake (only for building PoDoFo)
  • libjpeg (optional)

Licensing

The PoDoFo library is licensed under the LGPL (i.e. you may even use the shared library in closed sourced applications). The tests and tools which are included in PoDoFo are licensed under the GPL. See the files COPYING and COPYING.LIB for details.

Be Sociable, Share!