mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #16938 from calixteman/update_struct_tree
[Editor] Add the ability to create/update the structure tree when saving a pdf containing newly added annotations (bug 1845087)
This commit is contained in:
commit
3afb717eed
8 changed files with 613 additions and 14 deletions
|
@ -2297,6 +2297,114 @@ describe("api", function () {
|
|||
await loadingTask.destroy();
|
||||
});
|
||||
|
||||
it("write a new stamp annotation in a tagged pdf, save and check that the structure tree", async function () {
|
||||
if (isNodeJS) {
|
||||
pending("Cannot create a bitmap from Node.js.");
|
||||
}
|
||||
|
||||
const TEST_IMAGES_PATH = "../images/";
|
||||
const filename = "firefox_logo.png";
|
||||
const path = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
||||
|
||||
const response = await fetch(path);
|
||||
const blob = await response.blob();
|
||||
const bitmap = await createImageBitmap(blob);
|
||||
|
||||
let loadingTask = getDocument(buildGetDocumentParams("bug1823296.pdf"));
|
||||
let pdfDoc = await loadingTask.promise;
|
||||
pdfDoc.annotationStorage.setValue("pdfjs_internal_editor_0", {
|
||||
annotationType: AnnotationEditorType.STAMP,
|
||||
rect: [128, 400, 148, 420],
|
||||
rotation: 0,
|
||||
bitmap,
|
||||
bitmapId: "im1",
|
||||
pageIndex: 0,
|
||||
structTreeParentId: "p3R_mc12",
|
||||
accessibilityData: {
|
||||
type: "Figure",
|
||||
alt: "Hello World",
|
||||
},
|
||||
});
|
||||
|
||||
const data = await pdfDoc.saveDocument();
|
||||
await loadingTask.destroy();
|
||||
|
||||
loadingTask = getDocument(data);
|
||||
pdfDoc = await loadingTask.promise;
|
||||
const page = await pdfDoc.getPage(1);
|
||||
const tree = await page.getStructTree();
|
||||
const leaf = tree.children[0].children[6].children[1];
|
||||
|
||||
expect(leaf).toEqual({
|
||||
role: "Figure",
|
||||
children: [
|
||||
{
|
||||
type: "annotation",
|
||||
id: "pdfjs_internal_id_477R",
|
||||
},
|
||||
],
|
||||
alt: "Hello World",
|
||||
});
|
||||
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
|
||||
it("write a new stamp annotation in a non-tagged pdf, save and check that the structure tree", async function () {
|
||||
if (isNodeJS) {
|
||||
pending("Cannot create a bitmap from Node.js.");
|
||||
}
|
||||
|
||||
const TEST_IMAGES_PATH = "../images/";
|
||||
const filename = "firefox_logo.png";
|
||||
const path = new URL(TEST_IMAGES_PATH + filename, window.location).href;
|
||||
|
||||
const response = await fetch(path);
|
||||
const blob = await response.blob();
|
||||
const bitmap = await createImageBitmap(blob);
|
||||
|
||||
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
|
||||
let pdfDoc = await loadingTask.promise;
|
||||
pdfDoc.annotationStorage.setValue("pdfjs_internal_editor_0", {
|
||||
annotationType: AnnotationEditorType.STAMP,
|
||||
rect: [128, 400, 148, 420],
|
||||
rotation: 0,
|
||||
bitmap,
|
||||
bitmapId: "im1",
|
||||
pageIndex: 0,
|
||||
structTreeParentId: null,
|
||||
accessibilityData: {
|
||||
type: "Figure",
|
||||
alt: "Hello World",
|
||||
},
|
||||
});
|
||||
|
||||
const data = await pdfDoc.saveDocument();
|
||||
await loadingTask.destroy();
|
||||
|
||||
loadingTask = getDocument(data);
|
||||
pdfDoc = await loadingTask.promise;
|
||||
const page = await pdfDoc.getPage(1);
|
||||
const tree = await page.getStructTree();
|
||||
|
||||
expect(tree).toEqual({
|
||||
children: [
|
||||
{
|
||||
role: "Figure",
|
||||
children: [
|
||||
{
|
||||
type: "annotation",
|
||||
id: "pdfjs_internal_id_18R",
|
||||
},
|
||||
],
|
||||
alt: "Hello World",
|
||||
},
|
||||
],
|
||||
role: "Root",
|
||||
});
|
||||
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
|
||||
describe("Cross-origin", function () {
|
||||
let loadingTask;
|
||||
function _checkCanLoad(expectSuccess, filename, options) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue