@strav/pdf 0.4.17
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.
- package/README.md +79 -0
- package/package.json +51 -0
- package/src/color/cie.ts +61 -0
- package/src/color/color.ts +77 -0
- package/src/color/conversion.ts +26 -0
- package/src/color/device.ts +37 -0
- package/src/color/devicen.ts +74 -0
- package/src/color/icc.ts +103 -0
- package/src/color/index.ts +15 -0
- package/src/color/separation.ts +94 -0
- package/src/color/space.ts +47 -0
- package/src/content/content_stream.ts +373 -0
- package/src/content/graphics_state.ts +64 -0
- package/src/content/index.ts +16 -0
- package/src/content/operators.ts +70 -0
- package/src/content/path.ts +51 -0
- package/src/content/resources.ts +119 -0
- package/src/content/text_object.ts +140 -0
- package/src/document/catalog.ts +16 -0
- package/src/document/index.ts +13 -0
- package/src/document/object_table.ts +67 -0
- package/src/document/page.ts +74 -0
- package/src/document/page_tree.ts +78 -0
- package/src/document/pdf_document.ts +310 -0
- package/src/document/types.ts +65 -0
- package/src/document/xref.ts +68 -0
- package/src/ext-gstate/ext_gstate.ts +69 -0
- package/src/ext-gstate/index.ts +2 -0
- package/src/fonts/cff.ts +123 -0
- package/src/fonts/cid_encoding.ts +45 -0
- package/src/fonts/cmap_table.ts +180 -0
- package/src/fonts/font.ts +342 -0
- package/src/fonts/glyf.ts +59 -0
- package/src/fonts/hmtx.ts +21 -0
- package/src/fonts/index.ts +20 -0
- package/src/fonts/name_table.ts +50 -0
- package/src/fonts/os2.ts +41 -0
- package/src/fonts/sfnt.ts +224 -0
- package/src/fonts/standard_14.ts +132 -0
- package/src/fonts/subset.ts +221 -0
- package/src/fonts/to_unicode.ts +82 -0
- package/src/fonts/win_ansi.ts +69 -0
- package/src/images/image.ts +111 -0
- package/src/images/index.ts +6 -0
- package/src/images/jpeg.ts +103 -0
- package/src/images/png.ts +239 -0
- package/src/images/smask.ts +24 -0
- package/src/index.ts +57 -0
- package/src/metadata/index.ts +3 -0
- package/src/metadata/info_dict.ts +28 -0
- package/src/metadata/xmp.ts +110 -0
- package/src/objects/encode.ts +77 -0
- package/src/objects/index.ts +43 -0
- package/src/objects/indirect_ref.ts +17 -0
- package/src/objects/name.ts +50 -0
- package/src/objects/number.ts +43 -0
- package/src/objects/string.ts +136 -0
- package/src/objects/types.ts +86 -0
- package/src/output/buffer_sink.ts +40 -0
- package/src/output/byte_sink.ts +12 -0
- package/src/output/index.ts +3 -0
- package/src/output/stream_sink.ts +62 -0
- package/src/patterns/index.ts +10 -0
- package/src/patterns/shading.ts +162 -0
- package/src/patterns/tiling_pattern.ts +68 -0
- package/src/standards/context.ts +10 -0
- package/src/standards/index.ts +23 -0
- package/src/standards/pdf_a.ts +23 -0
- package/src/standards/pdf_x.ts +31 -0
- package/src/streams/ascii85.ts +61 -0
- package/src/streams/ascii_hex.ts +33 -0
- package/src/streams/flate.ts +17 -0
- package/src/streams/index.ts +9 -0
- package/src/streams/stream.ts +66 -0
- package/src/util/ascii.ts +63 -0
- package/src/util/binary.ts +71 -0
- package/src/util/errors.ts +61 -0
- package/src/util/index.ts +10 -0
- package/src/util/units.ts +24 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public error taxonomy (spec §16.2).
|
|
3
|
+
*
|
|
4
|
+
* Every error thrown by the library is a subclass of {@link PdfGenError} and
|
|
5
|
+
* carries a stable `code` string for programmatic handling. The taxonomy is
|
|
6
|
+
* part of the API contract — codes do not change across minor versions.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type PdfGenErrorCode =
|
|
10
|
+
| 'PDF_INVALID_NUMBER'
|
|
11
|
+
| 'PDF_INVALID_STRING'
|
|
12
|
+
| 'PDF_INVALID_NAME'
|
|
13
|
+
| 'PDF_INVALID_OBJECT'
|
|
14
|
+
| 'PDF_UNBALANCED_GRAPHICS_STATE'
|
|
15
|
+
| 'PDF_PATH_NOT_CONSUMED'
|
|
16
|
+
| 'PDF_NO_PATH'
|
|
17
|
+
| 'PDF_INVALID_COLOR'
|
|
18
|
+
| 'PDF_INVALID_PAGE'
|
|
19
|
+
| 'PDF_DOCUMENT_FINALIZED'
|
|
20
|
+
| 'PDF_CONFORMANCE'
|
|
21
|
+
| 'PDF_UNSUPPORTED_FONT'
|
|
22
|
+
| 'PDF_INVALID_IMAGE'
|
|
23
|
+
| 'PDF_TEXT_STATE'
|
|
24
|
+
| 'PDF_TEXT_ENCODING'
|
|
25
|
+
| 'PDF_NO_FONT'
|
|
26
|
+
|
|
27
|
+
export class PdfGenError extends Error {
|
|
28
|
+
readonly code: PdfGenErrorCode
|
|
29
|
+
|
|
30
|
+
constructor(code: PdfGenErrorCode, message: string) {
|
|
31
|
+
super(message)
|
|
32
|
+
this.name = new.target.name
|
|
33
|
+
this.code = code
|
|
34
|
+
// Maintain a clean stack across the subclass chain.
|
|
35
|
+
Object.setPrototypeOf(this, new.target.prototype)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Thrown at `save()` when a conformance mode's requirements are violated. */
|
|
40
|
+
export class ConformanceError extends PdfGenError {
|
|
41
|
+
readonly violations: string[]
|
|
42
|
+
|
|
43
|
+
constructor(message: string, violations: string[] = []) {
|
|
44
|
+
super('PDF_CONFORMANCE', message)
|
|
45
|
+
this.violations = violations
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Thrown when a font cannot be used (e.g. Standard-14 under conformance). */
|
|
50
|
+
export class UnsupportedFontError extends PdfGenError {
|
|
51
|
+
constructor(message: string) {
|
|
52
|
+
super('PDF_UNSUPPORTED_FONT', message)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Thrown when image bytes cannot be parsed or are an unsupported variant. */
|
|
57
|
+
export class InvalidImageError extends PdfGenError {
|
|
58
|
+
constructor(message: string) {
|
|
59
|
+
super('PDF_INVALID_IMAGE', message)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export {
|
|
2
|
+
PdfGenError,
|
|
3
|
+
ConformanceError,
|
|
4
|
+
UnsupportedFontError,
|
|
5
|
+
InvalidImageError,
|
|
6
|
+
} from './errors.ts'
|
|
7
|
+
export type { PdfGenErrorCode } from './errors.ts'
|
|
8
|
+
export { pt, inch, mm, cm } from './units.ts'
|
|
9
|
+
export { ascii, utf8, concatBytes } from './ascii.ts'
|
|
10
|
+
export { BinaryReader, fixed1616, f2dot14 } from './binary.ts'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit helpers (spec §6.4). The public API uses points (1 pt = 1/72 inch),
|
|
3
|
+
* matching PDF user space. These convert from physical units.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Points → points (identity; provided for symmetry and readability). */
|
|
7
|
+
export function pt(value: number): number {
|
|
8
|
+
return value
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Inches → points. 1 inch = 72 pt exactly. */
|
|
12
|
+
export function inch(value: number): number {
|
|
13
|
+
return value * 72
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Millimetres → points. 1 mm = 72 / 25.4 pt. */
|
|
17
|
+
export function mm(value: number): number {
|
|
18
|
+
return (value * 72) / 25.4
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Centimetres → points. */
|
|
22
|
+
export function cm(value: number): number {
|
|
23
|
+
return mm(value * 10)
|
|
24
|
+
}
|