Awesome
Sharp MuPDF
Sharp MuPDF demonstrates how to compile MuPDF source code into a dynamic link library and consume its functionality in .NET.
Compile
To compile the source code.
-
Install Visual Studio 2019 or newer versions.
-
Install python 3 (
Python.exe
must be accessible via the PATH environment variable). -
Open the
MuPDF.sln
in the solution folder with Visual Studio. -
Compile the solution.
-
During compilation, Python will be called to generate the definition file for the target dll file.
-
Results:
MuPDFLib
project will produce two DLL files for mupdf, one for x86 and the other for x64.Demo
project contains some code to demonstrate how to use functions in MuPDFLib.dll
System font loading
In order to support loading system fonts for documents with unembedded fonts and avoid the performance lost across DLL files, a code file named mupdf_load_system_font.c
shall be compiled with the libmupdf
project.
We have to modify that project and reference the code file from MuPDFLib\Document\mupdf_load_system_font.c
.
That code file is copied from project SumatraPDF and all credits goes to them.
Shrinking MuPDFLib.dll
Open the property page for the libmupdf
project.
Add ;TOFU;TOFU_CJK_EXT
to C/C++/Preprocessor/Preprocessor Definitions for All Configurations and All Platforms in configuration manager.
So you can exclude several huge fonts from the DLL.
For more information, see config.h
file within the !include/fitz
folder in libmupdf
project.
.NET assembly reference of MuPDFLib.dll
From version 2.* on, it is possible to reference MuPDFLib.dll as a .NET assembly, since it is compiled with C++/CLI.
If you redistribute the MuPDFLib.dll which is referenced as a .NET assembly in your application, your users may encounter a problem that the MuPDFLib.dll could not be loaded.
To fix the problem, enclose the Visual C++ Runtime library files with your redistribution. At least, vcruntime140.dll
and msvcp140.dll
are the minimum set of required DLL files.
Update source code
-
Use
git pull
command to update the repository. -
To update source code, tags and submodules, use:
cd mupdf git pull origin master --recurse-submodules
It is possible that local modifications have been made. To discard local modifications when updating submodules, use the following command before
pull
ing from master:git reset --hard --recurse-submodules origin/master git reset --hard --recurse-submodules <TAG>
To fetch remote tags, use:
git fetch origin --tags
Afterwards, it is possible to check out the newly added tags:
git checkout <TAG>
Alternatively, we can also execute the following commands against each changed files:
git reset HEAD <file name> git checkout -- <file name>
We may see the following warning when we
pull
from master:error: You have not concluded your merge (MERGE_HEAD exists). hint: Please, commit your changes before merging. fatal: Exiting because of unfinished merge.
To fix this, run the following commands:
git fetch --all git reset --hard origin/master
Afterwards, we can
pull
from master then. -
The first a few lines in the
name-table.h
file have slight modifications from the original one in thelibmupdf
project, for the sake of making field names valid in .NET. Check whether it is changed and make the corresponding synchronization. To facilitate this operation, run thesync_name_table.py
script within theMuPDFLib
project folder.
Git Proxy
If accessing the Internet requires HTTPS proxy, use the following command:
git config --global http.proxy <PROXY:PORT>
git config --global https.proxy <PROXY:PORT>
When you are done, use the following command to reset the proxy to default:
git config --global --unset http.proxy
git config --global --unset https.proxy
License
This project follows the license terms of MuPDF.