Pdf - PdfFileSpecification

18 Nov 20267 minutes to read

Represents a file specification used by a PDF action.

// Create a new PDF document
let document: PdfDocument = new PdfDocument();
let page: PdfPage = document.addPage();
// Create an embedded file
let embeddedFile: PdfEmbeddedFile = new PdfEmbeddedFile(attachmentData);
// Create and configure a file specification
let fileSpecification: PdfFileSpecification = new PdfFileSpecification('input.fdf');
fileSpecification.description = 'Form data';
fileSpecification.embeddedFile = embeddedFile;
// Create an import-data action
let action: PdfImportDataAction = new PdfImportDataAction(fileSpecification);
// Create a button and assign the action
let field: PdfButtonField = new PdfButtonField(
    page, 'ImportData', { x: 20, y: 20, width: 120, height: 30 }
);
field.actions.mouseUp = action;
document.form.add(field);
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Properties

Get description string

Gets the description of the file represented by the file specification.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the first button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the import-data action
let action: PdfImportDataAction = field.actions.mouseUp as PdfImportDataAction;
// Get the file description
let description: string = action.fileSpecification.description;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set description void

Sets the description of the file represented by the file specification.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the first button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the import-data action
let action: PdfImportDataAction = field.actions.mouseUp as PdfImportDataAction;
// Set the file description
action.fileSpecification.description = 'Form data';
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value string The description to set for the file.

Get embeddedFile PdfEmbeddedFile

Gets the embedded file associated with the file specification.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the first button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the import-data action
let action: PdfImportDataAction = field.actions.mouseUp as PdfImportDataAction;
// Get the embedded file and its binary data
let embeddedFile: PdfEmbeddedFile = action.fileSpecification.embeddedFile;
let embeddedData: Uint8Array = embeddedFile.data;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set embeddedFile void

Sets the embedded file associated with the file specification.

// Create a new PDF document
let document: PdfDocument = new PdfDocument();
let page: PdfPage = document.addPage();
// Create an embedded file
let embeddedFile: PdfEmbeddedFile = new PdfEmbeddedFile(attachmentData);
// Create a file specification and set the embedded file
let fileSpecification: PdfFileSpecification = new PdfFileSpecification('input.fdf');
fileSpecification.embeddedFile = embeddedFile;
// Create an import-data action
let action: PdfImportDataAction = new PdfImportDataAction(fileSpecification);
// Create a button and assign the action
let field: PdfButtonField = new PdfButtonField(
    page, 'ImportData', { x: 20, y: 20, width: 120, height: 30 }
);
field.actions.mouseUp = action;
document.form.add(field);
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value PdfEmbeddedFile The embedded file to associate with the file specification.

Get fileName string

Gets the file name represented by the file specification.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the first button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the import-data action
let action: PdfImportDataAction = field.actions.mouseUp as PdfImportDataAction;
// Get the file specification and file name
let fileSpecification: PdfFileSpecification = action.fileSpecification;
let fileName: string = fileSpecification.fileName;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set fileName void

Sets the file name represented by the file specification.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the first button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the import-data action
let action: PdfImportDataAction = field.actions.mouseUp as PdfImportDataAction;
// Set the file name
action.fileSpecification.fileName = 'updated.fdf';
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value string The file name to set in the file specification.

Get unicodeFileName string

Gets the Unicode file name represented by the file specification.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the first button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the import-data action
let action: PdfImportDataAction = field.actions.mouseUp as PdfImportDataAction;
// Get the Unicode file name
let unicodeFileName: string = action.fileSpecification.unicodeFileName;
// Save and destroy the document
document.save('output.pdf');
document.destroy();

Set unicodeFileName void

Sets the Unicode file name represented by the file specification.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Get the first button field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the import-data action
let action: PdfImportDataAction = field.actions.mouseUp as PdfImportDataAction;
// Set the Unicode file name
action.fileSpecification.unicodeFileName = 'form-data.fdf';
// Save and destroy the document
document.save('output.pdf');
document.destroy();
Parameter Type Description
value string The Unicode file name to set in the file specification.