mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Correctly update the xref table when an annotation is deleted
This commit is contained in:
parent
aaa55d2b38
commit
901d995a7e
4 changed files with 131 additions and 18 deletions
|
@ -9919,5 +9919,26 @@
|
|||
"rounds": 1,
|
||||
"link": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{
|
||||
"id": "delete_freetexts",
|
||||
"file": "pdfs/freetexts.pdf",
|
||||
"md5": "da1310a25ab796c1201810070d5032a3",
|
||||
"rounds": 1,
|
||||
"type": "eq",
|
||||
"save": true,
|
||||
"print": true,
|
||||
"annotationStorage": {
|
||||
"pdfjs_internal_editor_0": {
|
||||
"deleted": true,
|
||||
"pageIndex": 0,
|
||||
"id": "26R"
|
||||
},
|
||||
"pdfjs_internal_editor_3": {
|
||||
"deleted": true,
|
||||
"pageIndex": 0,
|
||||
"id": "51R"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -247,4 +247,71 @@ describe("Writer", function () {
|
|||
expect(data).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it("should update a file with a deleted object", async function () {
|
||||
const originalData = new Uint8Array();
|
||||
const newRefs = [
|
||||
{ ref: Ref.get(123, 0x2d), data: null },
|
||||
{ ref: Ref.get(456, 0x4e), data: "abc\n" },
|
||||
];
|
||||
const xrefInfo = {
|
||||
newRef: Ref.get(789, 0),
|
||||
startXRef: 314,
|
||||
fileIds: ["id", ""],
|
||||
rootRef: null,
|
||||
infoRef: null,
|
||||
encryptRef: null,
|
||||
filename: "foo.pdf",
|
||||
info: {},
|
||||
};
|
||||
|
||||
let data = await incrementalUpdate({
|
||||
originalData,
|
||||
xrefInfo,
|
||||
newRefs,
|
||||
useXrefStream: true,
|
||||
});
|
||||
data = bytesToString(data);
|
||||
|
||||
let expected =
|
||||
"\nabc\n" +
|
||||
"789 0 obj\n" +
|
||||
"<< /Prev 314 /Size 790 /Type /XRef /Index [123 1 456 1 789 1] " +
|
||||
"/W [1 1 1] /ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)] " +
|
||||
"/Length 9>> stream\n" +
|
||||
"\x00\x00\x2e" +
|
||||
"\x01\x01\x4e" +
|
||||
"\x01\x05\x00\n" +
|
||||
"endstream\n" +
|
||||
"endobj\n" +
|
||||
"startxref\n" +
|
||||
"5\n" +
|
||||
"%%EOF\n";
|
||||
expect(data).toEqual(expected);
|
||||
|
||||
data = await incrementalUpdate({
|
||||
originalData,
|
||||
xrefInfo,
|
||||
newRefs,
|
||||
useXrefStream: false,
|
||||
});
|
||||
data = bytesToString(data);
|
||||
|
||||
expected =
|
||||
"\nabc\n" +
|
||||
"xref\n" +
|
||||
"123 1\n" +
|
||||
"0000000000 00046 f\r\n" +
|
||||
"456 1\n" +
|
||||
"0000000001 00078 n\r\n" +
|
||||
"789 1\n" +
|
||||
"0000000005 00000 n\r\n" +
|
||||
"trailer\n" +
|
||||
"<< /Prev 314 /Size 789 " +
|
||||
"/ID [(id) (\x01#Eg\x89\xab\xcd\xef\xfe\xdc\xba\x98vT2\x10)]>>\n" +
|
||||
"startxref\n" +
|
||||
"5\n" +
|
||||
"%%EOF\n";
|
||||
expect(data).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue