@libpdf/core 0.0.1-beta.12 → 0.0.1-beta.14

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/dist/index.d.mts CHANGED
@@ -2696,6 +2696,40 @@ declare class EmbeddedFont extends PdfFont {
2696
2696
  * type any character at runtime).
2697
2697
  */
2698
2698
  canSubset(): boolean;
2699
+ /**
2700
+ * Get width of text in points at a given font size.
2701
+ *
2702
+ * Alias for getTextWidth() to match Standard14Font API.
2703
+ *
2704
+ * @param text - The text to measure
2705
+ * @param size - Font size in points
2706
+ * @returns Width in points
2707
+ */
2708
+ widthOfTextAtSize(text: string, size: number): number;
2709
+ /**
2710
+ * Get the height of the font at a given size.
2711
+ *
2712
+ * This returns the full height from descender to ascender.
2713
+ *
2714
+ * @param size - Font size in points
2715
+ * @returns Height in points
2716
+ */
2717
+ heightAtSize(size: number): number;
2718
+ /**
2719
+ * Calculate font size needed to achieve a specific text height.
2720
+ *
2721
+ * @param height - Desired height in points
2722
+ * @returns Font size in points
2723
+ */
2724
+ sizeAtHeight(height: number): number;
2725
+ /**
2726
+ * Calculate font size needed for text to fit a specific width.
2727
+ *
2728
+ * @param text - The text to measure
2729
+ * @param width - Desired width in points
2730
+ * @returns Font size in points
2731
+ */
2732
+ sizeAtWidth(text: string, width: number): number;
2699
2733
  /**
2700
2734
  * Build a FontDescriptor from the font program.
2701
2735
  */
@@ -3753,17 +3787,30 @@ type LineCap = "butt" | "round" | "square";
3753
3787
  * - "bevel": Beveled corner (2)
3754
3788
  */
3755
3789
  type LineJoin = "miter" | "round" | "bevel";
3790
+ /**
3791
+ * Named rotation origin positions.
3792
+ * These are relative to the bounding box of the object being rotated.
3793
+ */
3794
+ type RotationOriginName = "top-left" | "top-center" | "top-right" | "center-left" | "center" | "center-right" | "bottom-left" | "bottom-center" | "bottom-right";
3795
+ /**
3796
+ * Rotation origin - either explicit coordinates or a named position.
3797
+ */
3798
+ type RotationOrigin = {
3799
+ x: number;
3800
+ y: number;
3801
+ } | RotationOriginName;
3756
3802
  /**
3757
3803
  * Rotation specification.
3758
3804
  */
3759
3805
  interface Rotation {
3760
3806
  /** Rotation angle in degrees (counter-clockwise) */
3761
3807
  angle: number;
3762
- /** Rotation center point (default: object center) */
3763
- origin?: {
3764
- x: number;
3765
- y: number;
3766
- };
3808
+ /**
3809
+ * Rotation center point.
3810
+ * Can be explicit coordinates `{ x, y }` or a named position like "center", "top-left", etc.
3811
+ * Default varies by object type (usually center for shapes, bottom-left for text).
3812
+ */
3813
+ origin?: RotationOrigin;
3767
3814
  }
3768
3815
  /**
3769
3816
  * Font type - either a Standard 14 font name or an embedded font.
@@ -5848,6 +5895,16 @@ interface RemoveAnnotationsOptions {
5848
5895
  interface FlattenAnnotationsOptions {
5849
5896
  /** Annotation types to exclude from flattening */
5850
5897
  exclude?: AnnotationSubtype[];
5898
+ /**
5899
+ * Remove Link annotations instead of keeping them.
5900
+ *
5901
+ * Link annotations contain URI or other actions that Adobe considers
5902
+ * "hidden behavior" which can cause signature validation warnings.
5903
+ * Enable this option when preparing documents for signing.
5904
+ *
5905
+ * @default false
5906
+ */
5907
+ removeLinks?: boolean;
5851
5908
  }
5852
5909
  //#endregion
5853
5910
  //#region src/attachments/types.d.ts
