folio-pdf 0.0.0__tar.gz
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.
- folio_pdf-0.0.0/PKG-INFO +28 -0
- folio_pdf-0.0.0/README.md +19 -0
- folio_pdf-0.0.0/pyproject.toml +14 -0
- folio_pdf-0.0.0/src/folio_pdf/__init__.py +67 -0
- folio_pdf-0.0.0/src/folio_pdf/core.py +34 -0
- folio_pdf-0.0.0/src/folio_pdf/document.py +69 -0
- folio_pdf-0.0.0/src/folio_pdf/enums.py +11 -0
- folio_pdf-0.0.0/src/folio_pdf/exceptions.py +1 -0
- folio_pdf-0.0.0/src/folio_pdf/libs/folio-windows-x86_64.dll +0 -0
- folio_pdf-0.0.0/src/folio_pdf/libs/folio.h +754 -0
- folio_pdf-0.0.0/src/folio_pdf/libs/libfolio-linux-aarch64.so +0 -0
- folio_pdf-0.0.0/src/folio_pdf/libs/libfolio-linux-x86_64.so +0 -0
- folio_pdf-0.0.0/src/folio_pdf/libs/libfolio-macos-aarch64.dylib +0 -0
- folio_pdf-0.0.0/src/folio_pdf/libs/libfolio-macos-x86_64.dylib +0 -0
- folio_pdf-0.0.0/src/folio_pdf/py.typed +0 -0
folio_pdf-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: folio-pdf
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: A PDF library for Python powered by bindings to github.com/carlos7ags/folio in GO
|
|
5
|
+
Author: Gbenga Adeyi
|
|
6
|
+
Author-email: Gbenga Adeyi <adeyigbenga005@gmail.com>
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# Folio PDF
|
|
11
|
+
|
|
12
|
+
A PDF library for Python powered by bindings to [https://github.com/carlos7ags/folio](https://github.com/carlos7ags/folio) PDF library for Go: layout engine, HTML to PDF, forms, signatures, barcodes, and PDF/A.
|
|
13
|
+
|
|
14
|
+
Folio PDF only currently supports the following functions `html_to_pdf`, `html_to_buffer` & `parse_css_length` and is still in development.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
```python
|
|
21
|
+
from folio_pdf import html_to_pdf
|
|
22
|
+
|
|
23
|
+
html = '''
|
|
24
|
+
<h1 style="color: red;">Hello, world!</h1>
|
|
25
|
+
'''
|
|
26
|
+
html_to_pdf(html, "result.pdf")
|
|
27
|
+
# see generated result.pdf the generated pdf
|
|
28
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Folio PDF
|
|
2
|
+
|
|
3
|
+
A PDF library for Python powered by bindings to [https://github.com/carlos7ags/folio](https://github.com/carlos7ags/folio) PDF library for Go: layout engine, HTML to PDF, forms, signatures, barcodes, and PDF/A.
|
|
4
|
+
|
|
5
|
+
Folio PDF only currently supports the following functions `html_to_pdf`, `html_to_buffer` & `parse_css_length` and is still in development.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
```python
|
|
12
|
+
from folio_pdf import html_to_pdf
|
|
13
|
+
|
|
14
|
+
html = '''
|
|
15
|
+
<h1 style="color: red;">Hello, world!</h1>
|
|
16
|
+
'''
|
|
17
|
+
html_to_pdf(html, "result.pdf")
|
|
18
|
+
# see generated result.pdf the generated pdf
|
|
19
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "folio-pdf"
|
|
3
|
+
version = "0.0.0"
|
|
4
|
+
description = "A PDF library for Python powered by bindings to github.com/carlos7ags/folio in GO"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Gbenga Adeyi", email = "adeyigbenga005@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["uv_build>=0.11.7,<0.12.0"]
|
|
14
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import ctypes.wintypes
|
|
2
|
+
from folio_pdf.document import Document
|
|
3
|
+
from io import BytesIO
|
|
4
|
+
from .core import lib
|
|
5
|
+
import ctypes
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
lib.folio_html_to_pdf.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
|
|
10
|
+
lib.folio_html_to_pdf.restype = ctypes.c_int32
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def html_to_pdf(html: str, destination: str | Path):
|
|
14
|
+
_destination = destination
|
|
15
|
+
if isinstance(_destination, Path):
|
|
16
|
+
_destination = _destination.as_posix()
|
|
17
|
+
if not _destination.endswith("pdf"):
|
|
18
|
+
_destination += ".pdf"
|
|
19
|
+
return lib.folio_html_to_pdf(
|
|
20
|
+
ctypes.c_char_p(html.encode()), ctypes.c_char_p(_destination.encode())
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
lib.folio_html_to_buffer.argtypes = [ctypes.c_char_p, ctypes.c_double, ctypes.c_double]
|
|
25
|
+
lib.folio_html_to_buffer.restype = ctypes.c_int64
|
|
26
|
+
|
|
27
|
+
lib.folio_buffer_data.restype = ctypes.c_void_p
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def html_to_buffer(html: str, page_width: float, page_height: float) -> BytesIO:
|
|
31
|
+
buf = lib.folio_html_to_buffer(
|
|
32
|
+
ctypes.c_char_p(html.encode()),
|
|
33
|
+
ctypes.c_double(page_width),
|
|
34
|
+
ctypes.c_double(page_height),
|
|
35
|
+
)
|
|
36
|
+
size = lib.folio_buffer_len(buf)
|
|
37
|
+
ptr = lib.folio_buffer_data(buf)
|
|
38
|
+
data = ctypes.string_at(ptr, size)
|
|
39
|
+
lib.folio_buffer_free(buf)
|
|
40
|
+
return BytesIO(data)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def html_convert(html: str, page_width: float, page_height: float) -> Document:
|
|
44
|
+
doc_ptr = lib.folio_html_convert(
|
|
45
|
+
ctypes.c_char_p(html.encode()),
|
|
46
|
+
ctypes.c_double(page_width),
|
|
47
|
+
ctypes.c_double(page_height),
|
|
48
|
+
)
|
|
49
|
+
return Document._new_from_ptr(doc_ptr)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
lib.folio_html_parse_css_length.argtypes = [
|
|
53
|
+
ctypes.c_char_p,
|
|
54
|
+
ctypes.c_double,
|
|
55
|
+
ctypes.c_double,
|
|
56
|
+
]
|
|
57
|
+
lib.folio_html_parse_css_length.restype = ctypes.c_double
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def html_parse_css_length(s: str, font_size: float, relative_to: float) -> float:
|
|
61
|
+
result: ctypes.c_double = lib.folio_html_parse_css_length(
|
|
62
|
+
ctypes.c_char_p(s.encode()),
|
|
63
|
+
ctypes.c_double(font_size),
|
|
64
|
+
ctypes.c_double(relative_to),
|
|
65
|
+
)
|
|
66
|
+
return result.value
|
|
67
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
import ctypes
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
THIS_FILE_PATH = Path(__file__).parent
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _load_lib() -> ctypes.CDLL:
|
|
9
|
+
operating_system = platform.system()
|
|
10
|
+
architecture = platform.machine()
|
|
11
|
+
if operating_system == "Windows" and architecture == "x86_64":
|
|
12
|
+
return ctypes.CDLL(THIS_FILE_PATH / "libs/folio-windows-x86_64.dll")
|
|
13
|
+
if operating_system == "Linux" and architecture == "x86_64":
|
|
14
|
+
return ctypes.CDLL(THIS_FILE_PATH / "libs/libfolio-linux-x86_64.so")
|
|
15
|
+
if operating_system == "Linux" and architecture == "aarch64":
|
|
16
|
+
return ctypes.CDLL(THIS_FILE_PATH / "libs/libfolio-linux-aarch64.so")
|
|
17
|
+
if operating_system == "Darwin" and architecture == "x86_64":
|
|
18
|
+
return ctypes.CDLL(THIS_FILE_PATH / "libs/libfolio-macos-x86_64.dylib")
|
|
19
|
+
if operating_system == "Darwin" and architecture == "aarch64":
|
|
20
|
+
return ctypes.CDLL(THIS_FILE_PATH / "libs/libfolio-macos-aarch64.dylib")
|
|
21
|
+
raise RuntimeError("OS or CPU architecture not supported")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
lib = _load_lib()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
lib.folio_buffer_data.argtypes = [ctypes.c_int64]
|
|
28
|
+
lib.folio_buffer_data.restype = ctypes.c_void_p
|
|
29
|
+
|
|
30
|
+
lib.folio_buffer_len.argtypes = [ctypes.c_int64]
|
|
31
|
+
lib.folio_buffer_len.restype = ctypes.c_int32
|
|
32
|
+
|
|
33
|
+
lib.folio_buffer_free.argtypes = [ctypes.c_int64]
|
|
34
|
+
lib.folio_buffer_free.restype = None
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Callable
|
|
3
|
+
from folio_pdf.exceptions import DocumentException
|
|
4
|
+
from folio_pdf.enums import ErrorCodes
|
|
5
|
+
from folio_pdf.core import lib
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _with_error_handling(func: Callable):
|
|
9
|
+
def wrapper(self, *args, **kwargs):
|
|
10
|
+
res_code = func(self, *args, **kwargs)
|
|
11
|
+
err = ErrorCodes(res_code)
|
|
12
|
+
if err != ErrorCodes.OK:
|
|
13
|
+
msg_bytes = lib.folio_last_error()
|
|
14
|
+
raise DocumentException(str(msg_bytes))
|
|
15
|
+
|
|
16
|
+
return wrapper
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Document:
|
|
20
|
+
def __init__(self, width: float, height: float):
|
|
21
|
+
self._doc_ptr = lib.folio_document_new(width, height)
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def new_a4(cls):
|
|
25
|
+
obj = cls.__new__(cls)
|
|
26
|
+
cls._doc_ptr = lib.folio_document_new_a4()
|
|
27
|
+
return obj
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def _new_from_ptr(cls, doc_ptr: int):
|
|
31
|
+
obj = cls.__new__(cls)
|
|
32
|
+
cls._doc_ptr = doc_ptr
|
|
33
|
+
return obj
|
|
34
|
+
|
|
35
|
+
@_with_error_handling
|
|
36
|
+
def set_title(self, value: str):
|
|
37
|
+
return lib.folio_document_set_title(self._doc_ptr, value)
|
|
38
|
+
|
|
39
|
+
@_with_error_handling
|
|
40
|
+
def set_author(self, value: str):
|
|
41
|
+
return lib.folio_document_author(self._doc_ptr, value)
|
|
42
|
+
|
|
43
|
+
@_with_error_handling
|
|
44
|
+
def set_margins(self, top: float, right: float, bottom: float, left: float):
|
|
45
|
+
return lib.folio_document_set_margins(self._doc_ptr, top, right, bottom, left)
|
|
46
|
+
|
|
47
|
+
def add_page(self):
|
|
48
|
+
# TODO: Return Page obj
|
|
49
|
+
lib.folio_document_add_page(self._doc_ptr)
|
|
50
|
+
|
|
51
|
+
@_with_error_handling
|
|
52
|
+
def add(self, element):
|
|
53
|
+
return lib.folio_document_add(self._doc_ptr, element)
|
|
54
|
+
|
|
55
|
+
@_with_error_handling
|
|
56
|
+
def save(self, destination: str | Path):
|
|
57
|
+
_destination = destination
|
|
58
|
+
if isinstance(_destination, Path):
|
|
59
|
+
_destination = _destination.as_posix()
|
|
60
|
+
return lib.folio_document_save(self._doc_ptr, _destination)
|
|
61
|
+
|
|
62
|
+
def close(self):
|
|
63
|
+
lib.folio_document_free(self._doc_ptr)
|
|
64
|
+
|
|
65
|
+
def __enter__(self):
|
|
66
|
+
return self
|
|
67
|
+
|
|
68
|
+
def __exit__(self):
|
|
69
|
+
self.close()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from enum import IntEnum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ErrorCodes(IntEnum):
|
|
5
|
+
OK = 0
|
|
6
|
+
ERR_HANDLE = -1 # invalid or expired handle
|
|
7
|
+
ERR_ARG = -2 # invalid argument (NULL, out of range)
|
|
8
|
+
ERR_IO = -3 # file I/O error
|
|
9
|
+
ERR_PDF = -4 # PDF generation/parsing error
|
|
10
|
+
ERR_TYPE = -5 # handle type mismatch
|
|
11
|
+
ERR_INTERNAL = -6 # unexpected internal error
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class DocumentException(Exception): ...
|
|
Binary file
|
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Folio C ABI — PDF generation library
|
|
3
|
+
* https://github.com/carlos7ags/folio
|
|
4
|
+
* Apache 2.0 License
|
|
5
|
+
*
|
|
6
|
+
* MEMORY OWNERSHIP RULES
|
|
7
|
+
* ----------------------
|
|
8
|
+
* 1. All objects are opaque uint64_t handles. The library owns the memory.
|
|
9
|
+
* Every folio_*_new() / folio_*_load() has a matching folio_*_free().
|
|
10
|
+
*
|
|
11
|
+
* 2. Strings passed TO the library (const char*) are copied immediately.
|
|
12
|
+
* The caller retains ownership and may free after the call returns.
|
|
13
|
+
*
|
|
14
|
+
* 3. Strings returned FROM the library:
|
|
15
|
+
* - folio_version(): persistent pointer, do NOT free.
|
|
16
|
+
* - folio_last_error(): library-owned, valid until the next C ABI call.
|
|
17
|
+
* - All other string data is returned as buffer handles (see below).
|
|
18
|
+
*
|
|
19
|
+
* 4. Buffer handles (folio_buffer_data / folio_buffer_len / folio_buffer_free):
|
|
20
|
+
* The library allocates the buffer; the caller MUST call folio_buffer_free()
|
|
21
|
+
* when done. The data pointer is valid until folio_buffer_free() is called.
|
|
22
|
+
*
|
|
23
|
+
* ERROR CONVENTION
|
|
24
|
+
* ----------------
|
|
25
|
+
* Functions returning int32_t: 0 = success, negative = error.
|
|
26
|
+
* Call folio_last_error() for the human-readable message.
|
|
27
|
+
*
|
|
28
|
+
* THREAD SAFETY
|
|
29
|
+
* -------------
|
|
30
|
+
* The library is NOT thread-safe. All calls must be serialized.
|
|
31
|
+
* A single-threaded wrapper is recommended for multi-threaded applications.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
#ifndef FOLIO_H
|
|
35
|
+
#define FOLIO_H
|
|
36
|
+
|
|
37
|
+
#include <stdint.h>
|
|
38
|
+
#include <stddef.h>
|
|
39
|
+
|
|
40
|
+
#ifdef __cplusplus
|
|
41
|
+
extern "C" {
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
/* ── Error codes ───────────────────────────────────────────────────── */
|
|
45
|
+
|
|
46
|
+
#define FOLIO_OK 0
|
|
47
|
+
#define FOLIO_ERR_HANDLE -1 /* invalid or expired handle */
|
|
48
|
+
#define FOLIO_ERR_ARG -2 /* invalid argument (NULL, out of range) */
|
|
49
|
+
#define FOLIO_ERR_IO -3 /* file I/O error */
|
|
50
|
+
#define FOLIO_ERR_PDF -4 /* PDF generation/parsing error */
|
|
51
|
+
#define FOLIO_ERR_TYPE -5 /* handle type mismatch */
|
|
52
|
+
#define FOLIO_ERR_INTERNAL -6 /* unexpected internal error */
|
|
53
|
+
|
|
54
|
+
/* ── Enums ─────────────────────────────────────────────────────────── */
|
|
55
|
+
|
|
56
|
+
/* Text alignment (layout.Align) */
|
|
57
|
+
#define FOLIO_ALIGN_LEFT 0
|
|
58
|
+
#define FOLIO_ALIGN_CENTER 1
|
|
59
|
+
#define FOLIO_ALIGN_RIGHT 2
|
|
60
|
+
#define FOLIO_ALIGN_JUSTIFY 3
|
|
61
|
+
|
|
62
|
+
/* Vertical alignment (layout.VAlign) */
|
|
63
|
+
#define FOLIO_VALIGN_TOP 0
|
|
64
|
+
#define FOLIO_VALIGN_MIDDLE 1
|
|
65
|
+
#define FOLIO_VALIGN_BOTTOM 2
|
|
66
|
+
|
|
67
|
+
/* Heading levels (layout.HeadingLevel) */
|
|
68
|
+
#define FOLIO_H1 1
|
|
69
|
+
#define FOLIO_H2 2
|
|
70
|
+
#define FOLIO_H3 3
|
|
71
|
+
#define FOLIO_H4 4
|
|
72
|
+
#define FOLIO_H5 5
|
|
73
|
+
#define FOLIO_H6 6
|
|
74
|
+
|
|
75
|
+
/* List styles (layout.ListStyle) */
|
|
76
|
+
#define FOLIO_LIST_BULLET 0
|
|
77
|
+
#define FOLIO_LIST_DECIMAL 1
|
|
78
|
+
#define FOLIO_LIST_LOWER_ALPHA 2
|
|
79
|
+
#define FOLIO_LIST_UPPER_ALPHA 3
|
|
80
|
+
#define FOLIO_LIST_LOWER_ROMAN 4
|
|
81
|
+
#define FOLIO_LIST_UPPER_ROMAN 5
|
|
82
|
+
|
|
83
|
+
/* PDF/A levels (document.PdfALevel) */
|
|
84
|
+
#define FOLIO_PDFA_2B 0
|
|
85
|
+
#define FOLIO_PDFA_2U 1
|
|
86
|
+
#define FOLIO_PDFA_2A 2
|
|
87
|
+
#define FOLIO_PDFA_3B 3
|
|
88
|
+
#define FOLIO_PDFA_1B 4
|
|
89
|
+
#define FOLIO_PDFA_1A 5
|
|
90
|
+
|
|
91
|
+
/* Encryption algorithms (document.EncryptionAlgorithm) */
|
|
92
|
+
#define FOLIO_ENCRYPT_RC4_128 0
|
|
93
|
+
#define FOLIO_ENCRYPT_AES_128 1
|
|
94
|
+
#define FOLIO_ENCRYPT_AES_256 2
|
|
95
|
+
|
|
96
|
+
/* Encryption permissions (ISO 32000 Table 22, combine with |) */
|
|
97
|
+
#define FOLIO_PERM_PRINT (1 << 2) /* bit 3: print */
|
|
98
|
+
#define FOLIO_PERM_MODIFY (1 << 3) /* bit 4: modify contents */
|
|
99
|
+
#define FOLIO_PERM_EXTRACT (1 << 4) /* bit 5: copy/extract text */
|
|
100
|
+
#define FOLIO_PERM_ANNOTATE (1 << 5) /* bit 6: annotations, fill forms */
|
|
101
|
+
#define FOLIO_PERM_FILL_FORMS (1 << 8) /* bit 9: fill form fields */
|
|
102
|
+
#define FOLIO_PERM_EXTRACT_ACCESS (1 << 9) /* bit 10: extract for accessibility */
|
|
103
|
+
#define FOLIO_PERM_ASSEMBLE (1 << 10) /* bit 11: insert/rotate/delete pages */
|
|
104
|
+
#define FOLIO_PERM_PRINT_HIGH (1 << 11) /* bit 12: high-quality print */
|
|
105
|
+
#define FOLIO_PERM_ALL 0x0F3C
|
|
106
|
+
|
|
107
|
+
/* QR error correction levels (barcode.ECCLevel) */
|
|
108
|
+
#define FOLIO_ECC_L 0 /* 7% recovery */
|
|
109
|
+
#define FOLIO_ECC_M 1 /* 15% recovery */
|
|
110
|
+
#define FOLIO_ECC_Q 2 /* 25% recovery */
|
|
111
|
+
#define FOLIO_ECC_H 3 /* 30% recovery */
|
|
112
|
+
|
|
113
|
+
/* Flex direction (layout.FlexDirection) */
|
|
114
|
+
#define FOLIO_FLEX_ROW 0
|
|
115
|
+
#define FOLIO_FLEX_COLUMN 1
|
|
116
|
+
|
|
117
|
+
/* Flex justify-content (layout.JustifyContent) */
|
|
118
|
+
#define FOLIO_JUSTIFY_START 0
|
|
119
|
+
#define FOLIO_JUSTIFY_END 1
|
|
120
|
+
#define FOLIO_JUSTIFY_CENTER 2
|
|
121
|
+
#define FOLIO_JUSTIFY_SPACE_BETWEEN 3
|
|
122
|
+
#define FOLIO_JUSTIFY_SPACE_AROUND 4
|
|
123
|
+
#define FOLIO_JUSTIFY_SPACE_EVENLY 5
|
|
124
|
+
|
|
125
|
+
/* Flex align-items / align-self (layout.AlignItems) */
|
|
126
|
+
#define FOLIO_CROSS_STRETCH 0
|
|
127
|
+
#define FOLIO_CROSS_START 1
|
|
128
|
+
#define FOLIO_CROSS_END 2
|
|
129
|
+
#define FOLIO_CROSS_CENTER 3
|
|
130
|
+
|
|
131
|
+
/* Flex wrap (layout.FlexWrap) */
|
|
132
|
+
#define FOLIO_FLEX_NOWRAP 0
|
|
133
|
+
#define FOLIO_FLEX_WRAP 1
|
|
134
|
+
|
|
135
|
+
/* ── Callback types ────────────────────────────────────────────────── */
|
|
136
|
+
|
|
137
|
+
/*
|
|
138
|
+
* Page decorator callback. Invoked for each page during rendering.
|
|
139
|
+
* page_handle is a temporary handle valid only inside the callback.
|
|
140
|
+
*/
|
|
141
|
+
typedef void (*folio_page_decorator_fn)(
|
|
142
|
+
int32_t page_index,
|
|
143
|
+
int32_t total_pages,
|
|
144
|
+
uint64_t page_handle,
|
|
145
|
+
void *user_data
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
/* ── Core ──────────────────────────────────────────────────────────── */
|
|
149
|
+
|
|
150
|
+
const char *folio_version(void);
|
|
151
|
+
const char *folio_last_error(void);
|
|
152
|
+
|
|
153
|
+
/* ── Buffer ────────────────────────────────────────────────────────── */
|
|
154
|
+
|
|
155
|
+
void *folio_buffer_data(uint64_t buf);
|
|
156
|
+
int32_t folio_buffer_len(uint64_t buf);
|
|
157
|
+
void folio_buffer_free(uint64_t buf);
|
|
158
|
+
|
|
159
|
+
/* ── Document ──────────────────────────────────────────────────────── */
|
|
160
|
+
|
|
161
|
+
uint64_t folio_document_new(double width, double height);
|
|
162
|
+
uint64_t folio_document_new_letter(void);
|
|
163
|
+
uint64_t folio_document_new_a4(void);
|
|
164
|
+
void folio_document_free(uint64_t doc);
|
|
165
|
+
|
|
166
|
+
int32_t folio_document_set_title(uint64_t doc, const char *title);
|
|
167
|
+
int32_t folio_document_set_author(uint64_t doc, const char *author);
|
|
168
|
+
int32_t folio_document_set_margins(uint64_t doc, double top, double right, double bottom, double left);
|
|
169
|
+
|
|
170
|
+
uint64_t folio_document_add_page(uint64_t doc);
|
|
171
|
+
int32_t folio_document_page_count(uint64_t doc);
|
|
172
|
+
int32_t folio_document_add(uint64_t doc, uint64_t element);
|
|
173
|
+
|
|
174
|
+
int32_t folio_document_save(uint64_t doc, const char *path);
|
|
175
|
+
uint64_t folio_document_write_to_buffer(uint64_t doc);
|
|
176
|
+
|
|
177
|
+
/* Document features */
|
|
178
|
+
int32_t folio_document_set_tagged(uint64_t doc, int32_t enabled);
|
|
179
|
+
int32_t folio_document_set_pdfa(uint64_t doc, int32_t level);
|
|
180
|
+
int32_t folio_document_set_encryption(uint64_t doc, const char *user_pw, const char *owner_pw, int32_t algorithm);
|
|
181
|
+
int32_t folio_document_set_encryption_with_permissions(uint64_t doc, const char *user_pw,
|
|
182
|
+
const char *owner_pw, int32_t algorithm, int32_t permissions); /* FOLIO_PERM_* */
|
|
183
|
+
|
|
184
|
+
/* Convenience: serialize document to a buffer handle (caller must folio_buffer_free). */
|
|
185
|
+
uint64_t folio_document_to_bytes(uint64_t doc);
|
|
186
|
+
int32_t folio_document_validate_pdfa(uint64_t doc);
|
|
187
|
+
int32_t folio_document_set_auto_bookmarks(uint64_t doc, int32_t enabled);
|
|
188
|
+
int32_t folio_document_set_form(uint64_t doc, uint64_t form);
|
|
189
|
+
|
|
190
|
+
/* Callbacks (low-level, absolute positioning) */
|
|
191
|
+
int32_t folio_document_set_header(uint64_t doc, folio_page_decorator_fn fn, void *user_data);
|
|
192
|
+
int32_t folio_document_set_footer(uint64_t doc, folio_page_decorator_fn fn, void *user_data);
|
|
193
|
+
|
|
194
|
+
/* Header/footer text (high-level, auto space reservation) */
|
|
195
|
+
/* align: 0=left, 1=center, 2=right. Text may contain {page} and {pages}. */
|
|
196
|
+
int32_t folio_document_set_header_text(uint64_t doc, const char *text, uint64_t font,
|
|
197
|
+
double size, int32_t align);
|
|
198
|
+
int32_t folio_document_set_footer_text(uint64_t doc, const char *text, uint64_t font,
|
|
199
|
+
double size, int32_t align);
|
|
200
|
+
|
|
201
|
+
/* Watermark */
|
|
202
|
+
int32_t folio_document_set_watermark(uint64_t doc, const char *text);
|
|
203
|
+
int32_t folio_document_set_watermark_config(uint64_t doc, const char *text,
|
|
204
|
+
double font_size, double color_r, double color_g, double color_b,
|
|
205
|
+
double angle, double opacity);
|
|
206
|
+
|
|
207
|
+
/* Outlines / Bookmarks */
|
|
208
|
+
uint64_t folio_document_add_outline(uint64_t doc, const char *title, int32_t page_index);
|
|
209
|
+
uint64_t folio_document_add_outline_xyz(uint64_t doc, const char *title,
|
|
210
|
+
int32_t page_index, double left, double top, double zoom);
|
|
211
|
+
uint64_t folio_outline_add_child(uint64_t outline, const char *title, int32_t page_index);
|
|
212
|
+
uint64_t folio_outline_add_child_xyz(uint64_t outline, const char *title,
|
|
213
|
+
int32_t page_index, double left, double top, double zoom);
|
|
214
|
+
|
|
215
|
+
/* Named Destinations */
|
|
216
|
+
int32_t folio_document_add_named_dest(uint64_t doc, const char *name, int32_t page_index,
|
|
217
|
+
const char *fit_type, double top, double left, double zoom);
|
|
218
|
+
|
|
219
|
+
/* Viewer Preferences */
|
|
220
|
+
int32_t folio_document_set_viewer_preferences(uint64_t doc,
|
|
221
|
+
const char *page_layout, const char *page_mode,
|
|
222
|
+
int32_t hide_toolbar, int32_t hide_menubar, int32_t hide_window_ui,
|
|
223
|
+
int32_t fit_window, int32_t center_window, int32_t display_doc_title);
|
|
224
|
+
|
|
225
|
+
/* Page Labels */
|
|
226
|
+
int32_t folio_document_add_page_label(uint64_t doc, int32_t page_index,
|
|
227
|
+
const char *style, const char *prefix, int32_t start);
|
|
228
|
+
|
|
229
|
+
/* Page management */
|
|
230
|
+
int32_t folio_document_remove_page(uint64_t doc, int32_t index);
|
|
231
|
+
|
|
232
|
+
/* Absolute positioning */
|
|
233
|
+
int32_t folio_document_add_absolute(uint64_t doc, uint64_t element, double x, double y, double width);
|
|
234
|
+
|
|
235
|
+
/* File attachments (PDF/A-3b) */
|
|
236
|
+
int32_t folio_document_attach_file(uint64_t doc, const void *data, int32_t length,
|
|
237
|
+
const char *file_name, const char *mime_type, const char *description, const char *af_relationship);
|
|
238
|
+
|
|
239
|
+
/* Inline HTML */
|
|
240
|
+
int32_t folio_document_add_html(uint64_t doc, const char *html);
|
|
241
|
+
int32_t folio_document_add_html_with_options(uint64_t doc, const char *html,
|
|
242
|
+
double default_font_size, double page_width, double page_height,
|
|
243
|
+
const char *base_path, const char *fallback_font_path);
|
|
244
|
+
|
|
245
|
+
/* Page-specific margins (@page :first/:left/:right) */
|
|
246
|
+
int32_t folio_document_set_first_margins(uint64_t doc, double top, double right, double bottom, double left);
|
|
247
|
+
int32_t folio_document_set_left_margins(uint64_t doc, double top, double right, double bottom, double left);
|
|
248
|
+
int32_t folio_document_set_right_margins(uint64_t doc, double top, double right, double bottom, double left);
|
|
249
|
+
|
|
250
|
+
/* ── Page ──────────────────────────────────────────────────────────── */
|
|
251
|
+
|
|
252
|
+
int32_t folio_page_add_text(uint64_t page, const char *text, uint64_t font, double size, double x, double y);
|
|
253
|
+
int32_t folio_page_add_text_embedded(uint64_t page, const char *text, uint64_t font, double size, double x, double y);
|
|
254
|
+
int32_t folio_page_add_image(uint64_t page, uint64_t img, double x, double y, double w, double h);
|
|
255
|
+
int32_t folio_page_add_link(uint64_t page, double x1, double y1, double x2, double y2, const char *uri);
|
|
256
|
+
int32_t folio_page_add_internal_link(uint64_t page, double x1, double y1, double x2, double y2, const char *dest_name);
|
|
257
|
+
int32_t folio_page_add_text_annotation(uint64_t page, double x1, double y1, double x2, double y2, const char *text, const char *icon);
|
|
258
|
+
int32_t folio_page_set_opacity(uint64_t page, double alpha);
|
|
259
|
+
int32_t folio_page_set_rotate(uint64_t page, int32_t degrees);
|
|
260
|
+
int32_t folio_page_set_crop_box(uint64_t page, double x1, double y1, double x2, double y2);
|
|
261
|
+
int32_t folio_page_set_trim_box(uint64_t page, double x1, double y1, double x2, double y2);
|
|
262
|
+
int32_t folio_page_set_bleed_box(uint64_t page, double x1, double y1, double x2, double y2);
|
|
263
|
+
int32_t folio_page_set_art_box(uint64_t page, double x1, double y1, double x2, double y2);
|
|
264
|
+
int32_t folio_page_set_size(uint64_t page, double width, double height);
|
|
265
|
+
int32_t folio_page_add_page_link(uint64_t page, double x1, double y1, double x2, double y2, int32_t target_page);
|
|
266
|
+
int32_t folio_page_set_opacity_fill_stroke(uint64_t page, double fill_alpha, double stroke_alpha);
|
|
267
|
+
int32_t folio_page_add_highlight(uint64_t page, double x1, double y1, double x2, double y2,
|
|
268
|
+
double r, double g, double b, const double *quad_points, int32_t quad_count);
|
|
269
|
+
int32_t folio_page_add_underline_annotation(uint64_t page, double x1, double y1, double x2, double y2,
|
|
270
|
+
double r, double g, double b, const double *quad_points, int32_t quad_count);
|
|
271
|
+
int32_t folio_page_add_squiggly(uint64_t page, double x1, double y1, double x2, double y2,
|
|
272
|
+
double r, double g, double b, const double *quad_points, int32_t quad_count);
|
|
273
|
+
int32_t folio_page_add_strikeout(uint64_t page, double x1, double y1, double x2, double y2,
|
|
274
|
+
double r, double g, double b, const double *quad_points, int32_t quad_count);
|
|
275
|
+
|
|
276
|
+
/* ── Font ──────────────────────────────────────────────────────────── */
|
|
277
|
+
|
|
278
|
+
uint64_t folio_font_standard(const char *name);
|
|
279
|
+
uint64_t folio_font_helvetica(void);
|
|
280
|
+
uint64_t folio_font_helvetica_bold(void);
|
|
281
|
+
uint64_t folio_font_helvetica_oblique(void);
|
|
282
|
+
uint64_t folio_font_helvetica_bold_oblique(void);
|
|
283
|
+
uint64_t folio_font_times_roman(void);
|
|
284
|
+
uint64_t folio_font_times_bold(void);
|
|
285
|
+
uint64_t folio_font_times_italic(void);
|
|
286
|
+
uint64_t folio_font_times_bold_italic(void);
|
|
287
|
+
uint64_t folio_font_courier(void);
|
|
288
|
+
uint64_t folio_font_courier_bold(void);
|
|
289
|
+
uint64_t folio_font_courier_oblique(void);
|
|
290
|
+
uint64_t folio_font_courier_bold_oblique(void);
|
|
291
|
+
uint64_t folio_font_symbol(void);
|
|
292
|
+
uint64_t folio_font_zapf_dingbats(void);
|
|
293
|
+
|
|
294
|
+
uint64_t folio_font_load_ttf(const char *path);
|
|
295
|
+
uint64_t folio_font_parse_ttf(const void *data, int32_t length);
|
|
296
|
+
void folio_font_free(uint64_t font);
|
|
297
|
+
|
|
298
|
+
/* ── Paragraph ─────────────────────────────────────────────────────── */
|
|
299
|
+
|
|
300
|
+
uint64_t folio_paragraph_new(const char *text, uint64_t font, double font_size);
|
|
301
|
+
uint64_t folio_paragraph_new_embedded(const char *text, uint64_t font, double font_size);
|
|
302
|
+
void folio_paragraph_free(uint64_t para);
|
|
303
|
+
|
|
304
|
+
int32_t folio_paragraph_set_align(uint64_t para, int32_t align);
|
|
305
|
+
int32_t folio_paragraph_set_leading(uint64_t para, double leading);
|
|
306
|
+
int32_t folio_paragraph_set_space_before(uint64_t para, double pts);
|
|
307
|
+
int32_t folio_paragraph_set_space_after(uint64_t para, double pts);
|
|
308
|
+
int32_t folio_paragraph_set_background(uint64_t para, double r, double g, double b);
|
|
309
|
+
int32_t folio_paragraph_set_first_indent(uint64_t para, double pts);
|
|
310
|
+
int32_t folio_paragraph_set_orphans(uint64_t para, int32_t n);
|
|
311
|
+
int32_t folio_paragraph_set_widows(uint64_t para, int32_t n);
|
|
312
|
+
int32_t folio_paragraph_set_ellipsis(uint64_t para, int32_t enabled);
|
|
313
|
+
int32_t folio_paragraph_set_word_break(uint64_t para, const char *mode);
|
|
314
|
+
int32_t folio_paragraph_set_hyphens(uint64_t para, const char *mode);
|
|
315
|
+
int32_t folio_paragraph_set_text_align_last(uint64_t para, int32_t align);
|
|
316
|
+
|
|
317
|
+
int32_t folio_paragraph_add_run(uint64_t para, const char *text, uint64_t font, double font_size, double r, double g, double b);
|
|
318
|
+
|
|
319
|
+
/* ── Heading ───────────────────────────────────────────────────────── */
|
|
320
|
+
|
|
321
|
+
uint64_t folio_heading_new(const char *text, int32_t level);
|
|
322
|
+
uint64_t folio_heading_new_with_font(const char *text, int32_t level, uint64_t font, double font_size);
|
|
323
|
+
uint64_t folio_heading_new_embedded(const char *text, int32_t level, uint64_t font);
|
|
324
|
+
void folio_heading_free(uint64_t heading);
|
|
325
|
+
|
|
326
|
+
int32_t folio_heading_set_align(uint64_t heading, int32_t align);
|
|
327
|
+
|
|
328
|
+
/* ── Table ─────────────────────────────────────────────────────────── */
|
|
329
|
+
|
|
330
|
+
uint64_t folio_table_new(void);
|
|
331
|
+
void folio_table_free(uint64_t table);
|
|
332
|
+
|
|
333
|
+
int32_t folio_table_set_column_widths(uint64_t table, const double *widths, int32_t count);
|
|
334
|
+
int32_t folio_table_set_border_collapse(uint64_t table, int32_t enabled);
|
|
335
|
+
int32_t folio_table_set_cell_spacing(uint64_t table, double h, double v);
|
|
336
|
+
int32_t folio_table_set_auto_column_widths(uint64_t table);
|
|
337
|
+
int32_t folio_table_set_min_width(uint64_t table, double pts);
|
|
338
|
+
|
|
339
|
+
uint64_t folio_table_add_row(uint64_t table);
|
|
340
|
+
uint64_t folio_table_add_header_row(uint64_t table);
|
|
341
|
+
uint64_t folio_table_add_footer_row(uint64_t table);
|
|
342
|
+
void folio_row_free(uint64_t row);
|
|
343
|
+
|
|
344
|
+
uint64_t folio_row_add_cell(uint64_t row, const char *text, uint64_t font, double font_size);
|
|
345
|
+
uint64_t folio_row_add_cell_embedded(uint64_t row, const char *text, uint64_t font, double font_size);
|
|
346
|
+
uint64_t folio_row_add_cell_element(uint64_t row, uint64_t element);
|
|
347
|
+
void folio_cell_free(uint64_t cell);
|
|
348
|
+
|
|
349
|
+
int32_t folio_cell_set_align(uint64_t cell, int32_t align);
|
|
350
|
+
int32_t folio_cell_set_padding(uint64_t cell, double padding);
|
|
351
|
+
int32_t folio_cell_set_padding_sides(uint64_t cell, double top, double right, double bottom, double left);
|
|
352
|
+
int32_t folio_cell_set_valign(uint64_t cell, int32_t valign);
|
|
353
|
+
int32_t folio_cell_set_background(uint64_t cell, double r, double g, double b);
|
|
354
|
+
int32_t folio_cell_set_colspan(uint64_t cell, int32_t n);
|
|
355
|
+
int32_t folio_cell_set_rowspan(uint64_t cell, int32_t n);
|
|
356
|
+
int32_t folio_cell_set_border(uint64_t cell, double width, double r, double g, double b);
|
|
357
|
+
int32_t folio_cell_set_borders(uint64_t cell,
|
|
358
|
+
double top_w, double top_r, double top_g, double top_b,
|
|
359
|
+
double right_w, double right_r, double right_g, double right_b,
|
|
360
|
+
double bottom_w, double bottom_r, double bottom_g, double bottom_b,
|
|
361
|
+
double left_w, double left_r, double left_g, double left_b);
|
|
362
|
+
int32_t folio_cell_set_width_hint(uint64_t cell, double pts);
|
|
363
|
+
int32_t folio_cell_set_border_radius(uint64_t cell, double radius);
|
|
364
|
+
int32_t folio_cell_set_border_radius_per_corner(uint64_t cell, double tl, double tr, double br, double bl);
|
|
365
|
+
|
|
366
|
+
/* ── Image ─────────────────────────────────────────────────────────── */
|
|
367
|
+
|
|
368
|
+
uint64_t folio_image_load_jpeg(const char *path);
|
|
369
|
+
uint64_t folio_image_load_png(const char *path);
|
|
370
|
+
uint64_t folio_image_load_tiff(const char *path);
|
|
371
|
+
uint64_t folio_image_parse_jpeg(const void *data, int32_t length);
|
|
372
|
+
uint64_t folio_image_parse_png(const void *data, int32_t length);
|
|
373
|
+
int32_t folio_image_width(uint64_t img);
|
|
374
|
+
int32_t folio_image_height(uint64_t img);
|
|
375
|
+
void folio_image_free(uint64_t img);
|
|
376
|
+
|
|
377
|
+
uint64_t folio_image_element_new(uint64_t img);
|
|
378
|
+
int32_t folio_image_element_set_size(uint64_t elem, double w, double h);
|
|
379
|
+
int32_t folio_image_element_set_align(uint64_t elem, int32_t align);
|
|
380
|
+
int32_t folio_image_element_set_alt_text(uint64_t elem, const char *text);
|
|
381
|
+
int32_t folio_image_element_set_object_fit(uint64_t elem, const char *fit);
|
|
382
|
+
int32_t folio_image_element_set_object_position(uint64_t elem, const char *pos);
|
|
383
|
+
void folio_image_element_free(uint64_t elem);
|
|
384
|
+
|
|
385
|
+
/* ── Div (container) ───────────────────────────────────────────────── */
|
|
386
|
+
|
|
387
|
+
uint64_t folio_div_new(void);
|
|
388
|
+
void folio_div_free(uint64_t div);
|
|
389
|
+
|
|
390
|
+
int32_t folio_div_add(uint64_t div, uint64_t element);
|
|
391
|
+
int32_t folio_div_set_padding(uint64_t div, double top, double right, double bottom, double left);
|
|
392
|
+
int32_t folio_div_set_background(uint64_t div, double r, double g, double b);
|
|
393
|
+
int32_t folio_div_set_border(uint64_t div, double width, double r, double g, double b);
|
|
394
|
+
int32_t folio_div_set_width(uint64_t div, double pts);
|
|
395
|
+
int32_t folio_div_set_min_height(uint64_t div, double pts);
|
|
396
|
+
int32_t folio_div_set_max_width(uint64_t div, double pts);
|
|
397
|
+
int32_t folio_div_set_min_width(uint64_t div, double pts);
|
|
398
|
+
int32_t folio_div_set_width_percent(uint64_t div, double pct);
|
|
399
|
+
int32_t folio_div_set_aspect_ratio(uint64_t div, double ratio);
|
|
400
|
+
int32_t folio_div_set_keep_together(uint64_t div, int32_t enabled);
|
|
401
|
+
int32_t folio_div_set_border_radius_per_corner(uint64_t div, double tl, double tr, double br, double bl);
|
|
402
|
+
int32_t folio_div_set_hcenter(uint64_t div, int32_t enabled);
|
|
403
|
+
int32_t folio_div_set_hright(uint64_t div, int32_t enabled);
|
|
404
|
+
int32_t folio_div_set_clear(uint64_t div, const char *value);
|
|
405
|
+
int32_t folio_div_set_outline(uint64_t div, double width, const char *style,
|
|
406
|
+
double r, double g, double b, double offset);
|
|
407
|
+
int32_t folio_div_add_box_shadow(uint64_t div, double offset_x, double offset_y,
|
|
408
|
+
double blur, double spread, double r, double g, double b);
|
|
409
|
+
int32_t folio_div_set_space_before(uint64_t div, double pts);
|
|
410
|
+
int32_t folio_div_set_space_after(uint64_t div, double pts);
|
|
411
|
+
int32_t folio_div_set_border_radius(uint64_t div, double radius);
|
|
412
|
+
int32_t folio_div_set_opacity(uint64_t div, double opacity);
|
|
413
|
+
int32_t folio_div_set_overflow(uint64_t div, const char *mode);
|
|
414
|
+
int32_t folio_div_set_tag(uint64_t div, const char *tag); /* PDF/UA structure tag override */
|
|
415
|
+
int32_t folio_div_set_box_shadow(uint64_t div, double offset_x, double offset_y,
|
|
416
|
+
double blur, double spread, double r, double g, double b);
|
|
417
|
+
int32_t folio_div_set_max_height(uint64_t div, double pts);
|
|
418
|
+
|
|
419
|
+
/* ── List ──────────────────────────────────────────────────────────── */
|
|
420
|
+
|
|
421
|
+
uint64_t folio_list_new(uint64_t font, double font_size);
|
|
422
|
+
uint64_t folio_list_new_embedded(uint64_t font, double font_size);
|
|
423
|
+
void folio_list_free(uint64_t list);
|
|
424
|
+
|
|
425
|
+
int32_t folio_list_set_style(uint64_t list, int32_t style);
|
|
426
|
+
int32_t folio_list_set_indent(uint64_t list, double indent);
|
|
427
|
+
int32_t folio_list_set_leading(uint64_t list, double leading);
|
|
428
|
+
int32_t folio_list_add_item(uint64_t list, const char *text);
|
|
429
|
+
uint64_t folio_list_add_nested_item(uint64_t list, const char *text);
|
|
430
|
+
|
|
431
|
+
/* ── Link (layout element) ────────────────────────────────────────── */
|
|
432
|
+
|
|
433
|
+
uint64_t folio_link_new(const char *text, const char *uri, uint64_t font, double font_size);
|
|
434
|
+
uint64_t folio_link_new_embedded(const char *text, const char *uri, uint64_t font, double font_size);
|
|
435
|
+
uint64_t folio_link_new_internal(const char *text, const char *dest_name, uint64_t font, double font_size);
|
|
436
|
+
void folio_link_free(uint64_t link);
|
|
437
|
+
|
|
438
|
+
int32_t folio_link_set_color(uint64_t link, double r, double g, double b);
|
|
439
|
+
int32_t folio_link_set_underline(uint64_t link);
|
|
440
|
+
int32_t folio_link_set_align(uint64_t link, int32_t align);
|
|
441
|
+
|
|
442
|
+
/* ── TextRun builder (styled text for headings, lists) ─────────────── */
|
|
443
|
+
|
|
444
|
+
/* Decoration constants */
|
|
445
|
+
#define FOLIO_DECORATION_NONE 0
|
|
446
|
+
#define FOLIO_DECORATION_UNDERLINE 1
|
|
447
|
+
#define FOLIO_DECORATION_STRIKETHROUGH 2
|
|
448
|
+
|
|
449
|
+
uint64_t folio_run_list_new(void);
|
|
450
|
+
void folio_run_list_free(uint64_t rl);
|
|
451
|
+
|
|
452
|
+
int32_t folio_run_list_add(uint64_t rl, const char *text, uint64_t font, double font_size, double r, double g, double b);
|
|
453
|
+
int32_t folio_run_list_add_embedded(uint64_t rl, const char *text, uint64_t font, double font_size, double r, double g, double b);
|
|
454
|
+
int32_t folio_run_list_add_link(uint64_t rl, const char *text, uint64_t font, double font_size,
|
|
455
|
+
double r, double g, double b, const char *uri, int32_t underline);
|
|
456
|
+
int32_t folio_run_list_last_set_underline(uint64_t rl);
|
|
457
|
+
int32_t folio_run_list_last_set_strikethrough(uint64_t rl);
|
|
458
|
+
int32_t folio_run_list_last_set_letter_spacing(uint64_t rl, double spacing);
|
|
459
|
+
int32_t folio_run_list_last_set_background_color(uint64_t rl, double r, double g, double b);
|
|
460
|
+
|
|
461
|
+
int32_t folio_heading_set_runs(uint64_t heading, uint64_t run_list);
|
|
462
|
+
int32_t folio_list_add_item_runs(uint64_t list, uint64_t run_list);
|
|
463
|
+
uint64_t folio_list_add_item_runs_with_sublist(uint64_t list, uint64_t run_list);
|
|
464
|
+
|
|
465
|
+
/* ── Misc layout elements ──────────────────────────────────────────── */
|
|
466
|
+
|
|
467
|
+
uint64_t folio_line_separator_new(void);
|
|
468
|
+
uint64_t folio_area_break_new(void);
|
|
469
|
+
|
|
470
|
+
/* ── Barcode ──────────────────────────────────────────────────────── */
|
|
471
|
+
|
|
472
|
+
uint64_t folio_barcode_qr(const char *data);
|
|
473
|
+
uint64_t folio_barcode_qr_ecc(const char *data, int32_t level);
|
|
474
|
+
uint64_t folio_barcode_code128(const char *data);
|
|
475
|
+
uint64_t folio_barcode_ean13(const char *data);
|
|
476
|
+
int32_t folio_barcode_width(uint64_t bc);
|
|
477
|
+
int32_t folio_barcode_height(uint64_t bc);
|
|
478
|
+
void folio_barcode_free(uint64_t bc);
|
|
479
|
+
|
|
480
|
+
uint64_t folio_barcode_element_new(uint64_t bc, double width);
|
|
481
|
+
int32_t folio_barcode_element_set_height(uint64_t elem, double height);
|
|
482
|
+
int32_t folio_barcode_element_set_align(uint64_t elem, int32_t align);
|
|
483
|
+
int32_t folio_barcode_element_set_alt_text(uint64_t elem, const char *text);
|
|
484
|
+
void folio_barcode_element_free(uint64_t elem);
|
|
485
|
+
|
|
486
|
+
/* ── SVG ──────────────────────────────────────────────────────────── */
|
|
487
|
+
|
|
488
|
+
uint64_t folio_svg_parse(const char *svg_xml);
|
|
489
|
+
uint64_t folio_svg_parse_bytes(const void *data, int32_t length);
|
|
490
|
+
double folio_svg_width(uint64_t svg);
|
|
491
|
+
double folio_svg_height(uint64_t svg);
|
|
492
|
+
void folio_svg_free(uint64_t svg);
|
|
493
|
+
|
|
494
|
+
uint64_t folio_svg_element_new(uint64_t svg);
|
|
495
|
+
int32_t folio_svg_element_set_size(uint64_t elem, double w, double h);
|
|
496
|
+
int32_t folio_svg_element_set_align(uint64_t elem, int32_t align);
|
|
497
|
+
int32_t folio_svg_element_set_alt_text(uint64_t elem, const char *text);
|
|
498
|
+
void folio_svg_element_free(uint64_t elem);
|
|
499
|
+
|
|
500
|
+
/* ── Flex (container) ─────────────────────────────────────────────── */
|
|
501
|
+
|
|
502
|
+
uint64_t folio_flex_new(void);
|
|
503
|
+
void folio_flex_free(uint64_t flex);
|
|
504
|
+
|
|
505
|
+
int32_t folio_flex_add(uint64_t flex, uint64_t element);
|
|
506
|
+
int32_t folio_flex_add_item(uint64_t flex, uint64_t item);
|
|
507
|
+
int32_t folio_flex_set_direction(uint64_t flex, int32_t direction);
|
|
508
|
+
int32_t folio_flex_set_justify_content(uint64_t flex, int32_t justify);
|
|
509
|
+
int32_t folio_flex_set_align_items(uint64_t flex, int32_t align);
|
|
510
|
+
int32_t folio_flex_set_wrap(uint64_t flex, int32_t wrap);
|
|
511
|
+
int32_t folio_flex_set_gap(uint64_t flex, double gap);
|
|
512
|
+
int32_t folio_flex_set_padding(uint64_t flex, double padding);
|
|
513
|
+
int32_t folio_flex_set_background(uint64_t flex, double r, double g, double b);
|
|
514
|
+
int32_t folio_flex_set_space_before(uint64_t flex, double pts);
|
|
515
|
+
int32_t folio_flex_set_space_after(uint64_t flex, double pts);
|
|
516
|
+
int32_t folio_flex_set_row_gap(uint64_t flex, double gap);
|
|
517
|
+
int32_t folio_flex_set_column_gap(uint64_t flex, double gap);
|
|
518
|
+
int32_t folio_flex_set_align_content(uint64_t flex, int32_t align);
|
|
519
|
+
int32_t folio_flex_set_borders(uint64_t flex,
|
|
520
|
+
double top_w, double top_r, double top_g, double top_b,
|
|
521
|
+
double right_w, double right_r, double right_g, double right_b,
|
|
522
|
+
double bottom_w, double bottom_r, double bottom_g, double bottom_b,
|
|
523
|
+
double left_w, double left_r, double left_g, double left_b);
|
|
524
|
+
int32_t folio_flex_set_padding_all(uint64_t flex, double top, double right, double bottom, double left);
|
|
525
|
+
int32_t folio_flex_set_border(uint64_t flex, double width, double r, double g, double b);
|
|
526
|
+
|
|
527
|
+
uint64_t folio_flex_item_new(uint64_t element);
|
|
528
|
+
void folio_flex_item_free(uint64_t item);
|
|
529
|
+
|
|
530
|
+
int32_t folio_flex_item_set_grow(uint64_t item, double grow);
|
|
531
|
+
int32_t folio_flex_item_set_shrink(uint64_t item, double shrink);
|
|
532
|
+
int32_t folio_flex_item_set_basis(uint64_t item, double basis);
|
|
533
|
+
int32_t folio_flex_item_set_align_self(uint64_t item, int32_t align);
|
|
534
|
+
int32_t folio_flex_item_set_margins(uint64_t item, double top, double right, double bottom, double left);
|
|
535
|
+
|
|
536
|
+
/* ── HTML to PDF ───────────────────────────────────────────────────── */
|
|
537
|
+
|
|
538
|
+
int32_t folio_html_to_pdf(const char *html, const char *output_path);
|
|
539
|
+
uint64_t folio_html_to_buffer(const char *html, double page_width, double page_height);
|
|
540
|
+
uint64_t folio_html_convert(const char *html, double page_width, double page_height);
|
|
541
|
+
double folio_html_parse_css_length(const char *s, double font_size, double relative_to);
|
|
542
|
+
|
|
543
|
+
/* ── Reader (PDF parsing) ──────────────────────────────────────────── */
|
|
544
|
+
|
|
545
|
+
uint64_t folio_reader_open(const char *path);
|
|
546
|
+
uint64_t folio_reader_parse(const void *data, int32_t length);
|
|
547
|
+
void folio_reader_free(uint64_t reader);
|
|
548
|
+
|
|
549
|
+
int32_t folio_reader_page_count(uint64_t reader);
|
|
550
|
+
uint64_t folio_reader_version(uint64_t reader);
|
|
551
|
+
uint64_t folio_reader_info_title(uint64_t reader);
|
|
552
|
+
uint64_t folio_reader_info_author(uint64_t reader);
|
|
553
|
+
uint64_t folio_reader_extract_text(uint64_t reader, int32_t page_index);
|
|
554
|
+
double folio_reader_page_width(uint64_t reader, int32_t page_index);
|
|
555
|
+
double folio_reader_page_height(uint64_t reader, int32_t page_index);
|
|
556
|
+
|
|
557
|
+
/* Structured content extraction (returns JSON buffer handles) */
|
|
558
|
+
uint64_t folio_reader_structure_tree(uint64_t reader); /* JSON buffer, 0 if not tagged */
|
|
559
|
+
uint64_t folio_reader_text_spans(uint64_t reader, int32_t page_index);
|
|
560
|
+
uint64_t folio_reader_images(uint64_t reader, int32_t page_index);
|
|
561
|
+
uint64_t folio_reader_paths(uint64_t reader, int32_t page_index);
|
|
562
|
+
|
|
563
|
+
/* ── Digital Signatures ─────────────────────────────────────────────── */
|
|
564
|
+
|
|
565
|
+
/* PAdES conformance levels (sign.PAdESLevel) */
|
|
566
|
+
#define FOLIO_PADES_BB 0 /* B-B: basic signature */
|
|
567
|
+
#define FOLIO_PADES_BT 1 /* B-T: + timestamp */
|
|
568
|
+
#define FOLIO_PADES_BLT 2 /* B-LT: + revocation data */
|
|
569
|
+
#define FOLIO_PADES_BLTA 3 /* B-LTA: + document timestamp */
|
|
570
|
+
|
|
571
|
+
uint64_t folio_signer_new_pem(const void *key_pem, int32_t key_len,
|
|
572
|
+
const void *cert_pem, int32_t cert_len);
|
|
573
|
+
uint64_t folio_signer_new_pkcs12(const void *data, int32_t length, const char *password);
|
|
574
|
+
void folio_signer_free(uint64_t signer);
|
|
575
|
+
|
|
576
|
+
uint64_t folio_tsa_client_new(const char *url);
|
|
577
|
+
void folio_tsa_client_free(uint64_t tsa);
|
|
578
|
+
|
|
579
|
+
uint64_t folio_ocsp_client_new(void);
|
|
580
|
+
void folio_ocsp_client_free(uint64_t ocsp);
|
|
581
|
+
|
|
582
|
+
uint64_t folio_sign_opts_new(uint64_t signer, int32_t level); /* FOLIO_PADES_* */
|
|
583
|
+
int32_t folio_sign_opts_set_name(uint64_t opts, const char *name);
|
|
584
|
+
int32_t folio_sign_opts_set_reason(uint64_t opts, const char *reason);
|
|
585
|
+
int32_t folio_sign_opts_set_location(uint64_t opts, const char *location);
|
|
586
|
+
int32_t folio_sign_opts_set_contact_info(uint64_t opts, const char *info);
|
|
587
|
+
int32_t folio_sign_opts_set_tsa(uint64_t opts, uint64_t tsa);
|
|
588
|
+
int32_t folio_sign_opts_set_ocsp(uint64_t opts, uint64_t ocsp);
|
|
589
|
+
void folio_sign_opts_free(uint64_t opts);
|
|
590
|
+
|
|
591
|
+
uint64_t folio_sign_pdf(const void *pdf_data, int32_t pdf_len, uint64_t opts); /* returns buffer handle */
|
|
592
|
+
|
|
593
|
+
/* ── Merge (combine PDFs) ──────────────────────────────────────────── */
|
|
594
|
+
|
|
595
|
+
uint64_t folio_reader_merge(const uint64_t *readers, int32_t count);
|
|
596
|
+
uint64_t folio_merge_files(const char **paths, int32_t count);
|
|
597
|
+
int32_t folio_merge_set_info(uint64_t merged, const char *title, const char *author);
|
|
598
|
+
int32_t folio_merge_add_blank_page(uint64_t merged, double width, double height);
|
|
599
|
+
int32_t folio_merge_add_page_with_text(uint64_t merged, double width, double height,
|
|
600
|
+
const char *text, uint64_t font, double font_size, double x, double y);
|
|
601
|
+
int32_t folio_merge_save(uint64_t merged, const char *path);
|
|
602
|
+
uint64_t folio_merge_write_to_buffer(uint64_t merged);
|
|
603
|
+
int32_t folio_merge_flatten_forms(uint64_t merged);
|
|
604
|
+
int32_t folio_merge_page_count(uint64_t merged);
|
|
605
|
+
int32_t folio_merge_remove_page(uint64_t merged, int32_t index);
|
|
606
|
+
int32_t folio_merge_rotate_page(uint64_t merged, int32_t index, int32_t degrees);
|
|
607
|
+
int32_t folio_merge_reorder_pages(uint64_t merged, const int32_t *order, int32_t count);
|
|
608
|
+
int32_t folio_merge_crop_page(uint64_t merged, int32_t index, double x1, double y1, double x2, double y2);
|
|
609
|
+
void folio_merge_free(uint64_t merged);
|
|
610
|
+
|
|
611
|
+
/* ── Forms ─────────────────────────────────────────────────────────── */
|
|
612
|
+
|
|
613
|
+
uint64_t folio_form_new(void);
|
|
614
|
+
void folio_form_free(uint64_t form);
|
|
615
|
+
|
|
616
|
+
int32_t folio_form_add_text_field(uint64_t form, const char *name, double x1, double y1, double x2, double y2, int32_t page_index);
|
|
617
|
+
int32_t folio_form_add_checkbox(uint64_t form, const char *name, double x1, double y1, double x2, double y2, int32_t page_index, int32_t checked);
|
|
618
|
+
int32_t folio_form_add_dropdown(uint64_t form, const char *name, double x1, double y1, double x2, double y2, int32_t page_index, const char **options, int32_t opt_count);
|
|
619
|
+
int32_t folio_form_add_signature(uint64_t form, const char *name, double x1, double y1, double x2, double y2, int32_t page_index);
|
|
620
|
+
int32_t folio_form_add_multiline_text_field(uint64_t form, const char *name, double x1, double y1, double x2, double y2, int32_t page_index);
|
|
621
|
+
int32_t folio_form_add_password_field(uint64_t form, const char *name, double x1, double y1, double x2, double y2, int32_t page_index);
|
|
622
|
+
int32_t folio_form_add_listbox(uint64_t form, const char *name, double x1, double y1, double x2, double y2, int32_t page_index, const char **options, int32_t opt_count);
|
|
623
|
+
int32_t folio_form_add_radio_group(uint64_t form, const char *name,
|
|
624
|
+
const char **values, const double *rects, const int32_t *page_indices, int32_t count);
|
|
625
|
+
|
|
626
|
+
/* Form field builder — create field, configure, then add to form */
|
|
627
|
+
uint64_t folio_form_create_text_field(const char *name, double x1, double y1, double x2, double y2, int32_t page_index);
|
|
628
|
+
uint64_t folio_form_create_checkbox(const char *name, double x1, double y1, double x2, double y2, int32_t page_index, int32_t checked);
|
|
629
|
+
int32_t folio_form_add_field(uint64_t form, uint64_t field);
|
|
630
|
+
void folio_form_field_free(uint64_t field);
|
|
631
|
+
|
|
632
|
+
int32_t folio_form_field_set_value(uint64_t field, const char *value);
|
|
633
|
+
int32_t folio_form_field_set_read_only(uint64_t field);
|
|
634
|
+
int32_t folio_form_field_set_required(uint64_t field);
|
|
635
|
+
int32_t folio_form_field_set_background_color(uint64_t field, double r, double g, double b);
|
|
636
|
+
int32_t folio_form_field_set_border_color(uint64_t field, double r, double g, double b);
|
|
637
|
+
|
|
638
|
+
/* Form filling (modify existing PDF forms) */
|
|
639
|
+
uint64_t folio_form_filler_new(uint64_t reader);
|
|
640
|
+
void folio_form_filler_free(uint64_t filler);
|
|
641
|
+
uint64_t folio_form_filler_field_names(uint64_t filler); /* returns buffer handle (newline-separated) */
|
|
642
|
+
uint64_t folio_form_filler_get_value(uint64_t filler, const char *field_name); /* returns buffer handle */
|
|
643
|
+
int32_t folio_form_filler_set_value(uint64_t filler, const char *field_name, const char *value);
|
|
644
|
+
int32_t folio_form_filler_set_checkbox(uint64_t filler, const char *field_name, int32_t checked);
|
|
645
|
+
|
|
646
|
+
/* ── Grid (container) ─────────────────────────────────────────────── */
|
|
647
|
+
|
|
648
|
+
/* Grid track types: 0=px, 1=percent, 2=fr, 3=auto */
|
|
649
|
+
#define FOLIO_GRID_PX 0
|
|
650
|
+
#define FOLIO_GRID_PERCENT 1
|
|
651
|
+
#define FOLIO_GRID_FR 2
|
|
652
|
+
#define FOLIO_GRID_AUTO 3
|
|
653
|
+
|
|
654
|
+
/* Float sides */
|
|
655
|
+
#define FOLIO_FLOAT_LEFT 0
|
|
656
|
+
#define FOLIO_FLOAT_RIGHT 1
|
|
657
|
+
|
|
658
|
+
/* Tab alignment */
|
|
659
|
+
#define FOLIO_TAB_LEFT 0
|
|
660
|
+
#define FOLIO_TAB_RIGHT 1
|
|
661
|
+
#define FOLIO_TAB_CENTER 2
|
|
662
|
+
|
|
663
|
+
uint64_t folio_grid_new(void);
|
|
664
|
+
void folio_grid_free(uint64_t grid);
|
|
665
|
+
|
|
666
|
+
int32_t folio_grid_add_child(uint64_t grid, uint64_t element);
|
|
667
|
+
int32_t folio_grid_set_template_columns(uint64_t grid, const int32_t *types, const double *values, int32_t count);
|
|
668
|
+
int32_t folio_grid_set_template_rows(uint64_t grid, const int32_t *types, const double *values, int32_t count);
|
|
669
|
+
int32_t folio_grid_set_border(uint64_t grid, double width, double r, double g, double b);
|
|
670
|
+
int32_t folio_grid_set_borders(uint64_t grid,
|
|
671
|
+
double top_w, double top_r, double top_g, double top_b,
|
|
672
|
+
double right_w, double right_r, double right_g, double right_b,
|
|
673
|
+
double bottom_w, double bottom_r, double bottom_g, double bottom_b,
|
|
674
|
+
double left_w, double left_r, double left_g, double left_b);
|
|
675
|
+
/* template_areas: rows is an array of space-separated area names; cols is the
|
|
676
|
+
* column count per row. Example: rows={"header header","nav main"} cols={2,2}. */
|
|
677
|
+
int32_t folio_grid_set_template_areas(uint64_t grid, const char **rows,
|
|
678
|
+
const int32_t *cols, int32_t row_count);
|
|
679
|
+
int32_t folio_grid_set_auto_rows(uint64_t grid, const int32_t *types, const double *values, int32_t count);
|
|
680
|
+
int32_t folio_grid_set_gap(uint64_t grid, double row_gap, double col_gap);
|
|
681
|
+
int32_t folio_grid_set_placement(uint64_t grid, int32_t child_index, int32_t col_start, int32_t col_end, int32_t row_start, int32_t row_end);
|
|
682
|
+
int32_t folio_grid_set_padding(uint64_t grid, double padding);
|
|
683
|
+
int32_t folio_grid_set_background(uint64_t grid, double r, double g, double b);
|
|
684
|
+
int32_t folio_grid_set_justify_items(uint64_t grid, int32_t align);
|
|
685
|
+
int32_t folio_grid_set_align_items(uint64_t grid, int32_t align);
|
|
686
|
+
int32_t folio_grid_set_justify_content(uint64_t grid, int32_t justify);
|
|
687
|
+
int32_t folio_grid_set_align_content(uint64_t grid, int32_t align);
|
|
688
|
+
int32_t folio_grid_set_space_before(uint64_t grid, double pts);
|
|
689
|
+
int32_t folio_grid_set_space_after(uint64_t grid, double pts);
|
|
690
|
+
|
|
691
|
+
/* ── Columns (multi-column layout) ────────────────────────────────── */
|
|
692
|
+
|
|
693
|
+
uint64_t folio_columns_new(int32_t cols);
|
|
694
|
+
void folio_columns_free(uint64_t columns);
|
|
695
|
+
|
|
696
|
+
int32_t folio_columns_set_gap(uint64_t columns, double gap);
|
|
697
|
+
int32_t folio_columns_set_widths(uint64_t columns, const double *widths, int32_t count);
|
|
698
|
+
int32_t folio_columns_add(uint64_t columns, int32_t col_index, uint64_t element);
|
|
699
|
+
|
|
700
|
+
/* ── Float (text wrapping) ────────────────────────────────────────── */
|
|
701
|
+
|
|
702
|
+
uint64_t folio_float_new(int32_t side, uint64_t element); /* FOLIO_FLOAT_LEFT/RIGHT */
|
|
703
|
+
void folio_float_free(uint64_t flt);
|
|
704
|
+
int32_t folio_float_set_margin(uint64_t flt, double margin);
|
|
705
|
+
|
|
706
|
+
/* ── TabbedLine (tab-stop text) ───────────────────────────────────── */
|
|
707
|
+
|
|
708
|
+
uint64_t folio_tabbed_line_new(uint64_t font, double font_size,
|
|
709
|
+
const double *positions, const int32_t *aligns, const int32_t *leaders, int32_t count);
|
|
710
|
+
uint64_t folio_tabbed_line_new_embedded(uint64_t font, double font_size,
|
|
711
|
+
const double *positions, const int32_t *aligns, const int32_t *leaders, int32_t count);
|
|
712
|
+
void folio_tabbed_line_free(uint64_t tl);
|
|
713
|
+
|
|
714
|
+
int32_t folio_tabbed_line_set_segments(uint64_t tl, const char **segments, int32_t count);
|
|
715
|
+
int32_t folio_tabbed_line_set_color(uint64_t tl, double r, double g, double b);
|
|
716
|
+
int32_t folio_tabbed_line_set_leading(uint64_t tl, double leading);
|
|
717
|
+
|
|
718
|
+
/* ── Drawing primitives ────────────────────────────────────────────── */
|
|
719
|
+
|
|
720
|
+
int32_t folio_page_add_line(uint64_t page, double x1, double y1, double x2, double y2,
|
|
721
|
+
double width, double r, double g, double b);
|
|
722
|
+
int32_t folio_page_add_rect(uint64_t page, double x, double y, double w, double h,
|
|
723
|
+
double stroke_width, double r, double g, double b);
|
|
724
|
+
int32_t folio_page_add_rect_filled(uint64_t page, double x, double y, double w, double h,
|
|
725
|
+
double r, double g, double b);
|
|
726
|
+
|
|
727
|
+
/* ── Page import (template workflows) ─────────────────────────────── */
|
|
728
|
+
|
|
729
|
+
uint64_t folio_extract_page_import(uint64_t reader, int32_t page_index);
|
|
730
|
+
void folio_page_import_free(uint64_t imp);
|
|
731
|
+
double folio_page_import_width(uint64_t imp);
|
|
732
|
+
double folio_page_import_height(uint64_t imp);
|
|
733
|
+
int32_t folio_page_import_apply(uint64_t page, uint64_t imp);
|
|
734
|
+
|
|
735
|
+
/* ── Redaction ────────────────────────────────────────────────────── */
|
|
736
|
+
|
|
737
|
+
uint64_t folio_redact_opts_new(void);
|
|
738
|
+
void folio_redact_opts_free(uint64_t opts);
|
|
739
|
+
int32_t folio_redact_opts_set_fill_color(uint64_t opts, double r, double g, double b);
|
|
740
|
+
int32_t folio_redact_opts_set_overlay(uint64_t opts, const char *text, double font_size,
|
|
741
|
+
double r, double g, double b);
|
|
742
|
+
int32_t folio_redact_opts_set_strip_metadata(uint64_t opts, int32_t strip);
|
|
743
|
+
|
|
744
|
+
uint64_t folio_redact_text(uint64_t reader, const char **targets, int32_t count, uint64_t opts);
|
|
745
|
+
uint64_t folio_redact_pattern(uint64_t reader, const char *pattern, uint64_t opts);
|
|
746
|
+
uint64_t folio_redact_regions(uint64_t reader, const int32_t *pages,
|
|
747
|
+
const double *x1s, const double *y1s, const double *x2s, const double *y2s,
|
|
748
|
+
int32_t count, uint64_t opts);
|
|
749
|
+
|
|
750
|
+
#ifdef __cplusplus
|
|
751
|
+
}
|
|
752
|
+
#endif
|
|
753
|
+
|
|
754
|
+
#endif /* FOLIO_H */
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|