Skip to content

Commit

Permalink
Add a test to check that the compression is ok when saving an annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Jun 16, 2023
1 parent 8937cac commit d271adb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,4 @@
!issue16538.pdf
!freetexts.pdf
!issue16553.pdf
!empty.pdf
Binary file added test/pdfs/empty.pdf
Binary file not shown.
43 changes: 43 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,49 @@ describe("api", function () {
await loadingTask.destroy();
});

it("write a a new annotation, save the pdf and check that the text content is correct", async function () {
// This test helps to check that the text stream is correctly compressed
// when saving.
const manifesto = `
The Mozilla Manifesto Addendum
Pledge for a Healthy Internet
The open, global internet is the most powerful communication and collaboration resource we have ever seen.
It embodies some of our deepest hopes for human progress.
It enables new opportunities for learning, building a sense of shared humanity, and solving the pressing problems
facing people everywhere.
Over the last decade we have seen this promise fulfilled in many ways.
We have also seen the power of the internet used to magnify divisiveness,
incite violence, promote hatred, and intentionally manipulate fact and reality.
We have learned that we should more explicitly set out our aspirations for the human experience of the internet.
We do so now.
`.repeat(100);
let loadingTask = getDocument(buildGetDocumentParams("empty.pdf"));
let pdfDoc = await loadingTask.promise;
pdfDoc.annotationStorage.setValue("pdfjs_internal_editor_0", {
annotationType: AnnotationEditorType.FREETEXT,
rect: [10, 10, 500, 500],
rotation: 0,
fontSize: 1,
color: [0, 0, 0],
value: manifesto,
pageIndex: 0,
});

const data = await pdfDoc.saveDocument();
await loadingTask.destroy();

loadingTask = getDocument(data);
pdfDoc = await loadingTask.promise;
const page = await pdfDoc.getPage(1);
const annotations = await page.getAnnotations();

expect(annotations[0].contentsObj.str).toEqual(manifesto);

await loadingTask.destroy();
});

describe("Cross-origin", function () {
let loadingTask;
function _checkCanLoad(expectSuccess, filename, options) {
Expand Down

0 comments on commit d271adb

Please sign in to comment.