Skip to content

native-v7.3.0

Latest

Choose a tag to compare

@github-actions github-actions released this 21 Nov 23:30
· 10 commits to develop since this release
native-v7.3.0
b67fdd1

Changelog

Breaking Changes

  • Recipe info() without arguments reports the custom keys of a source PDF
    in their own spelling, as the PDF stores them, instead of lower-cased:
    info().reportid is now info().ReportId; see
    Breaking Changes
    #996
  • Recipe info() without arguments returns {} for a new PDF, and for a
    source without an Info dictionary, instead of undefined, and includes the
    values set on the Recipe, as @muhammara/wasm
    does; see
    Breaking Changes
    #996
  • Recipe custom() with title, author, subject or keywords sets that
    field, as info() and @muhammara/wasm do, instead of writing a custom
    /title entry; see
    Breaking Changes
    #996
  • Recipe info() and custom() throw a TypeError for Trapped, the
    source-Creator, source-Producer and source-ModDate entries and an empty
    key, which used to write custom entries. Recipe writes these itself; use
    another key. Trapped is only carried over from a source PDF; see
    Breaking Changes
    #996
  • Recipe info(options) after endPDF() throws PDF writer has ended, as
    @muhammara/wasm does, instead of ignoring the values; set them before
    endPDF() #996
  • The native packages need Node.js 20.19 or later on the 20 line, or 22.12 or
    later on the 22 line. The line-breaking dependency linebreak 2.0.0 is
    ESM-only, so an older Node.js fails require("@muhammara/native") with
    ERR_REQUIRE_ESM. Upgrade Node.js; see
    Breaking Changes

Added

  • Write PDF/A documents with the new pdfa Recipe option,
    { level, iccProfile, outputCondition }: PDF/A-1b, 2b, 2u, 3b, 3u, 4, 4e
    and 4f (Recipe.PdfA), with the PDF version of the level, XMP metadata that
    identifies it, and an output intent with the caller's ICC profile, given as
    a Buffer or a path. Recipe throws where the document would not conform:
    transparency in PDF/A-1, colors the profile does not describe, hidden
    annotations, annotations without an appearance stream from PDF/A-2 on,
    custom Info entries in PDF/A-4, and encryption; see
    Write PDF/A Documents #1000
  • Attach files to a new PDF with Recipe attach(name, file, options), with a
    MIME type, a description, and how each file relates to the document
    (Recipe.AFRelationship) #1000
  • Remove the creation or modification date of an Info dictionary with
    setCreationDate(null) and setModDate(null) #1000
  • Write XMP metadata that mirrors the Info dictionary with the new xmp option
    of Recipe, and read the XMP packet of a source PDF with recipe.xmp(). An
    edit keeps the existing packet, or, with xmp: true, replaces it with one
    built from the Info values the PDF is written with
    #996
  • Draw right-to-left text such as Hebrew in visual order when writeText()
    or Recipe text() is given the new direction option (TextDirection /
    Recipe.TextDirection). "auto" takes each paragraph's direction from its
    first strong letter, and "ltr" and "rtl" set it. Text is reordered with
    the Unicode Bidirectional Algorithm (bidi-js,
    MIT, a new dependency of @muhammara/native-core): numbers and Latin
    words inside Hebrew keep their order, brackets
    are mirrored, points are drawn on their letters, and invisible direction
    marks are neither drawn nor measured. Recipe reorders each wrapped line with the direction and levels of its
    whole paragraph, also across the styled runs of an HTML line,
    places justified words from right to left, and ends the last line of a
    justified right-to-left paragraph at the right edge; textDimensions()
    takes the same option, and table() takes it for the table and each
    column, whose headers take it too. The default, "none", draws text exactly as given,
    as before; see Write Right-to-Left Text
    #330
  • Support Electron 39 through 44 on macOS x64, which used to stop at 38.1
    #984
  • Strike out <s> and <strike> text in Recipe HTML, as <del> already does
    #936
  • Add Recipe formFields() to list the AcroForm fields of an existing PDF
    with their object IDs, fully qualified names, kinds, values, flags, options
    and widgets, and the Recipe.FormFieldKind and Recipe.FormFieldFlag
    constants to compare them against
    #992
  • Add Recipe fillForm() to fill text, checkbox, radio, combo box and list
    box fields of an existing PDF by name or id, drawing a new appearance
    stream for each changed widget, or setting /NeedAppearances with
    appearances: "viewer", dropping the /XFA of a form that also has
    fields, and the Recipe.FormAppearances constant
    #992

Fixed

  • Throw "The Recipe has no source PDF to read" from Recipe structure() for a new PDF instead of claiming the reader was released by endPDF() #1016
  • A dictionary's writeKey() and write*Value() methods throw
    Dictionary context is no longer active after the dictionary was passed to
    ObjectsContext.endDictionary(), startPDFStream() or
    startUnfilteredPDFStream(). Passing such a dictionary, or one of another
    writer that has ended, to startPDFStream() or startUnfilteredPDFStream()
    throws a TypeError Provide the active dictionary context, as
    @muhammara/wasm does; so does a dictionary of a writer event that has
    returned. Before, these calls terminated the process or wrote after the
    dictionary's end
    #1039
  • ObjectsContext.startPDFStream() and startUnfilteredPDFStream() throw a
    TypeError Provide the active dictionary context for an open dictionary
    that is not the innermost one startDictionary() opened: an outer
    dictionary while an inner one is open, a dictionary of another writer, or a
    writer event's dictionary while the event runs. startPDFStream() throws
    Unable to start PDF stream for a dictionary that already has the /Length
    key, or the /Filter key while compression is on, and
    startUnfilteredPDFStream() throws Unable to start unfiltered PDF stream
    for one that has /Length. The errors match @muhammara/wasm.
    Before, the returned stream terminated the process on use, and a writer
    event's dictionary made writePage() fail or wrote an unreadable PDF
    #1055
  • Decrypt PDFs whose crypt filter selects RC4 with /CFM /V2, the name the
    PDF specification uses. Their strings and streams were returned still
    encrypted, and recrypt() wrote them out unchanged
    #1026
  • Read the document's XMP metadata stream (the catalog's /Metadata) of an
    encrypted PDF that keeps its metadata unencrypted (/EncryptMetadata false)
    as stored, instead of decrypting it into unreadable bytes, so recrypt()
    keeps the packet intact
    #1027
  • Decrypt streams that name their own crypt filter (/Filter /Crypt) when
    they are copied from an encrypted PDF (appendPDFPagesFromPDF(),
    mergePDFPagesToPage(), createFormXObjectsFromPDF(),
    createPDFCopyingContext(), recrypt(), Recipe appendPage()), and drop
    that filter from the copy, instead of copying the encrypted bytes that
    readers cannot decode
    #1028
  • writeLiteralString(), writeHexString(), startPDFStream() and
    startUnfilteredPDFStream() of the objects context, a dictionary's
    writeLiteralStringValue(), and a copying context's copyDirectObjectAsIs()
    and copyDirectObjectWithDeepCopy() throw an Error when a writer created
    with a password has no indirect object open, instead of terminating the
    process. On a writer created with version: ePDFVersion20, and for direct
    copies that contain no strings, these calls used to succeed and now throw as
    well; call startNewIndirectObject() first
    #1029
  • ObjectsContext.endIndirectObject() throws Unable to end indirect object
    when no indirect object is open, as @muhammara/wasm does. Before, it wrote
    a stray endobj, and on a writer with a password it aborted the process
    #1030
  • ObjectsContext.endIndirectObject() right after endPDFStream(), which
    already ends the object, writes nothing. Before, it wrote a second endobj,
    which also appeared in Recipe replaceText() output
    #1030
  • ObjectsContext.startNewIndirectObject() and startModifiedIndirectObject()
    throw Unable to start indirect object and
    Unable to start modified indirect object while another indirect object is
    open or when the object cannot be started, such as an ID that is already
    written, and a RangeError Object ID must be positive for ID 0, as
    @muhammara/wasm does. Before, they wrote a nested object or failed
    silently #1030
  • Recipe editPage() throws a RangeError for a page number that is not an
    existing page (such as 1.5, 0, a page past the end, or the string "1"),
    as @muhammara/wasm does, instead of an internal TypeError
    #1023
  • Open a Recipe from a Uint8Array or an ArrayBuffer source, and read()
    one, as @muhammara/wasm does, instead of throwing
    src.toLowerCase is not a function or Unable to start parsing PDF file;
    another non-string source throws a TypeError that names the accepted types
    #1009
  • Decrypt strings and streams correctly when a PDF encrypted with RC4 or
    AES-128 (security handler revision 2 to 4) is opened with its owner password,
    instead of returning garbled text without an error. AES-256 was not affected
    #1002
  • Set the field when Recipe info() or custom() gets the Info name of a
    standard field, such as Title, instead of writing a value without a key,
    which broke or overrode the Info dictionary. Creator, Producer, CreationDate
    and ModDate,
    which Recipe writes itself, throw a TypeError before any entry is set
    #996
  • Keep the custom entries of a source PDF that are named like Recipe's own
    fields (creator, modDate, trapped) when Recipe edits it, and write the
    source-Creator, source-Producer and source-ModDate of the edited source
    over those it carries from an earlier edit, as @muhammara/wasm does
    #996
  • Start the objects that native Recipe appends to an output file when it writes
    annotations on their own line, after the %%EOF of the first pass, as PDF/A
    requires #1000
  • Keep the custom text Info entries of a source PDF, empty ones included, in their
    original spelling when Recipe edits it. They used to be dropped by the next
    edit
    #996
  • Keep the custom Info entries set with Recipe info() or custom() when the
    Recipe also writes annotations. They used to be dropped
    #996
  • Keep a title, author, subject or keywords set through the low-level writer
    of a Recipe that edits a PDF, as @muhammara/wasm does. endPDF() used to
    write the value of the source over it
    #996
  • Leave a custom Recipe info() value that is null or undefined out of the
    PDF instead of writing the text null or undefined, as @muhammara/wasm
    does #996
  • Write a Recipe keywords array, and an array passed to custom(), as
    comma-and-space-separated text, as @muhammara/wasm does, instead of a,b
    #996
  • Turn a rotated Recipe rectangle() without rotationOrigin around its
    top-left corner, as documented and as in @muhammara/wasm, instead of its
    bottom-left corner. Pass rotationOrigin: [x, y + height] to keep the old
    pivot #923
  • Apply rotation in Recipe line(), clockwise around its first point or
    rotationOrigin, as in @muhammara/wasm. The option was validated but the
    line was drawn unrotated #925
  • Draw a stroked Recipe circle() with rotation. Its placing matrix had
    nan offsets, which PDF viewers reject #922
  • Turn Recipe text links with rotated text, so the link covers the turned text
    instead of the unrotated line box #926
  • Keep the box padding in Recipe text() with a box height or minHeight
    and a bottom or center textAlign. Bottom-aligned text ended flush with the
    box, and centered text ignored unequal padding #935
  • Wrap Recipe HTML text that follows an inline element at the text box width,
    and keep justified HTML inside its box #891, #905
  • Keep the spaces that start a line of Recipe text: in a flow before
    movedown(), and on any line that ends with a line break, also when the
    text is right or center aligned #906
  • Add the markup annotations of flowed Recipe text (highlight, underline,
    strikeOut, squiggly) over the run that sets them, instead of from the
    call that ends the flow over the whole line #909
  • Keep the first line of flowed Recipe text whose box has textBox.wrap of
    trim, clip, or ellipsis, instead of dropping runs, and stop throwing a
    TypeError when a run continues a line with ellipsis #913, #928
  • Align flowed Recipe text as the call that ends the flow sets it, as in
    @muhammara/wasm, so the runs of a line no longer overlap or leave a gap
    #918
  • Continue the open line of flowed Recipe text up to a line break in a later
    run, instead of gluing the words on either side of the break together
    #927
  • Justify flowed Recipe text line by line, with one gap width per line and a
    left-aligned last line, so runs no longer overlap or run past the box
    #929
  • Stop drawing a line feed that ends a Recipe HTML text node or an inline
    element; it ends the line instead #931
  • Lay out Recipe HTML runs with the font and size they are drawn in, so the
    run after bold or italic text no longer overlaps it, bold and italic lines
    get their face's baseline and line height, and h1–h3 and small text
    wraps at its own size #937
  • End a flowed Recipe line at every paragraph separator that ends a run:
    \r, vertical tab, form feed, U+0085, U+2028 and U+2029 no
    longer draw as missing glyphs with the next run on the same line, as \n
    already did, text written after a flow that ends with one starts below
    the flow instead of over its last line, and a plain line ending in U+0085
    no longer ends a missing glyph short of the right edge
    #330
  • Keep the spaces a Recipe line starts with when a line break ends it, in a
    text box or a flow, or movedown() ends a flowed line, as Wasm does; they
    were dropped only on such lines, and so was the space a later run on such
    a line starts with, so styled or flowed runs touched
    #330
  • Keep the space that the first element of a flowed HTML run starts with,
    as in <span> 6 7</span>, inside that element, as Wasm does; it was
    dropped, so the run touched the text before it
    #330
  • Keep a figure space (U+2007) or a narrow no-break space (U+202F) at the
    start and end of a Recipe line, as the no-break space (U+00A0) already was
    and as Wasm does #330
  • Write no link annotation without width for Recipe text, such as for a run
    of only spaces at the end of a line or a justified HTML line whose link
    ended before it started, as Wasm does
    #330
  • Lay out a long Recipe text flow in time that grows with its runs: each
    flowed text() call copied and searched every run the flow had, so a
    flow built word by word took time with the square of its words
    #330
  • Measure the line height of a Recipe font once for each size instead of for
    every text() call, which took about a millisecond each
    #330
  • Write the Recipe structure() of a PDF without an Info dictionary, such as
    one written by pdf-lib, instead of throwing
    Cannot read properties of undefined (reading 'getType'); trailer entries
    the PDF lacks are skipped
    #1008
  • Reference the Node.js types from the native type declarations, so TypeScript
    6 and later resolve Buffer, EventEmitter and NodeJS in
    @muhammara/native without "node" in compilerOptions.types
  • Keep the Info entries of the source, such as Title, Author and custom
    entries, in a PDF modified with the low-level createWriterToModify(), and
    start the writer's getDocumentContext().getInfoDictionary() with them, so
    that set values replace them. The update wrote an Info dictionary with only a
    new ModDate, and readers showed none of the others
    #1053
  • Let a custom Info entry added with addAdditionalInfoEntry() under the key
    of a field (Title, Author, Subject, Keywords, Creator, Producer,
    CreationDate, ModDate or Trapped) replace that field, on every writer,
    including createWriter(). With the field already set, the repeated key was
    refused but its value still written, so the Info dictionary could not be read
    and readers showed none of its entries
    #1053
  • Let an Info field set after a custom entry under its key replace that entry,
    on every writer: title, author, subject, keywords, creator,
    producer, trapped, setCreationDate() and setModDate() after
    addAdditionalInfoEntry() with the field's key, such as Title, also when
    they clear the field; clearing used to keep the entry. The custom value was
    still written after the field, so the Info dictionary could not be read and
    readers showed none of its entries. A trapped set that throws now leaves the
    Info dictionary as it was; it used to set Trapped to True
    #1056

Changed

  • Recipe info() of a source that needs its user password returns {}
    instead of throwing, the new xmp() returns undefined for it, and
    endPDF() throws as @muhammara/wasm does, instead of
    unable to create copying context:
    Editing a password-protected source is unsupported; decrypt it with recrypt() first
    #996
  • Test the native prebuilds up to Node.js 26.11.1 and Electron 44.7.1
    #984
  • Update the test dependency serialize-javascript (pulled in by mocha)
    from 7.1.2 to 7.1.4 for its security fix. Only the repository's tests use
    it; installed packages are unaffected.
  • Check the npm, GitHub Actions, and docs requirements dependencies weekly
    with Dependabot
    #867
  • Update the documentation-build dependency mkdocs-material from 9.7.7 to
    9.8.1. Only the repository's documentation site uses it; installed
    packages are unaffected.
  • Update the test dependencies minimatch to 11.0.9 and glob to 14.0.6
    (pulled in by mocha and jest) for the minimatch security fix
    GHSA-g3hv-75wg-m249. Only the repository's tests use them; installed
    packages are unaffected.
    #1057

Pull requests

Contributors

@julianhille

Full changelog: native-v7.2.4...native-v7.3.0