@libpdf/core 0.2.1 → 0.2.3

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 CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  A modern PDF library for TypeScript. Parse, modify, and generate PDFs with a clean, intuitive API.
4
4
 
5
- > **Beta Software**: LibPDF is under active development. APIs may change between minor versions. Not yet recommended for production use.
5
+ > **Beta Software**: LibPDF is under active development and APIs may change between minor versions, but we use it in production at [Documenso](https://documenso.com) and consider it ready for real-world use.
6
6
 
7
7
  ## Why LibPDF?
8
8
 
9
9
  LibPDF was born from frustration. At [Documenso](https://documenso.com), we found ourselves wrestling with the JavaScript PDF ecosystem:
10
10
 
11
- - **PDF.js** is excellent for rendering, but it's read-only
11
+ - **PDF.js** is excellent for rendering and even has annotation editing — but it requires a browser
12
12
  - **pdf-lib** has a great API, but chokes on slightly malformed documents
13
13
  - **pdfkit** only generates, no parsing at all
14
14
 
package/dist/index.d.mts CHANGED
@@ -3732,6 +3732,40 @@ interface FindTextOptions {
3732
3732
  wholeWord?: boolean;
3733
3733
  }
3734
3734
  //#endregion
3735
+ //#region src/svg/path-executor.d.ts
3736
+ /**
3737
+ * Options for SVG path execution.
3738
+ */
3739
+ interface SvgPathExecutorOptions {
3740
+ /**
3741
+ * Flip Y coordinates (negate Y values).
3742
+ *
3743
+ * SVG uses a top-left origin with Y increasing downward.
3744
+ * PDF uses a bottom-left origin with Y increasing upward.
3745
+ *
3746
+ * When true (default), Y coordinates are negated to convert
3747
+ * SVG paths to PDF coordinate space.
3748
+ *
3749
+ * @default true
3750
+ */
3751
+ flipY?: boolean;
3752
+ /**
3753
+ * Scale factor to apply to all coordinates.
3754
+ * @default 1
3755
+ */
3756
+ scale?: number;
3757
+ /**
3758
+ * X offset to add after scaling and flipping.
3759
+ * @default 0
3760
+ */
3761
+ translateX?: number;
3762
+ /**
3763
+ * Y offset to add after scaling and flipping.
3764
+ * @default 0
3765
+ */
3766
+ translateY?: number;
3767
+ }
3768
+ //#endregion
3735
3769
  //#region src/fonts/standard-14.d.ts
3736
3770
  /**
3737
3771
  * Standard 14 PDF Fonts
@@ -3971,6 +4005,65 @@ interface DrawEllipseOptions {
3971
4005
  /** Rotation */
3972
4006
  rotate?: Rotation;
3973
4007
  }
4008
+ /**
4009
+ * Options for drawing an SVG path.
4010
+ *
4011
+ * SVG paths are automatically transformed from SVG coordinate space
4012
+ * (Y-down, origin at top-left) to PDF coordinate space (Y-up, origin
4013
+ * at bottom-left). Use `x`, `y`, and `scale` to position and size
4014
+ * the path on the page.
4015
+ */
4016
+ interface DrawSvgPathOptions {
4017
+ /**
4018
+ * X position on the page (left edge of the path's bounding box).
4019
+ * @default 0
4020
+ */
4021
+ x?: number;
4022
+ /**
4023
+ * Y position on the page (bottom edge of the path's bounding box after transform).
4024
+ * @default 0
4025
+ */
4026
+ y?: number;
4027
+ /**
4028
+ * Scale factor to apply to the path.
4029
+ * Useful for SVG icons with large viewBox (e.g., 512x512).
4030
+ * A scale of 0.1 would make a 512-unit icon ~51 points.
4031
+ * @default 1
4032
+ */
4033
+ scale?: number;
4034
+ /**
4035
+ * Whether to flip the Y-axis to convert from SVG coordinates (Y-down)
4036
+ * to PDF coordinates (Y-up).
4037
+ *
4038
+ * Set to `true` (default) when using SVG paths from icon libraries.
4039
+ * Set to `false` when using paths already in PDF coordinate space.
4040
+ *
4041
+ * @default true
4042
+ */
4043
+ flipY?: boolean;
4044
+ /** Fill color (default: black; omit to stroke only if borderColor set) */
4045
+ color?: Color;
4046
+ /** Stroke color (omit for no stroke) */
4047
+ borderColor?: Color;
4048
+ /** Stroke width in points (default: 1 if borderColor set) */
4049
+ borderWidth?: number;
4050
+ /** Line cap style */
4051
+ lineCap?: LineCap;
4052
+ /** Line join style */
4053
+ lineJoin?: LineJoin;
4054
+ /** Miter limit for miter joins */
4055
+ miterLimit?: number;
4056
+ /** Dash pattern array */
4057
+ dashArray?: number[];
4058
+ /** Dash pattern phase */
4059
+ dashPhase?: number;
4060
+ /** Fill opacity 0-1 (default: 1) */
4061
+ opacity?: number;
4062
+ /** Stroke opacity 0-1 (default: 1) */
4063
+ borderOpacity?: number;
4064
+ /** Winding rule for fill (default: "nonzero") */
4065
+ windingRule?: "nonzero" | "evenodd";
4066
+ }
3974
4067
  /**
3975
4068
  * Options for path painting.
3976
4069
  */
@@ -4093,6 +4186,40 @@ declare class PathBuilder {
4093
4186
  * Add an ellipse to the current path.
4094
4187
  */
4095
4188
  ellipse(cx: number, cy: number, rx: number, ry: number): this;
4189
+ /**
4190
+ * Append an SVG path string to the current path.
4191
+ *
4192
+ * Parses the SVG path `d` attribute string and adds all commands to this path.
4193
+ * Relative commands (lowercase) are converted to absolute coordinates based on
4194
+ * the current point. Smooth curves (S, T) and arcs (A) are converted to
4195
+ * cubic bezier curves.
4196
+ *
4197
+ * By default, this method does NOT transform coordinates (flipY: false).
4198
+ * Use the options to apply scale, translation, and Y-flip for SVG paths.
4199
+ *
4200
+ * @param pathData - SVG path `d` attribute string
4201
+ * @param options - Execution options (flipY, scale, translate)
4202
+ * @returns This PathBuilder for chaining
4203
+ *
4204
+ * @example
4205
+ * ```typescript
4206
+ * // Simple path (no transform)
4207
+ * page.drawPath()
4208
+ * .appendSvgPath("M 10 10 L 100 10 L 55 90 Z")
4209
+ * .fill({ color: rgb(1, 0, 0) });
4210
+ *
4211
+ * // SVG icon with full transform
4212
+ * page.drawPath()
4213
+ * .appendSvgPath(iconPath, {
4214
+ * flipY: true,
4215
+ * scale: 0.1,
4216
+ * translateX: 100,
4217
+ * translateY: 500,
4218
+ * })
4219
+ * .fill({ color: rgb(0, 0, 0) });
4220
+ * ```
4221
+ */
4222
+ appendSvgPath(pathData: string, options?: SvgPathExecutorOptions): this;
4096
4223
  /**
4097
4224
  * Stroke the path with the given options.
4098
4225
  */
@@ -5204,6 +5331,49 @@ declare class PDFPage {
5204
5331
  * ```
5205
5332
  */
5206
5333
  drawPath(): PathBuilder;
5334
+ /**
5335
+ * Draw an SVG path on the page.
5336
+ *
5337
+ * This is a convenience method that parses an SVG path `d` attribute string
5338
+ * and draws it with the specified options. For more control, use `drawPath()`
5339
+ * with `appendSvgPath()`.
5340
+ *
5341
+ * By default, the path is filled with black. Specify `borderColor` without
5342
+ * `color` to stroke without filling.
5343
+ *
5344
+ * SVG paths are automatically transformed from SVG coordinate space (Y-down)
5345
+ * to PDF coordinate space (Y-up). Use `x`, `y` to position the path, and
5346
+ * `scale` to resize it.
5347
+ *
5348
+ * @param pathData - SVG path `d` attribute string
5349
+ * @param options - Drawing options (x, y, scale, color, etc.)
5350
+ *
5351
+ * @example
5352
+ * ```typescript
5353
+ * // Draw a Font Awesome heart icon at position (100, 500)
5354
+ * // Icon is 512x512 in SVG, scale to ~50pt
5355
+ * page.drawSvgPath(faHeartPath, {
5356
+ * x: 100,
5357
+ * y: 500,
5358
+ * scale: 0.1,
5359
+ * color: rgb(1, 0, 0),
5360
+ * });
5361
+ *
5362
+ * // Draw a simple triangle at default position (0, 0)
5363
+ * page.drawSvgPath("M 0 0 L 50 0 L 25 40 Z", {
5364
+ * color: rgb(0, 0, 1),
5365
+ * });
5366
+ *
5367
+ * // Stroke a curve
5368
+ * page.drawSvgPath("M 0 0 C 10 10, 30 10, 40 0", {
5369
+ * x: 200,
5370
+ * y: 300,
5371
+ * borderColor: rgb(0, 0, 0),
5372
+ * borderWidth: 2,
5373
+ * });
5374
+ * ```
5375
+ */
5376
+ drawSvgPath(pathData: string, options?: DrawSvgPathOptions): void;
5207
5377
  /** Cached annotations for this page */
5208
5378
  private _annotationCache;
5209
5379
  /**
@@ -9260,5 +9430,5 @@ declare function isWidgetAnnotation(dict: PdfDict, registry?: ObjectRegistry): b
9260
9430
  */
9261
9431
  declare function isPopupAnnotation(dict: PdfDict, registry?: ObjectRegistry): boolean;
9262
9432
  //#endregion
9263
- export { AnnotationFlags, type AnnotationSubtype, type AuthenticationResult, type BorderStyle, type BorderStyleType, type ButtonField, type CMYK, type CaretAnnotationOptions, type CaretSymbol, CertificateChainError, type CheckboxField, type CheckboxOptions, type CheckboxSymbol, type CircleAnnotationOptions, type Color, type CopyPagesOptions, CryptoKeySigner, type Degrees, type DestinationType, type DigestAlgorithm, type DocumentMetadata, type DrawCircleOptions, type DrawEllipseOptions, type DrawFieldOptions, type DrawImageOptions, type DrawLineOptions, type DrawPageOptions, type DrawRectangleOptions, type DrawTextOptions, type DropdownField, type DropdownOptions, type EmbedFontOptions, type EmbeddedFont, type EncryptionAlgorithmOption, type ExtractPagesOptions, type FieldOptions, type FieldType, type FieldValue, type FileAttachmentIcon, type FlattenAllOptions, type FlattenAllResult, type FlattenAnnotationsOptions, type FlattenLayersResult, type FlattenOptions, type FontInput, type FormField, type FormProperties, type FreeTextAnnotationOptions, type FreeTextJustification, GoogleKmsSigner, type Grayscale, type HighlightMode, HttpTimestampAuthority, type HttpTimestampAuthorityOptions, type InkAnnotationOptions, type KeyType, KmsSignerError, type LayerInfo, type LayoutResult, type LineAnnotationOptions, type LineCap, type LineEndingStyle, type LineJoin, type LinkAction, type LinkAnnotationOptions, type LinkDestination, type ListBoxField, type ListboxOptions, type LoadOptions, type MergeOptions, P12Signer, type PAdESLevel, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFLineAnnotation, PDFLinkAnnotation, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PathBuilder, type PathOptions, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, type PdfObject, PdfRef, PdfStream, PdfString, type PemBlock, PermissionDeniedError, type PermissionOptions, type Permissions, PlaceholderError, type Point, type PolygonAnnotationOptions, type PolylineAnnotationOptions, type PopupOptions, type PositionedWord, type ProtectionOptions, type RGB, type RadioField, type RadioGroupOptions, type RadioSymbol, type Rect, type Rectangle, type RemoveAnnotationsOptions, RevocationError, type RevocationProvider, type Rotation, type RotationOrigin, type RotationOriginName, STANDARD_STAMPS, type SaveOptions, SecurityError, type SecurityInfo, type SetTitleOptions, type SignOptions, type SignResult, type SignWarning, type SignatureAlgorithm, SignatureError, type SignatureField, type SignatureFieldOptions, type Signer, SignerError, type SquareAnnotationOptions, type StampAnnotationOptions, type StampName, Standard14Font, type Standard14FontName, StandardFonts, type SubFilter, type TextAlignment, type TextAnnotationIcon, type TextAnnotationOptions, type TextAnnotationState, type TextAnnotationStateModel, type TextField, type TextFieldOptions, type TextLine, type TextMarkupAnnotationOptions, type TimestampAuthority, TimestampError, type TrappedStatus, black, blue, cmyk, createAnnotation, degrees, grayscale, green, isPopupAnnotation, isWidgetAnnotation, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, measureText, parsePem, rectToQuadPoints, rectsToQuadPoints, red, rgb, version, white };
9433
+ export { AnnotationFlags, type AnnotationSubtype, type AuthenticationResult, type BorderStyle, type BorderStyleType, type ButtonField, type CMYK, type CaretAnnotationOptions, type CaretSymbol, CertificateChainError, type CheckboxField, type CheckboxOptions, type CheckboxSymbol, type CircleAnnotationOptions, type Color, type CopyPagesOptions, CryptoKeySigner, type Degrees, type DestinationType, type DigestAlgorithm, type DocumentMetadata, type DrawCircleOptions, type DrawEllipseOptions, type DrawFieldOptions, type DrawImageOptions, type DrawLineOptions, type DrawPageOptions, type DrawRectangleOptions, type DrawSvgPathOptions, type DrawTextOptions, type DropdownField, type DropdownOptions, type EmbedFontOptions, type EmbeddedFont, type EncryptionAlgorithmOption, type ExtractPagesOptions, type FieldOptions, type FieldType, type FieldValue, type FileAttachmentIcon, type FlattenAllOptions, type FlattenAllResult, type FlattenAnnotationsOptions, type FlattenLayersResult, type FlattenOptions, type FontInput, type FormField, type FormProperties, type FreeTextAnnotationOptions, type FreeTextJustification, GoogleKmsSigner, type Grayscale, type HighlightMode, HttpTimestampAuthority, type HttpTimestampAuthorityOptions, type InkAnnotationOptions, type KeyType, KmsSignerError, type LayerInfo, type LayoutResult, type LineAnnotationOptions, type LineCap, type LineEndingStyle, type LineJoin, type LinkAction, type LinkAnnotationOptions, type LinkDestination, type ListBoxField, type ListboxOptions, type LoadOptions, type MergeOptions, P12Signer, type PAdESLevel, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFLineAnnotation, PDFLinkAnnotation, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PathBuilder, type PathOptions, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, type PdfObject, PdfRef, PdfStream, PdfString, type PemBlock, PermissionDeniedError, type PermissionOptions, type Permissions, PlaceholderError, type Point, type PolygonAnnotationOptions, type PolylineAnnotationOptions, type PopupOptions, type PositionedWord, type ProtectionOptions, type RGB, type RadioField, type RadioGroupOptions, type RadioSymbol, type Rect, type Rectangle, type RemoveAnnotationsOptions, RevocationError, type RevocationProvider, type Rotation, type RotationOrigin, type RotationOriginName, STANDARD_STAMPS, type SaveOptions, SecurityError, type SecurityInfo, type SetTitleOptions, type SignOptions, type SignResult, type SignWarning, type SignatureAlgorithm, SignatureError, type SignatureField, type SignatureFieldOptions, type Signer, SignerError, type SquareAnnotationOptions, type StampAnnotationOptions, type StampName, Standard14Font, type Standard14FontName, StandardFonts, type SubFilter, type TextAlignment, type TextAnnotationIcon, type TextAnnotationOptions, type TextAnnotationState, type TextAnnotationStateModel, type TextField, type TextFieldOptions, type TextLine, type TextMarkupAnnotationOptions, type TimestampAuthority, TimestampError, type TrappedStatus, black, blue, cmyk, createAnnotation, degrees, grayscale, green, isPopupAnnotation, isWidgetAnnotation, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, measureText, parsePem, rectToQuadPoints, rectsToQuadPoints, red, rgb, version, white };
9264
9434
  //# sourceMappingURL=index.d.mts.map