@@ -7637,6 +7694,24 @@ declare class PDF {
7637
7694
  static merge(sources: Uint8Array[], options?: MergeOptions): Promise<PDF>;
7638
7695
  /** PDF version string (e.g., "1.7", "2.0") */
7639
7696
  get version(): string;
7697
+ /**
7698
+ * Upgrade the PDF version.
7699
+ *
7700
+ * Sets the /Version entry in the catalog dictionary. This is the standard
7701
+ * way to upgrade PDF version in incremental updates since the header
7702
+ * cannot be modified.
7703
+ *
7704
+ * The version will only be upgraded if the new version is higher than
7705
+ * the current version.
7706
+ *
7707
+ * @param version - Target version (e.g., "1.7", "2.0")
7708
+ *
7709
+ * @example
7710
+ * ```typescript
7711
+ * pdf.upgradeVersion("1.7");
7712
+ * ```
7713
+ */
7714
+ upgradeVersion(version: string): void;
7640
7715
  /** Whether the document is encrypted */
7641
7716
  get isEncrypted(): boolean;
7642
7717
  /** Whether authentication succeeded (for encrypted docs) */
@@ -8572,12 +8647,6 @@ declare class PDF {
8572
8647
  * Used by signing to chain incremental updates.
8573
8648
  */
8574
8649
  private saveInternal;
8575
- /**
8576
- * Ensure all reachable objects are loaded into the registry.
8577
- *
8578
- * Walks from the catalog to load all referenced objects.
8579
- */
8580
- private ensureObjectsLoaded;
8581
8650
  }
8582
8651
  //#endregion
8583
8652
  //#region src/signatures/signers/crypto-key.d.ts
@@ -8727,35 +8796,50 @@ declare class GoogleKmsSigner implements Signer {
8727
8796
  */
8728
8797
  static create(options: GoogleKmsSignerOptions): Promise<GoogleKmsSigner>;
8729
8798
  /**
8730
- * Load a certificate from Google Secret Manager.
8799
+ * Loads a signing certificate from Google Secret Manager for use with KMS-based signing.
8731
8800
  *
8732
- * The secret must contain a DER-encoded certificate. PEM format is NOT supported -
8733
- * convert to DER before storing in Secret Manager.
8801
+ * This helper retrieves certificate material securely stored in Secret Manager, supporting
8802
+ * both PEM and DER formats:
8803
+ * - If the secret contains PEM-encoded data, all certificates will be parsed.
8804
+ * The first is used as the signing cert (`cert`), and the remainder returned as
8805
+ * the optional `chain` (intermediates).
8806
+ * - If the secret contains raw DER data, it is returned as the signing cert (`cert`).
8734
8807
  *
8735
- * Supports cross-project access: the secret can be in a different GCP project
8736
- * than the KMS key.
8808
+ * Supports cross-project use: the secret may be in a different GCP project than the KMS key.
8737
8809
  *
8738
- * @param secretVersionName - Full resource name, e.g.
8739
- * "projects/my-project/secrets/my-cert/versions/latest"
8740
- * @param options - Optional client configuration
8741
- * @throws {KmsSignerError} if @google-cloud/secret-manager is not installed
8810
+ * - The secret should contain the certificate in binary DER (recommended) or PEM format.
8811
+ * - Private keys must never be stored in Secret Manager.
8812
+ *
8813
+ * @param secretVersionName Full resource name for the secret version,
8814
+ * e.g. "projects/my-project/secrets/my-cert/versions/latest"
8815
+ * @param options Optional client configuration, including a SecretManagerServiceClient instance.
8816
+ * @returns An object with `cert` (main certificate bytes) and optional `chain` (intermediates).
8817
+ * @throws {KmsSignerError} if @google-cloud/secret-manager is not installed or retrieval fails.
8742
8818
  *
8743
8819
  * @example
8744
- * ```typescript
8745
- * // From same project
8746
- * const cert = await GoogleKmsSigner.getCertificateFromSecretManager(
8820
+ * // Load a certificate from the same project
8821
+ * const { cert } = await GoogleKmsSigner.getCertificateFromSecretManager(
8747
8822
  * "projects/my-project/secrets/signing-cert/versions/latest"
8748
8823
  * );
8749
8824
  *
8750
- * // From different project (cross-project access)
8751
- * const cert = await GoogleKmsSigner.getCertificateFromSecretManager(
8752
- * "projects/shared-certs-project/secrets/signing-cert/versions/1"
8825
+ * // Load from a different project (cross-project access)
8826
+ * const { cert, chain } = await GoogleKmsSigner.getCertificateFromSecretManager(
8827
+ * "projects/shared-certs-project/secrets/org-ca-cert/versions/1"
8753
8828
  * );
8754
- * ```
8829
+ *
8830
+ * // Use the result with KMS-based signing
8831
+ * const signer = await GoogleKmsSigner.create({
8832
+ * keyVersionName: "...",
8833
+ * certificate: cert,
8834
+ * chain,
8835
+ * });
8755
8836
  */
8756
8837
  static getCertificateFromSecretManager(secretVersionName: string, options?: {
8757
8838
  client?: SecretManagerServiceClient;
8758
- }): Promise<Uint8Array>;
8839
+ }): Promise<{
8840
+ cert: Uint8Array;
8841
+ chain?: Uint8Array[];
8842
+ }>;
8759
8843
  /**
8760
8844
  * Sign data using the KMS key.
8761
8845
  *
@@ -8968,6 +9052,67 @@ declare class HttpTimestampAuthority implements TimestampAuthority {
8968
9052
  private parseTimestampResponse;
8969
9053
  }
8970
9054
  //#endregion
9055
+ //#region src/fonts/standard-14-font.d.ts
9056
+ /**
9057
+ * A wrapper class for Standard 14 fonts that provides measurement methods.
9058
+ *
9059
+ * Standard 14 fonts don't need to be embedded - they're built into PDF readers.
9060
+ * This class provides the same measurement API as EmbeddedFont.
9061
+ */
9062
+ declare class Standard14Font {
9063
+ /** The Standard 14 font name */
9064
+ readonly name: Standard14FontName;
9065
+ /** Cached metrics */
9066
+ private readonly metrics;
9067
+ private constructor();
9068
+ /**
9069
+ * Create a Standard14Font instance.
9070
+ *
9071
+ * @param name - The Standard 14 font name (e.g., "Helvetica", "Times-Bold")
9072
+ * @returns Standard14Font instance
9073
+ * @throws {Error} if name is not a valid Standard 14 font
9074
+ *
9075
+ * @example
9076
+ * ```typescript
9077
+ * const helvetica = Standard14Font.of("Helvetica");
9078
+ * const timesBold = Standard14Font.of("Times-Bold");
9079
+ * ```
9080
+ */
9081
+ static of(name: Standard14FontName): Standard14Font;
9082
+ /**
9083
+ * Get width of text in points at a given font size.
9084
+ *
9085
+ * @param text - The text to measure
9086
+ * @param size - Font size in points
9087
+ * @returns Width in points
9088
+ */
9089
+ widthOfTextAtSize(text: string, size: number): number;
9090
+ /**
9091
+ * Get the height of the font at a given size.
9092
+ *
9093
+ * This returns the full height from descender to ascender.
9094
+ *
9095
+ * @param size - Font size in points
9096
+ * @returns Height in points
9097
+ */
9098
+ heightAtSize(size: number): number;
9099
+ /**
9100
+ * Calculate font size needed to achieve a specific text height.
9101
+ *
9102
+ * @param height - Desired height in points
9103
+ * @returns Font size in points
9104
+ */
9105
+ sizeAtHeight(height: number): number;
9106
+ /**
9107
+ * Calculate font size needed for text to fit a specific width.
9108
+ *
9109
+ * @param text - The text to measure
9110
+ * @param width - Desired width in points
9111
+ * @returns Font size in points
9112
+ */
9113
+ sizeAtWidth(text: string, width: number): number;
9114
+ }
9115
+ //#endregion
8971
9116
  //#region src/api/drawing/text-layout.d.ts
8972
9117
  /**
8973
9118
  * A single line of laid out text.
@@ -9095,5 +9240,5 @@ declare function isWidgetAnnotation(dict: PdfDict): boolean;
9095
9240
  */
9096
9241
  declare function isPopupAnnotation(dict: PdfDict): boolean;
9097
9242
  //#endregion
9098
- 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, 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, type Standard14FontName, StandardFonts, type SubFilter, 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 };
9243
+ 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, 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 };
9099
9244
  //# sourceMappingURL=index.d.mts.map