pd4ml 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pd4ml/__init__.py ADDED
@@ -0,0 +1,109 @@
1
+ """PD4ML for Python: HTML to PDF, PDF/A, DOCX, RTF and image conversion.
2
+
3
+ The public PD4ML API (package ``com.pd4ml``) runs in a Java virtual machine inside this
4
+ process (JPype). The JVM starts on first use with the PD4ML build from ``PD4ML_CLASSPATH`` /
5
+ ``PD4ML_CLASSPATH_FILE``, else the one :func:`install` downloaded (with none, the first use
6
+ downloads the most recent PD4ML release); or call :func:`start` first::
7
+
8
+ import pd4ml
9
+
10
+ pd = pd4ml.PD4ML() # the v42 layout engine
11
+ pd.setPageSize(pd4ml.PageSize.A4)
12
+ pd.readHTML("https://pd4ml.com")
13
+ pdf = pd.writePDF() # bytes
14
+
15
+ The Java classes are available under their own names (``PageSize``, ``PageMargins``,
16
+ ``PdfSpec``, ``Constants`` and its ``LayoutEngine``/``ErrorPolicy`` enums...); :class:`PD4ML`
17
+ wraps ``com.pd4ml.PD4ML`` and adds Python I/O. Java exceptions are raised as Python
18
+ exceptions and can be caught as the exported exception classes (``InvokeException``...).
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ from typing import Any
24
+
25
+ from ._api import (
26
+ DEFAULT_ENGINE,
27
+ PD4ML,
28
+ has_layout_engines,
29
+ html_to_pdf,
30
+ merge_pdfs,
31
+ open_pdf,
32
+ pdf_spec,
33
+ progress_listener,
34
+ to_input_stream,
35
+ to_url,
36
+ write_pdf,
37
+ )
38
+ from ._jvm import ClasspathError, configured_classpath, is_started, java_class, start
39
+ from ._install import InstallError, install, installed_classpath, installed_jar, installed_version
40
+
41
+ __version__ = "4.2.0.dev0"
42
+
43
+ #: Java classes of the public API, loaded on first access (which starts the JVM).
44
+ _JAVA_CLASSES = {
45
+ "JPD4ML": "com.pd4ml.PD4ML",
46
+ "Constants": "com.pd4ml.Constants",
47
+ "LayoutEngine": "com.pd4ml.Constants$LayoutEngine",
48
+ "ErrorPolicy": "com.pd4ml.Constants$ErrorPolicy",
49
+ "PageSize": "com.pd4ml.PageSize",
50
+ "PageMargins": "com.pd4ml.PageMargins",
51
+ "Dimensions": "com.pd4ml.Dimensions",
52
+ "Units": "com.pd4ml.Dimensions$Units",
53
+ "PdfDocument": "com.pd4ml.PdfDocument",
54
+ "PdfSpec": "com.pd4ml.PdfSpec",
55
+ "PdfSpecViolationException": "com.pd4ml.PdfSpec$PdfSpecViolationException",
56
+ "PdfSpecUnsupportedException": "com.pd4ml.PdfSpec$PdfSpecUnsupportedException",
57
+ "ProgressListener": "com.pd4ml.ProgressListener",
58
+ "ResourceProvider": "com.pd4ml.ResourceProvider",
59
+ "CustomTag": "com.pd4ml.CustomTag",
60
+ "StatusMessage": "com.pd4ml.StatusMessage",
61
+ "ConflictingParametersException": "com.pd4ml.ConflictingParametersException",
62
+ "ForcedTerminationException": "com.pd4ml.ForcedTerminationException",
63
+ "InvalidPasswordException": "com.pd4ml.InvalidPasswordException",
64
+ "InvokeException": "com.pd4ml.InvokeException",
65
+ }
66
+
67
+ __all__ = [
68
+ "PD4ML",
69
+ "DEFAULT_ENGINE",
70
+ "start",
71
+ "is_started",
72
+ "configured_classpath",
73
+ "java_class",
74
+ "ClasspathError",
75
+ "install",
76
+ "installed_jar",
77
+ "installed_classpath",
78
+ "installed_version",
79
+ "InstallError",
80
+ "has_layout_engines",
81
+ "html_to_pdf",
82
+ "open_pdf",
83
+ "write_pdf",
84
+ "merge_pdfs",
85
+ "pdf_spec",
86
+ "progress_listener",
87
+ "to_input_stream",
88
+ "to_url",
89
+ "version",
90
+ *_JAVA_CLASSES,
91
+ ]
92
+
93
+
94
+ def __getattr__(name: str) -> Any:
95
+ qualified = _JAVA_CLASSES.get(name)
96
+ if qualified is None:
97
+ raise AttributeError(f"module 'pd4ml' has no attribute {name!r}")
98
+ cls = java_class(qualified)
99
+ globals()[name] = cls
100
+ return cls
101
+
102
+
103
+ def __dir__():
104
+ return sorted(set(globals()) | set(_JAVA_CLASSES))
105
+
106
+
107
+ def version() -> str:
108
+ """The PD4ML (Java) version."""
109
+ return str(java_class("com.pd4ml.PD4ML").getVersion())