rename fileAttachmentAnnotation to fileAnnotation

This commit is contained in:
Steffen Matheis 2021-03-25 18:16:33 +01:00 committed by Luiz Américo
parent 7219fd07a9
commit 3cd88b296c
7 changed files with 16 additions and 16 deletions

View File

@ -29,12 +29,12 @@ const file = {
creationDate: new Date(2020, 3, 1)
};
// then, add the annotation
doc.fileAttachmentAnnotation(100, 150, 10, doc.currentLineHeight(), file);
doc.fileAnnotation(100, 150, 10, doc.currentLineHeight(), file);
// declared files can be reused, but they will show up separately in the PDF Viewer's attachments panel
// we're going to use the paperclip icon for this one together with a short description
// be aware that some PDF Viewers may not render the icon correctly — or not at all
doc.fileAttachmentAnnotation(150, 150, 10, doc.currentLineHeight(), file, {
doc.fileAnnotation(150, 150, 10, doc.currentLineHeight(), file, {
Name: 'Paperclip',
Contents: 'Paperclip attachment'
});

Binary file not shown.

View File

@ -16,7 +16,7 @@ and some other properties. Here is a list of the available annotation methods:
* `rectAnnotation(x, y, width, height, options)`
* `ellipseAnnotation(x, y, width, height, options)`
* `textAnnotation(x, y, width, height, text, options)`
* `fileAttachmentAnnotation(x, y, width, height, file, options)`
* `fileAnnotation(x, y, width, height, file, options)`
Many of the annotations have a `color` option that you can specify. You can
use an array of RGB values, a hex color, or a named CSS color value for that

View File

@ -28,18 +28,18 @@ There are a few other options for `doc.file`:
If you are attaching a file from your file system, creationDate and modifiedDate will be set to the source file's creationDate and modifiedDate.
Setting the `hidden` option prevents this file from showing up in the pdf viewer's attachment panel.
While this may not be very useful for embedded files, it is absolutely necessary for the file attachment annotations, to prevent them from showing up twice in the attachment panel.
While this may not be very useful for embedded files, it is absolutely necessary for file annotations, to prevent them from showing up twice in the attachment panel.
## File Attachment Annotations
## File Annotations
A file attachment annotation contains a reference to an embedded file that can be placed anywhere in the document.
File attachment annotations show up in your reader's annotation panel as well as the attachment panel.
A file annotation contains a reference to an embedded file that can be placed anywhere in the document.
File annotations show up in your reader's annotation panel as well as the attachment panel.
In order to add a file attachment annotation, you should first read the chapter on annotations.
In order to add a file annotation, you should first read the chapter on annotations.
Like other annotations, you specify position and size with `x`, `y`, `width` and `height`, unlike other annotations you must also specify a file object.
The file object may contain the same options as `doc.file` in the previous section with the addition of the source file or buffered data in `src`.
Here is an example of adding a file attachment annotation:
Here is an example of adding a file annotation:
const file = {
src: path.join(__dirname, 'example.txt'),
@ -48,6 +48,6 @@ Here is an example of adding a file attachment annotation:
}
const options = { Name: 'Paperclip' }
doc.fileAttachmentAnnotation(100, 100, 100, 100, file, options)
doc.fileAnnotation(100, 100, 100, 100, file, options)
The annotation's appearance may be changed by setting the `Name` option to one of the three predefined icons `GraphPush`, `Paperclip` or `Push` (default value).

Binary file not shown.

View File

@ -129,7 +129,7 @@ export default {
return this.annotate(x, y, w, h, options);
},
fileAttachmentAnnotation(x, y, w, h, file = {}, options = {}) {
fileAnnotation(x, y, w, h, file = {}, options = {}) {
// create hidden file
const filespec = this.file(
file.src,

View File

@ -101,11 +101,11 @@ describe('Annotations', () => {
});
});
describe('fileAttachmentAnnotation', () => {
test('creating a fileAttachmentAnnotation', () => {
describe('fileAnnotation', () => {
test('creating a fileAnnotation', () => {
const docData = logData(document);
document.fileAttachmentAnnotation(100, 100, 20, 20, {
document.fileAnnotation(100, 100, 20, 20, {
src: Buffer.from('example text'),
name: 'file.txt'
});
@ -126,7 +126,7 @@ describe('Annotations', () => {
test("using the file's description", () => {
const docData = logData(document);
document.fileAttachmentAnnotation(100, 100, 20, 20, {
document.fileAnnotation(100, 100, 20, 20, {
src: Buffer.from('example text'),
name: 'file.txt',
description: 'file description'
@ -149,7 +149,7 @@ describe('Annotations', () => {
test("overriding the file's description", () => {
const docData = logData(document);
document.fileAttachmentAnnotation(
document.fileAnnotation(
100,
100,
20,