: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
this._current = this._builder.buildRoot(this._ids);
this._errorCode = XMLParserErrorCode.NoError;
this._whiteRegex = /^\s+$/;
this._richText = richText;
if (this._errorCode !== XMLParserErrorCode.NoError) {
this._current[$finalize]();
return this._current.element;
text = text.replace(this._nbsps, match => match.slice(1) + " ");
if (this._richText || this._current[$acceptWhitespace]()) {
this._current[$onText](text, this._richText);
if (this._whiteRegex.test(text)) {
this._current[$onText](text.trim());
this._current[$onText](text);
_mkAttributes(attributes, tagName) {
const attributeObj = Object.create({});
warn(`XFA - multiple namespace definition in <${tagName}>`);
} else if (name.startsWith("xmlns:")) {
const prefix = name.substring("xmlns:".length);
const i = name.indexOf(":");
attributeObj[name] = value;
let nsAttrs = attributeObj[$nsAttributes];
nsAttrs = attributeObj[$nsAttributes] = Object.create(null);
const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)];
const attrs = nsAttrs[ns] ||= Object.create(null);
return [namespace, prefixes, attributeObj];
_getNameAndPrefix(name, nsAgnostic) {
const i = name.indexOf(":");
return [name.substring(i + 1), nsAgnostic ? "" : name.substring(0, i)];
onBeginElement(tagName, attributes, isEmpty) {
const [namespace, prefixes, attributesObj] = this._mkAttributes(attributes, tagName);
const [name, nsPrefix] = this._getNameAndPrefix(tagName, this._builder.isNsAgnostic());
const node = this._builder.build({
attributes: attributesObj,
node[$globalData] = this._globalData;
if (this._current[$onChild](node)) {
node[$clean](this._builder);
this._stack.push(this._current);
const node = this._current;
if (node[$isCDATAXml]() && typeof node[$content] === "string") {
const parser = new XFAParser();
parser._globalData = this._globalData;
const root = parser.parse(node[$content]);
this._current = this._stack.pop();
if (this._current[$onChild](node)) {
node[$clean](this._builder);
;// CONCATENATED MODULE: ./src/core/xfa/factory.js
this.root = new XFAParser().parse(XFAFactory._createDocument(data));
const binder = new Binder(this.root);
this.form = binder.bind();
this.dataHandler = new DataHandler(this.root, binder.getData());
this.form[$globalData].template = this.form;
warn(`XFA - an error occurred during parsing and binding: ${e}`);
return this.root && this.form;
const iterator = this.form[$toPages]();
return new Promise((resolve, reject) => {
const nextIteration = () => {
const value = iterator.next();
setTimeout(nextIteration, 0);
setTimeout(nextIteration, 0);
this.pages = await this._createPagesHelper();
this.dims = this.pages.children.map(c => {
return [0, 0, parseInt(width), parseInt(height)];
warn(`XFA - an error occurred during layout: ${e}`);
getBoundingBox(pageIndex) {
return this.dims[pageIndex];
await this._createPages();
this.form[$globalData].images = images;
this.form[$globalData].fontFinder = new FontFinder(fonts);
for (let typeface of this.form[$globalData].usedTypefaces) {
typeface = stripQuotes(typeface);
const font = this.form[$globalData].fontFinder.find(typeface);
missingFonts.push(typeface);
if (missingFonts.length > 0) {
appendFonts(fonts, reallyMissingFonts) {
this.form[$globalData].fontFinder.add(fonts, reallyMissingFonts);
await this._createPages();
const pages = this.pages;
return this.dataHandler.serialize(storage);
static _createDocument(data) {
return Object.values(data).join("");
static getRichTextAsHtml(rc) {
if (!rc || typeof rc !== "string") {
let root = new XFAParser(XhtmlNamespace, true).parse(rc);
if (!["body", "xhtml"].includes(root[$nodeName])) {
const newRoot = XhtmlNamespace.body({});
newRoot[$appendChild](root);
const result = root[$toHTML]();
attributes.class = attributes.class.filter(attr => !attr.startsWith("xfa"));
warn(`XFA - an error occurred during parsing of rich text: ${e}`);
;// CONCATENATED MODULE: ./src/core/annotation.js
class AnnotationFactory {
static createGlobals(pdfManager) {
return Promise.all([pdfManager.ensureCatalog("acroForm"), pdfManager.ensureDoc("xfaDatasets"), pdfManager.ensureCatalog("structTreeRoot"), pdfManager.ensureCatalog("baseUrl"), pdfManager.ensureCatalog("attachments")]).then(([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => {
acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
warn(`createGlobals: "${reason}".`);
static async create(xref, ref, annotationGlobals, idFactory, collectFields, pageRef) {
const pageIndex = collectFields ? await this._getPageIndex(xref, ref, annotationGlobals.pdfManager) : null;
return annotationGlobals.pdfManager.ensure(this, "_create", [xref, ref, annotationGlobals, idFactory, collectFields, pageIndex, pageRef]);
static _create(xref, ref, annotationGlobals, idFactory, collectFields = false, pageIndex = null, pageRef = null) {
const dict = xref.fetchIfRef(ref);
if (!(dict instanceof Dict)) {
const id = ref instanceof Ref ? ref.toString() : `annot_${idFactory.createObjId()}`;
let subtype = dict.get("Subtype");
subtype = subtype instanceof Name ? subtype.name : null;
needAppearances: !collectFields && acroForm.get("NeedAppearances") === true,
evaluatorOptions: pdfManager.evaluatorOptions,
return new LinkAnnotation(parameters);
return new TextAnnotation(parameters);
let fieldType = getInheritableProperty({
fieldType = fieldType instanceof Name ? fieldType.name : null;
return new TextWidgetAnnotation(parameters);
return new ButtonWidgetAnnotation(parameters);
return new ChoiceWidgetAnnotation(parameters);
return new SignatureWidgetAnnotation(parameters);
warn(`Unimplemented widget field type "${fieldType}", ` + "falling back to base field type.");
return new WidgetAnnotation(parameters);
return new PopupAnnotation(parameters);
return new FreeTextAnnotation(parameters);
return new LineAnnotation(parameters);
return new SquareAnnotation(parameters);
return new CircleAnnotation(parameters);
return new PolylineAnnotation(parameters);
return new PolygonAnnotation(parameters);
return new CaretAnnotation(parameters);
return new InkAnnotation(parameters);
return new HighlightAnnotation(parameters);
return new UnderlineAnnotation(parameters);
return new SquigglyAnnotation(parameters);
return new StrikeOutAnnotation(parameters);
return new StampAnnotation(parameters);
return new FileAttachmentAnnotation(parameters);
warn("Annotation is missing the required /Subtype.");
warn(`Unimplemented annotation type "${subtype}", ` + "falling back to base annotation.");
return new Annotation(parameters);
static async _getPageIndex(xref, ref, pdfManager) {
const annotDict = await xref.fetchIfRefAsync(ref);
if (!(annotDict instanceof Dict)) {
const pageRef = annotDict.getRaw("P");
if (pageRef instanceof Ref) {
const pageIndex = await pdfManager.ensureCatalog("getPageIndex", [pageRef]);
info(`_getPageIndex -- not a valid page reference: "${ex}".`);
if (annotDict.has("Kids")) {
const numPages = await pdfManager.ensureDoc("numPages");
for (let pageIndex = 0; pageIndex < numPages; pageIndex++) {
const page = await pdfManager.getPage(pageIndex);
const annotations = await pdfManager.ensure(page, "annotations");
for (const annotRef of annotations) {
if (annotRef instanceof Ref && isRefsEqual(annotRef, ref)) {
warn(`_getPageIndex: "${ex}".`);
static generateImages(annotations, xref, isOffscreenCanvasSupported) {
if (!isOffscreenCanvasSupported) {
warn("generateImages: OffscreenCanvas is not supported, cannot save or print some annotations with images.");
imagePromises ||= new Map();
imagePromises.set(bitmapId, StampAnnotation.createImage(bitmap, xref));
static async saveNewAnnotations(evaluator, task, annotations, imagePromises) {
const xref = evaluator.xref;
isOffscreenCanvasSupported
for (const annotation of annotations) {
if (annotation.deleted) {
switch (annotation.annotationType) {
case AnnotationEditorType.FREETEXT:
const baseFont = new Dict(xref);
baseFont.set("BaseFont", Name.get("Helvetica"));
baseFont.set("Type", Name.get("Font"));
baseFont.set("Subtype", Name.get("Type1"));
baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
baseFontRef = xref.getNewTemporaryRef();
await writeObject(baseFontRef, baseFont, buffer, xref);
promises.push(FreeTextAnnotation.createNewAnnotation(xref, annotation, dependencies, {
case AnnotationEditorType.HIGHLIGHT:
if (annotation.quadPoints) {
promises.push(HighlightAnnotation.createNewAnnotation(xref, annotation, dependencies));
promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
case AnnotationEditorType.INK:
promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
case AnnotationEditorType.STAMP: