Skip to content

Commit

Permalink
Lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haoran Un committed Oct 22, 2024
1 parent e7480c3 commit af70e9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
27 changes: 10 additions & 17 deletions src/api/PDFPage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
Color,
colorToComponents,
rgb
} from 'src/api/colors';
import { Color, colorToComponents, rgb } from 'src/api/colors';
import {
drawImage,
drawLine,
Expand Down Expand Up @@ -1331,10 +1327,9 @@ export default class PDFPage {
);
}


/**
/**
* Draw a link on this page.
*
*
* In the PDF specification,you define a rectangular section of the page
* that when clicked should activate the link
*
Expand All @@ -1357,9 +1352,7 @@ export default class PDFPage {
assertIs(options.height, 'options.height', ['number']);

assertOrUndefined(options.borderWidth, 'options.borderWidth', ['number']);
assertOrUndefined(options.color, 'options.color', [
[Object, 'Color'],
]);
assertOrUndefined(options.color, 'options.color', [[Object, 'Color']]);

const pdfRef: PDFRef = this.doc.context.register(
this.doc.context.obj({
Expand All @@ -1373,7 +1366,7 @@ export default class PDFPage {
// upper right x coord
options.x + options.width,
// upper right y coord
options.y + options.height
options.y + options.height,
],

// The three parameters are:
Expand All @@ -1387,18 +1380,18 @@ export default class PDFPage {
/* Default to transparent */
C: options.color ? colorToComponents(options.color) : [],

// Name unique identifier
// NM: string
// Name unique identifier
// NM: string

/* Page to be visited when the link is clicked */
A: {
Type: 'Action',
S: 'URI',
URI: PDFString.of(link),
},
})
)
}),
);

// Annots Dictionary may or may not exist--create it if it doesn't.
if (this.node.Annots()) {
this.node.Annots()?.push(pdfRef);
Expand Down
23 changes: 13 additions & 10 deletions tests/api/PDFPage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import fs from 'fs';
import { PDFArray, PDFDocument, PDFName, PDFRef, StandardFonts } from 'src/index';
import {
PDFArray,
PDFDocument,
PDFName,
PDFRef,
StandardFonts,
} from 'src/index';

const birdPng = fs.readFileSync('assets/images/greyscale_bird.png');

Expand Down Expand Up @@ -153,15 +159,12 @@ describe(`PDFPage`, () => {
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage();

page.drawLink(
'https://pdf-lib.js.org',
{
x: 5,
y: 5,
width: 20,
height: 50,
}
);
page.drawLink('https://pdf-lib.js.org', {
x: 5,
y: 5,
width: 20,
height: 50,
});

const annots = page.node.normalizedEntries().Annots;
expect(annots).toBeInstanceOf(PDFArray);
Expand Down

0 comments on commit af70e9c

Please # to comment.