-
Notifications
You must be signed in to change notification settings - Fork 496
Windows Binaries Generation
This a "How To" install PyMuPDF and MuPDF using Visual Studio.
I am using this procedure to create the binary setup files for PyMuPDF.
Download MuPDF 1.9
As described in the installation chapter of PyMuPDF. Currently (as of May 10th), only version 1.9a can be seen there. But under the archive directory earlier versions are available, too.
I then unzip mupdf-1.9-source.tar.gz
(I am using 7zip) until I get a folder named mupdf-1.9-source
. Inside this folder, look for directory platform/win32
.
Double click on mupdf.sln
in this folder to open it with Visual Studio. The Visual Studio version I am using is VS Community 2013 (version 2015 should work too, but you need to use the platform toolset Visual Studio 2013 (v120) in it to compile MuPDF).
VS will automatically upgrade the solution and all 13 project files to version 12.0 (they come with version 8.0).
Now we need to decide whether we generate for x86 or x64 bitness. Let us assume x86. Start Configuration Manager
in the BUILD
menu and set Active solution configuration
to Release
and Active solution platform
to Win32
. Verify that all check boxes in the Build
column are checked. Close configuration manager.
Now update the VC++ directories for all projects using their Property Pages
. You need a Windows SDK
to successfully proceed. For my Windows 10, I am using Windows 10 SDK.
For every project, prefix the following 3 directories with the respective SDK directory (using my configuration example - it will be a little different names for Windows 7 and 8):
-
Executable Directories:
C:\Program Files (x86)\Windows Kits\10\bin\x86; ...
-
Include Directories:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\shared; ...
-
Library Directories:
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86; ...
Now generate the solution. In this process, the project generated
will create .exe
files and execute them. This may irritate your antivirus program, so you may consider to temporarily deactivate it.
If all worked well you will find the required library files libfonts.lib
, libmupdf.lib
and libthirdparty.lib
(and many more!) in directory ...\platform\win32\Release
.
If you use these library files as described so far, your PyMuPDF binary will be a quite large animal of 17+ MB (!). This is because MuPDF 1.9 includes support for many, many dozens of fonts from all over the world. If you do not need that or do not like that (I don't), you can reduce their number like so:
-
edit file
fitz.h
in directorymupdf-1.9-source/include/mupdf
-
insert 2 lines as follows
#ifndef MUDPF_FITZ_H
#define MUDPF_FITZ_H
#define NOTO_SMALL /* use a NOTO fonts subset only */
#define TOFU_CJK /* exclude Android specific fonts */
...
-
save and rebuild the solution as described above. Your PyMuPDF binary will now become around 8 MB large. However, the
*.lib
file sizes will not have changed.
First check that all your include and library directory specs are in order in your setup.py
file. Either copy the *.lib
files from above into the a directory named in setup.py
or change the script.
Second, make sure that your Python version uses the same compiler / linker version as the one used in Visual Studio.
Now generate by invoking python setup.py install
.
Done.
A common problem is error: Unable to find vcvarsall.bat
. An easy fix is using the following python++.bat
file:
PUSHD "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC"
call vcvarsall.bat x86
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
POPD
python %*
Then do your setup with the command python++ setup.py install
.
Another option to reduce the binary's _fitz.pyd
file size is using UPX. This can be done like so:
python++ setup.py build
pushd "...\build\lib.win32-2.7\fitz"
upx -9 *.pyd
popd
python setup.py install
This will cause the setup files to be only created / compiled (Python 2.7 used as an example) at first. Then a compress is performed and the result finally copied to the Python site-packages
directory.
UPX will compress _fitz.pyd
by more than 50%, currently yielding a file size of about 4 MB if combined with the recommended limited font support above.
HOWTO Button annots with JavaScript
HOWTO work with PDF embedded files
HOWTO extract text from inside rectangles
HOWTO extract text in natural reading order
HOWTO create or extract graphics
HOWTO create your own PDF Drawing
Rectangle inclusion & intersection
Metadata & bookmark maintenance