@digital-blueprint/annotpdf
Version:
Javascript library for creating annotations in PDF documents
225 lines (224 loc) • 11.7 kB
TypeScript
import { Annotation, Color } from './parser';
/**
* The annotation factory provides methods to create annotations. Those are stored temporary
* and than encoded into PDF code when the PDF document is outputted and for instance downloaded.
* That
* */
export declare class AnnotationFactory {
private data;
private userPassword;
private ownerPassword;
private annotations;
private toDelete;
private parser;
constructor(data: Uint8Array, userPassword?: string, ownerPassword?: string);
/**
* Returns the number of annotations that will be added to the PDF document
* */
getAnnotationCount(): number;
/**
* Load a PDF file referenced by the given 'path'
* */
static loadFile(path: string, userPassword?: string, ownerPassword?: string): Promise<AnnotationFactory>;
/**
* Generates a unique identifier necessary for creating the annotation
* */
private generateUniqueIdentifier;
/**
* Generates a default border
* */
private createDefaultBorder;
/**
* Writes the made annotations into a bytestream
* */
write(): Uint8Array;
/**
* Checks the 'rect' parameter, whether all the entries are of type number and if the the number of entries is correct
* */
private checkRect;
/**
* Extracts the rectangular hull from a quadPoint definition
* */
private extractRectFromQuadPoints;
/**
* Checks the 'quadPoints' parameter
* */
private checkQuadPoints;
/**
* Creates a base annotation that mean the raw object of annotation or those parts that are all existing
* and equally set in all types of annotations
* */
createBaseAnnotation(page: number, rect: number[], contents: string, author: string): Annotation;
/**
* Creates a text annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createTextAnnotation(page: number, rect: number[], contents: string, author: string, color?: Color): void;
/**
* Creates a text markup annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* subtype : the subtype of the Textmarkup annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createTextMarkupAnnotation(page: number, rect: number[], contents: string, author: string, subtype: string, color?: Color, quadPoints?: number[]): Annotation;
/**
* Creates a highlight annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createHighlightAnnotation(page: number, rect: number[], contents: string, author: string, color?: Color, quadPoints?: number[]): void;
/**
* Creates an underline annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createUnderlineAnnotation(page: number, rect: number[], contents: string, author: string, color?: Color, quadPoints?: number[]): void;
/**
* Creates a squiggle annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createSquigglyAnnotation(page: number, rect: number[], contents: string, author: string, color?: Color, quadPoints?: number[]): void;
/**
* Creates a strike out annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createStrikeOutAnnotation(page: number, rect: number[], contents: string, author: string, color?: Color, quadPoints?: number[]): void;
/**
* Creates a free text annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createFreeTextAnnotation(page: number, rect: number[], contents: string, author: string, color?: Color): void;
createLineAnnotation(): void;
/**
* Creates the base annotation object of a circle and square annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* fill : the filling color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createSquareCircleAnnotation(page: number, rect: number[], contents: string, author: string, subtype: string, color?: Color, fill?: Color): Annotation;
/**
* Creates a square annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* fill : the filling color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createSquareAnnotation(page: number, rect: number[], contents: string, author: string, color?: Color, fill?: Color): void;
/**
* Creates a circle annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* fill : the filling color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createCircleAnnotation(page: number, rect: number[], contents: string, author: string, color?: Color, fill?: Color): void;
/**
* Creates the base object of a polygon or polyline annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* vertices : the vertices defining the arrangement of the object
* subtyp: Polygon or PolyLine
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createPolygonPolyLineAnnotation(page: number, rect: number[], contents: string, author: string, vertices: number[], subtype: string, color?: Color): Annotation;
/**
* Creates a polygon annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* vertices : the vertices defining the arrangement of the object
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createPolygonAnnotation(page: number, rect: number[], contents: string, author: string, vertices: number[], color?: Color): void;
/**
* Creates a polyline annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* vertices : the vertices defining the arrangement of the object
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createPolyLineAnnotation(page: number, rect: number[], contents: string, author: string, vertices: number[], color?: Color): void;
/**
* Creates an ink annotation
* page : the number of the PDF document page, where the annotation must be attached
* rect : the position of the annotation on the page
* contents : the content of the annotation
* author : the author of the annotation
* inkList : a list of list containing the points for drawing the lines
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createInkAnnotation(page: number, rect: number[], contents: string, author: string, inkList: number[][] | number[], color?: Color): void;
/**
* Creates a stamp annotation. There exists a number of predifined stamps that can be attached to PDF documents.
* page : the number of the PDF document page, where the annotation must be attached
* contents : the content of the annotation
* author : the author of the annotation
* stampType : the name of the used stamp type. Can be: [Approved, Experimental, NotApproved, AsIs, Expired, NotForPublicRelease, Confidential, Final, Sold, Departmental, ForComment, TopSecret, Draft, ForPublicRelease]
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createStampAnnotation(page: number, contents: string, author: string, stampType?: string, color?: Color): void;
/**
* Creates a visual symbol that indcates the existance of text edits.
* page : the number of the PDF document page, where the annotation must be attached
* contents : the content of the annotation
* author : the author of the annotation
* caretSymbol : None or P, with P for using the paragraph symbol as caret
* color : the color of the annotation in rgb. Can be of domain 0 - 255 or 0 - 1
* */
createCaretAnnotation(page: number, contents: string, author: string, caretSymbol?: string, color?: Color): void;
/**
* Deletes the annotation with the given id or the given reference object
* */
deleteAnnotation(id: any): Promise<any>;
/**
* Returns a promise with the resul of all annotations that are part of the document. This will
* comprise those that are already exists and those that were created using this library
* */
getAnnotations(): Promise<Annotation[][]>;
createPopupAnnotation(): void;
/**
* Downloads the adapted PDF document
* */
download(fileName?: string): void;
/**
* Saves the adapted PDF document in a nodejs environment
* */
save(fileName?: string): void;
}