diff --git a/src/core/annotation.js b/src/core/annotation.js index 8224b915b..3d4cd539d 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -1894,13 +1894,11 @@ class WidgetAnnotation extends Annotation { let newTransform = null; if (encrypt) { newTransform = encrypt.createCipherTransform(newRef.num, newRef.gen); - appearance = newTransform.encryptString(appearance); } const resources = this._getSaveFieldResources(xref); const appearanceStream = new StringStream(appearance); const appearanceDict = (appearanceStream.dict = new Dict(xref)); - appearanceDict.set("Length", appearance.length); appearanceDict.set("Subtype", Name.get("Form")); appearanceDict.set("Resources", resources); appearanceDict.set("BBox", [ @@ -3669,7 +3667,6 @@ class FreeTextAnnotation extends MarkupAnnotation { appearanceStreamDict.set("Subtype", Name.get("Form")); appearanceStreamDict.set("Type", Name.get("XObject")); appearanceStreamDict.set("BBox", [0, 0, w, h]); - appearanceStreamDict.set("Length", appearance.length); appearanceStreamDict.set("Resources", resources); if (rotation) { diff --git a/src/core/writer.js b/src/core/writer.js index 51626f157..2fe03aaa3 100644 --- a/src/core/writer.js +++ b/src/core/writer.js @@ -45,13 +45,13 @@ function writeDict(dict, buffer, transform) { } function writeStream(stream, buffer, transform) { - writeDict(stream.dict, buffer, transform); - buffer.push(" stream\n"); let string = stream.getString(); if (transform !== null) { string = transform.encryptString(string); } - buffer.push(string, "\nendstream"); + stream.dict.set("Length", string.length); + writeDict(stream.dict, buffer, transform); + buffer.push(" stream\n", string, "\nendstream"); } function writeArray(array, buffer, transform) { diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 2282a3811..1a8ec3ce6 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -571,3 +571,4 @@ !autoprint.pdf !bug1811694.pdf !bug1811510.pdf +!bug1815476.pdf diff --git a/test/pdfs/bug1815476.pdf b/test/pdfs/bug1815476.pdf new file mode 100755 index 000000000..e1e38aa46 Binary files /dev/null and b/test/pdfs/bug1815476.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 173061a9b..2021bbef2 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -7332,5 +7332,22 @@ "rounds": 1, "link": true, "type": "eq" + }, + { + "id": "bug1815476-save-print", + "file": "pdfs/bug1815476.pdf", + "md5": "476f77da5f9422ef86ea5f4531602e93", + "rounds": 1, + "type": "eq", + "save": true, + "print": true, + "annotationStorage": { + "88R": { + "value": "foo" + }, + "87R": { + "value": "bar" + } + } } ] diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index fa860b3d6..b90d18a83 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -2062,8 +2062,8 @@ describe("annotation", function () { "/V (hello world) /AP << /N 2 0 R>> /M (date)>>\nendobj\n" ); expect(newData.data).toEqual( - "2 0 obj\n<< /Length 74 /Subtype /Form /Resources " + - "<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10]>> stream\n" + + "2 0 obj\n<< /Subtype /Form /Resources " + + "<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] /Length 74>> stream\n" + "/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2 3.07 Td (hello world) Tj " + "ET Q EMC\nendstream\nendobj\n" ); @@ -2108,8 +2108,8 @@ describe("annotation", function () { "/V (hello world) /MK << /R 90>> /AP << /N 2 0 R>> /M (date)>>\nendobj\n" ); expect(newData.data).toEqual( - "2 0 obj\n<< /Length 74 /Subtype /Form /Resources " + - "<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] /Matrix [0 1 -1 0 32 0]>> stream\n" + + "2 0 obj\n<< /Subtype /Form /Resources " + + "<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] /Matrix [0 1 -1 0 32 0] /Length 74>> stream\n" + "/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2 2.94 Td (hello world) Tj " + "ET Q EMC\nendstream\nendobj\n" ); @@ -2239,8 +2239,8 @@ describe("annotation", function () { `/V (\xfe\xff${utf16String}) /AP << /N 2 0 R>> /M (date)>>\nendobj\n` ); expect(newData.data).toEqual( - "2 0 obj\n<< /Length 79 /Subtype /Form /Resources " + - "<< /Font << /Helv 314 0 R /Goth 159 0 R>>>> /BBox [0 0 32 10]>> stream\n" + + "2 0 obj\n<< /Subtype /Form /Resources " + + "<< /Font << /Helv 314 0 R /Goth 159 0 R>>>> /BBox [0 0 32 10] /Length 79>> stream\n" + `/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 0 Tm 2 3.07 Td (${utf16String}) Tj ` + "ET Q EMC\nendstream\nendobj\n" ); @@ -3626,8 +3626,8 @@ describe("annotation", function () { expect(newData.data).toEqual( [ "2 0 obj", - "<< /Length 170 /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " + - "/BBox [0 0 32 10] /Matrix [0 -1 1 0 0 10]>> stream", + "<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " + + "/BBox [0 0 32 10] /Matrix [0 -1 1 0 0 10] /Length 170>> stream", "/Tx BMC q", "1 1 10 32 re W n", "0.600006 0.756866 0.854904 rg", @@ -3687,8 +3687,8 @@ describe("annotation", function () { expect(newData.data).toEqual( [ "2 0 obj", - "<< /Length 133 /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " + - "/BBox [0 0 32 10]>> stream", + "<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " + + "/BBox [0 0 32 10] /Length 133>> stream", "/Tx BMC q", "1 1 32 10 re W n", "0.600006 0.756866 0.854904 rg", @@ -3753,8 +3753,8 @@ describe("annotation", function () { expect(newData.data).toEqual( [ "2 0 obj", - "<< /Length 171 /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " + - "/BBox [0 0 32 10]>> stream", + "<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " + + "/BBox [0 0 32 10] /Length 171>> stream", "/Tx BMC q", "1 1 32 10 re W n", "0.600006 0.756866 0.854904 rg", @@ -4058,7 +4058,7 @@ describe("annotation", function () { expect(appearance).toEqual( "3 0 obj\n" + "<< /FormType 1 /Subtype /Form /Type /XObject /BBox [0 0 44 44] " + - "/Length 101 /Resources << /Font << /Helv 1 0 R>>>>>> stream\n" + + "/Resources << /Font << /Helv 1 0 R>>>> /Length 101>> stream\n" + "q\n" + "0 0 44 44 re W n\n" + "BT\n" +