Files
pdf.js/web/external_services.js
calixteman c3c21fa894 Use platform print-to-PDF for FreeText appearances (bug 1794809)
PDF.js creates FreeText appearances with Helvetica and WinAnsiEncoding. It
cannot generate a matching appearance when Helvetica cannot encode the text.

Add a Firefox-only `printToPDF` callback to `saveDocument`. The worker batches
serialized FreeText entries and imports one generated PDF page per appearance.
The single-PDF batch preserves resources shared across pages.

Copy each page's resources and content without reserializing retained
operators. Drop marked-content operators because their metadata belongs to the
generated PDF.
2026-09-06 21:29:59 +02:00

85 lines
2.4 KiB
JavaScript

/* Copyright 2024 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class BaseExternalServices {
constructor() {
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
this.constructor === BaseExternalServices
) {
throw new Error("Cannot initialize BaseExternalServices.");
}
}
updateFindControlState(data) {}
updateFindMatchesCount(data) {}
initPassiveLoading() {}
reportTelemetry(data) {}
reportText(data) {}
/**
* @returns {Promise<L10n>}
*/
async createL10n() {
throw new Error("Not implemented: createL10n");
}
createScripting() {
throw new Error("Not implemented: createScripting");
}
createSignatureStorage() {
throw new Error("Not implemented: createSignatureStorage");
}
/**
* Build a signature verifier for the Digital signature properties panel.
*
* The MOZCENTRAL build returns a verifier that calls into NSS via
* the chrome bridge. The default GENERIC implementation returns
* `null` — there is no portable cryptographic verification path
* outside Firefox, so the toolbar button stays hidden and the
* worker is never asked for `getSignatures()`.
*
* Downstream consumers of `pdfjs-dist` that want the Signature
* Properties UI should subclass `BaseExternalServices` and return
* an object exposing `verify(signature)` (and optionally
* `viewCertificate(certificate)`) that resolves to a
* `VerificationResult` — see `web/firefoxcom.js` for the exact shape.
* @returns {object | null}
*/
createSignatureVerifier() {
return null;
}
/**
* Platform appearance renderer; see `PDFDocumentProxy.saveDocument`.
* @type {?function(Array<object>): Promise<Uint8Array | null>}
*/
printToPDF = null;
updateEditorStates(data) {
throw new Error("Not implemented: updateEditorStates");
}
dispatchGlobalEvent(_event) {}
}
export { BaseExternalServices };