Skip to content

Commit e5463f0

Browse files
pdf2htmlEX stopped shipping the C++ library, I wonder why? Build it locally. Use the latest pdf2htmlEX version from ODR
1 parent 7d8562e commit e5463f0

File tree

12 files changed

+1222
-1
lines changed

12 files changed

+1222
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sources:
2+
"0.18.8.rc1-git-eb5d291-library":
3+
url: "https://github.com/opendocument-app/pdf2htmlEX/archive/refs/tags/v0.18.8.rc1-odr-git-eb5d291.tar.gz"
4+
sha256: "530de80cebd3427c9d075c2c5567ba3c7ef1f25ca6a926dcb0d63ce562ce230c"
5+
patches:
6+
"0.18.8.rc1-git-eb5d291-library":
7+
- patch_file: "patches/0.18.8.rc1-git-eb5d291-library/0001-library.patch"
8+
- patch_file: "patches/0.18.8.rc1-git-eb5d291-library/0002-use-find_package.patch"
9+
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import os
2+
import stat
3+
4+
from conan import ConanFile
5+
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
6+
from conan.tools.env import Environment
7+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
8+
from conan.errors import ConanInvalidConfiguration
9+
10+
required_conan_version = ">=2.0.6"
11+
12+
13+
class pdf2htmlEXConan(ConanFile):
14+
name = "pdf2htmlex"
15+
package_type = "library"
16+
17+
license = ["GPLv3-or-later", "MIT", "CC-BY-3.0"]
18+
homepage = "https://github.com/pdf2htmlEX/pdf2htmlEX"
19+
url = "https://github.com/opendocument-app/pdf2htmlEX-Android"
20+
description = "Convert PDF to HTML without losing text or format. "
21+
topics = ("PDF", "HTML", "pdf-document-processor", "pdf-viewer")
22+
23+
# Binary configuration
24+
settings = "os", "compiler", "build_type", "arch"
25+
options = {"shared": [True, False], "fPIC": [True, False]}
26+
default_options = {"shared": False, "fPIC": True}
27+
28+
def config_options(self):
29+
if self.settings.os == "Windows":
30+
self.options.rm_safe("fPIC")
31+
32+
def configure(self):
33+
if self.options.shared:
34+
self.options.rm_safe("fPIC")
35+
36+
def validate(self):
37+
if not self.dependencies["poppler"].options.with_cairo:
38+
raise ConanInvalidConfiguration('Dependency "poppler" needs to be built with "with_cairo" option')
39+
if not self.dependencies["poppler"].options.with_glib:
40+
raise ConanInvalidConfiguration('Dependency "poppler" needs to be built with "with_glib" option')
41+
if self.dependencies["poppler"].options.shared:
42+
raise ConanInvalidConfiguration('Dependency "poppler" needs to be built as a static library (shared=False)')
43+
if not self.dependencies["fontforge"].options.install_private_headers:
44+
raise ConanInvalidConfiguration(
45+
'Dependency "fontforge" needs to be built with "install_private_headers" option')
46+
47+
def requirements(self):
48+
self.requires("poppler/24.08.0-odr", options={
49+
"with_cairo": True,
50+
"with_glib": True,
51+
"shared": False,
52+
"fontconfiguration": "fontconfig",
53+
}, transitive_headers=True, transitive_libs=True)
54+
self.requires("cairo/1.18.0-odr", options={
55+
# Don't pull in xorg dependencies.
56+
"with_xlib": False,
57+
"with_xlib_xrender": False,
58+
"with_xcb": False,
59+
}, transitive_headers=True, transitive_libs=True)
60+
self.requires("freetype/2.14.1")
61+
self.requires("fontforge/20240423-git", options={
62+
"install_private_headers": True,
63+
})
64+
65+
self.requires("glib/2.81.0-odr")
66+
67+
# self.requires("libtiff/4.6.0")
68+
# # jbig and libdeflate are required by libtiff
69+
# # Conan auto finds them, but linker doesn't, unless they're added here manually
70+
# self.requires("jbig/20160605")
71+
# self.requires("libdeflate/1.20")
72+
# self.requires("libiconv/1.17")
73+
# self.requires("giflib/5.2.2")
74+
75+
def layout(self):
76+
cmake_layout(self, src_folder="src")
77+
78+
def export_sources(self):
79+
export_conandata_patches(self)
80+
81+
def source(self):
82+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
83+
apply_conandata_patches(self)
84+
85+
# @TODO: use build_tools for closure compiler and yuicompressor
86+
for executable in ["build_css.sh", "build_js.sh"]:
87+
exe = os.path.join(self.source_folder, "pdf2htmlEX", "share", executable)
88+
os.chmod(exe, os.stat(exe).st_mode | stat.S_IEXEC)
89+
90+
def generate(self):
91+
deps = CMakeDeps(self)
92+
deps.generate()
93+
tc = CMakeToolchain(self)
94+
tc.extra_cxxflags = ["-Wno-maybe-uninitialized"]
95+
tc.variables["PDF2HTMLEX_VERSION"] = self.version
96+
tc.cache_variables["CMAKE_POLICY_VERSION_MINIMUM"] = "3.5" # CMake 4 support
97+
98+
# Get runenv info, exported by package_info() of dependencies
99+
# We need to obtain POPPLER_DATA_DIR and FONTCONFIG_PATH
100+
runenv_info = Environment()
101+
deps = self.dependencies.host.topological_sort
102+
deps = [dep for dep in reversed(deps.values())]
103+
for dep in deps:
104+
runenv_info.compose_env(dep.runenv_info)
105+
envvars = runenv_info.vars(self)
106+
for v in ["POPPLER_DATA_DIR", "FONTCONFIG_PATH"]:
107+
tc.variables[v] = envvars.get(v)
108+
# @TODO: figure out how to use POPPLER_DATA_DIR exported by poppler-data. It should JustWork^tm
109+
tc.generate()
110+
111+
def build(self):
112+
cmake = CMake(self)
113+
cmake.configure(build_script_folder="pdf2htmlEX")
114+
cmake.build()
115+
116+
def package(self):
117+
licensedir = os.path.join(self.package_folder, "licenses")
118+
copy(self, "LICENSE*", src=self.source_folder, dst=licensedir)
119+
copy(self, "LICENSE", src=os.path.join(self.source_folder, "pdf2htmlEX", "share"),
120+
dst=os.path.join(licensedir, "share"))
121+
copy(self, "LICENSE*", src=os.path.join(self.source_folder, "pdf2htmlEX", "logo"),
122+
dst=os.path.join(licensedir, "logo"))
123+
124+
copy(
125+
self,
126+
"*.h",
127+
src=os.path.join(self.source_folder, "pdf2htmlEX", "src"),
128+
dst=os.path.join(self.package_folder, "include", "pdf2htmlEX"),
129+
)
130+
131+
cmake = CMake(self)
132+
cmake.install()
133+
134+
rmdir(self, os.path.join(self.package_folder, "share", "man"))
135+
136+
def package_info(self):
137+
self.cpp_info.libs = ["pdf2htmlEX"]
138+
self.cpp_info.includedirs = ["include", "include/pdf2htmlEX"]
139+
self.cpp_info.resdirs = ["share/pdf2htmlEX"]
140+
141+
pdf2htmlEX_data_dir = os.path.join(self.package_folder, "share", "pdf2htmlEX")
142+
self.runenv_info.define_path("PDF2HTMLEX_DATA_DIR", pdf2htmlEX_data_dir)

0 commit comments

Comments
 (0)