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"

16 comments:

  1. hi, thank you for your detailed instructions.
    After having followed them to the letter and stumbling over numerous errors, I've given up - wasted 2 days trying to compile swftools to obtain gfx2gfx and the python 2.7 gfx module for Windows 7 x64. Tried it on a x86 Win XP VM and the result was the same.
    Could you please send me the gfx2gfx and python module over email, or make them available for download?

    cheers,
    joca

    ReplyDelete
    Replies
    1. Hi, links to the binaries:
      https://drive.google.com/file/d/0B62RcibHRlstZXR1dndIc1ZmTDA/edit?usp=sharing
      https://drive.google.com/file/d/0B62RcibHRlstVHJCMmFIbllwRmM/edit?usp=sharing
      https://drive.google.com/file/d/0B62RcibHRlstTXlPWnNWTS1uNEk/edit?usp=sharing

      Delete
  2. Hi, I'm still getting error "You need zlib to compile swftools" while running ".\configure" but I installed "zlib-1.2.3.exe". What am I doing wrong? Thanks for your answer!

    ReplyDelete
  3. try copy zlib.h and zconf.h to your msys\1.0\local\include directory, and copy libz.a to your msys\1.0\local\lib directory.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  4. Hi Tony, thanks, it worked! However I'm still getting another errors and when I solve one I get another... Could you please compile and post "gfx2gfx" with "out->setparameter(out, "maxdpi", "600")" and without dependencies to dlls? I already spent lot of days trying to compile it and would really appreciate it! Cheers!

    ReplyDelete
  5. Hi gfx2gfx with maxdpi 600 and without dependencies:
    https://drive.google.com/file/d/0B62RcibHRlstdV9yTFZERFNZdE0/view?usp=sharing

    ReplyDelete
    Replies
    1. Man, thank you so much, you're amazing! Greetings from Switzerland!

      Delete
    2. Just for knowing what I do wrong - here is the error what I get when trying to run make in swftools/src (for compiling gfx2gfx): https://drive.google.com/file/d/0B0-EMLg7y1qaSkQwUno1VG9nbmM/view?usp=sharing

      It seems like libgfxpdf.lib is missing and I can't find it anywhere...

      Cheers!

      Delete
    3. static library files in MinGW has .a extension, whereas static library files in Visual C++ uses .lib files.
      .lib files may be incompatible with G++

      This is the command that my make runs:

      g++ -DHAVE_CONFIG_H gfx2gfx.o -o gfx2gfx.exe ../lib/libgfxswf.a ../lib/librfxswf.a ../lib/libgfxpdf.a ../lib/libgfx.a ../lib/libbase.a -s -L/usr/local/lib -L/c/mingw/lib -L/usr/local/lib -lgif -ljpeg -lpdf -lz -lm -lws2_32 -lgdi32 -L/usr/local/lib -lfreetype -lz

      Delete
    4. Also to build static binaries without dll dependencies, I've used TDM-GCC's C++ instead of the MinGW's C++
      The build I posted earlier in Aug 2014 was built using MinGW's C++ so I had to include dll's.

      Delete
  6. Oh, if you get a code page error, set your Windows setting for Language for Non-unicode programs to English (United States). I think this is a limitation of pdflite and there is nothing I can do about it.

    ReplyDelete
  7. hello...How to import newer xpdf v3,04 pdf parser into pdf2swf 0.9.2? Please help. I am not programmer but use this tool. In 0.9.2 is old xpdf v3.02 which have problems with newer pdf versions. thanks

    ReplyDelete
  8. Hi Tony, I tried to compile, but got error:

    ../config.h:193:17: error: two or more data types in declaration specifiers
    #define boolean int
    ^
    os.c: In function 'getRegistryEntry':
    os.c:80:2: warning: format '%d' expects argument of type 'int', but argument 3 h
    as type 'long int' [-Wformat=]
    fprintf(stderr, "RegQueryValueEx(1) failed: %d\n", rc);
    ^
    os.c:86:2: warning: format '%d' expects argument of type 'int', but argument 3 h
    as type 'long int' [-Wformat=]
    fprintf(stderr, "RegQueryValueEx(2) failed: %d\n", rc);
    ^
    os.c: In function 'open_file_or_stdin':
    os.c:351:9: warning: implicit declaration of function 'open' [-Wimplicit-functio
    n-declaration]
    f = open(filename, attr);
    ^
    make[1]: *** [os.obj] Error 1
    make[1]: Leaving directory `/home/swftools/lib'
    make: *** [all] Error 2

    Can you help me please?

    ReplyDelete
  9. Hi tony,
    Could you please compile for gfx2gfx with maxdpi 300 and without dependencies?

    ReplyDelete