Monday, July 14, 2014

Compiling swftools on Windows

Compiling swftools on Windows...

1. Download swftools-master.zip

2. Download mingw-get-setup.exe from www.mingw.org, run it and install base, msys & c++ to C:\MINGW

3. Download from http://gnuwin32.sourceforge.net/packages.html and install to C:\MINGW\GNUWIN32:
bison-2.4.1-setup.exe
flex-2.5.4a-1.exe
freetype-2.3.5-1-setup.exe
gettext-0.14.4.exe
giflib-4.1.4-1.exe
jpeg-6b-4.exe
libgw32c-0.4.exe
libiconv-1.9.2-1.exe
libpng-1.2.37-setup.exe
pdflib-lite-6.0.2.exe
t1lib-5.1.0.exe
yasm-1.1.0-win32.exe
zlib-1.2.3.exe

4. Download and compile lame

5. Download  fontconfig-2.2.2-20040412.zip,   fontconfig-dev-2.2.2-20040412.zip
    and extract to c:\mingw\fontconfig

6. Create C:\MinGW\msys\1.0\etc\fstab and put the following lines in:
c:\mingw /mingw
c:\mingw\gnuwin32 /gw32
c:\mingw\fontconfig /fc

7. Extract swftools to C:\MinGW\msys\1.0\home\

8. Run msys
cd ..
cd swftools
.\configure
make

8. If gcc complains about ..
- #define boolean int  in config.h -- just comment out that line
- not found -- copy lib\pdf\aconf.h to lib\pdf\xpdf directory and edit the line 
   #include "../../config.h" in xpdf\aconf.h into #include "../../../config.h"
- "cmyk.h" not found -- edit GfxState.cc and change "cmyk.h" to "../cmyk.h"
extern "C" int unlink(char *filename); definition conflict in stream.cc -- comment out that line

9. To compile gfx2gfx (exampel usage: gfx2gfx infile.swf -o outfile.pdf)
- edit swftools\src\gfx2gfx.c and insert the line       out->setparameter(out, "maxdpi", "0");
   below the line           gfxdevice_pdf_init(out);
- edit swftools\src\makefile and append gfx2gfx$(E) to the end of the line
   programs = $(install_programs) swfbytes$(E) ttftool$(E)
- run make again

note: pdf2pdf also accepts swf input and sends to pdf output

References: 
http://lists.gnu.org/archive/html/swftools-common/2005-02/msg00023.html
http://sudofixit.blogspot.com/2014/02/guide-convert-book-style-swfs-to-pdfs.html
http://go.kblog.us/2009/08/mingw-to-compile-lame-for-windows.html

Other:
If you want to build pdflib lite, and get
1) DWORD errors: add to pc_util.c
    typedef unsigned int DWORD;
2) png dereferencing errors: change #include "png.h" in p_image.h to
   #include "..\png\png.h"
(this error is caused by gcc reading a different (newer) version of libpng that may be installed elsewhere)
and similarly search and replace #include "tiffio.h" to #include "..\tiff\tiffio.h"
and #include "zlib.h" to #include "..\flate\zlib.h"