mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-05 06:35:48 +02:00
Avoid to add outlines having a deleted page which leads to clone a useless page (bug 2033908)
This commit is contained in:
parent
fe48736846
commit
a52c8334f5
@ -1452,9 +1452,12 @@ class PDFEditor {
|
|||||||
result.push({
|
result.push({
|
||||||
...item,
|
...item,
|
||||||
// When the item's own destination is invalid (but it has surviving
|
// When the item's own destination is invalid (but it has surviving
|
||||||
// children), clear the destination so the output item is a plain
|
// children), clear the destination and rawDict so the output item is
|
||||||
// container rather than a broken link.
|
// a plain container rather than a broken link. Clearing rawDict
|
||||||
|
// prevents #setOutlineItemDest from cloning a GoTo action that
|
||||||
|
// references a deleted page via its D array.
|
||||||
dest: hasValidOwnDest ? item.dest : null,
|
dest: hasValidOwnDest ? item.dest : null,
|
||||||
|
rawDict: hasValidOwnDest ? item.rawDict : null,
|
||||||
items: filteredChildren,
|
items: filteredChildren,
|
||||||
_documentData: documentData,
|
_documentData: documentData,
|
||||||
});
|
});
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -886,6 +886,7 @@
|
|||||||
!outlines_se.pdf
|
!outlines_se.pdf
|
||||||
!radial_gradients.pdf
|
!radial_gradients.pdf
|
||||||
!outlines_for_editor.pdf
|
!outlines_for_editor.pdf
|
||||||
|
!outline_goto_action.pdf
|
||||||
!mesh_shading_empty.pdf
|
!mesh_shading_empty.pdf
|
||||||
!acroform_calculation_order.pdf
|
!acroform_calculation_order.pdf
|
||||||
!extractPages_null_in_array.pdf
|
!extractPages_null_in_array.pdf
|
||||||
|
|||||||
BIN
test/pdfs/outline_goto_action.pdf
Normal file
BIN
test/pdfs/outline_goto_action.pdf
Normal file
Binary file not shown.
@ -6971,6 +6971,41 @@ small scripts as well as for`);
|
|||||||
|
|
||||||
await newLoadingTask.destroy();
|
await newLoadingTask.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle parent items whose dest was cleared but rawDict still holds a GoTo action (bug 2033603)", async function () {
|
||||||
|
// outline_goto_action.pdf has 2 pages and this outline:
|
||||||
|
// "Parent" /A << /S /GoTo /D [page1Ref /FitH 842] >>
|
||||||
|
// "Child" /Dest [page2Ref /FitH 0]
|
||||||
|
const loadingTask = getDocument(
|
||||||
|
buildGetDocumentParams("outline_goto_action.pdf")
|
||||||
|
);
|
||||||
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const data = await pdfDoc.extractPages([
|
||||||
|
{ document: null, includePages: [1] },
|
||||||
|
]);
|
||||||
|
await loadingTask.destroy();
|
||||||
|
|
||||||
|
const newLoadingTask = getDocument(data);
|
||||||
|
const newPdfDoc = await newLoadingTask.promise;
|
||||||
|
expect(newPdfDoc.numPages).toEqual(1);
|
||||||
|
|
||||||
|
const outline = await newPdfDoc.getOutline();
|
||||||
|
expect(Array.isArray(outline)).toEqual(true);
|
||||||
|
expect(outline.length).toEqual(1);
|
||||||
|
|
||||||
|
// "Parent" is kept as a plain container (dest cleared, no action).
|
||||||
|
const parent = outline[0];
|
||||||
|
expect(parent.title).toEqual("Parent");
|
||||||
|
expect(parent.dest).toEqual(null);
|
||||||
|
expect(parent.items.length).toEqual(1);
|
||||||
|
|
||||||
|
// "Child" keeps its explicit dest pointing to the (only) kept page.
|
||||||
|
const child = parent.items[0];
|
||||||
|
expect(child.title).toEqual("Child");
|
||||||
|
expect(Array.isArray(child.dest)).toEqual(true);
|
||||||
|
|
||||||
|
await newLoadingTask.destroy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("extract pages with null values in arrays", function () {
|
describe("extract pages with null values in arrays", function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user