2023-11-08 03:33:22 +03:00
2023-11-14 23:14:08 +01:00
import { PdfFile } from '../wrappers/PdfFile' ;
2023-11-08 03:33:22 +03:00
2023-11-14 03:26:42 +03:00
export type UpdateMetadataParams = {
file : PdfFile ,
2023-11-11 20:27:28 +03:00
deleteAll? : boolean , // Delete all metadata if set to true
author? : string , // The author of the document
creationDate? : Date , // The creation date of the document (format: yyyy/MM/dd HH:mm:ss)
creator? : string , // The creator of the document
keywords? : string , // The keywords for the document
modificationDate? : Date , // The modification date of the document (format: yyyy/MM/dd HH:mm:ss)
producer? : string , // The producer of the document
subject? : string , // The subject of the document
title? : string , // The title of the document
//trapped?: string, // The trapped status of the document
2023-11-12 16:57:53 +03:00
//allRequestParams?: {[key: string]: [key: string]}, // Map list of key and value of custom parameters. Note these must start with customKey and customValue if they are non-standard
2023-11-08 03:33:22 +03:00
}
2023-11-11 20:27:28 +03:00
2023-11-14 03:26:42 +03:00
export async function updateMetadata ( params : UpdateMetadataParams ) : Promise < PdfFile > {
2023-11-15 02:38:07 +03:00
const pdfDoc = await params . file . pdfLibDocument ;
2023-11-08 03:33:22 +03:00
2023-11-14 03:26:42 +03:00
if ( params . deleteAll ) {
2023-11-11 20:27:28 +03:00
pdfDoc . setAuthor ( "" ) ;
pdfDoc . setCreationDate ( new Date ( 0 ) )
pdfDoc . setCreator ( "" )
pdfDoc . setKeywords ( [ ] )
pdfDoc . setModificationDate ( new Date ( 0 ) )
pdfDoc . setProducer ( "" )
pdfDoc . setSubject ( "" )
pdfDoc . setTitle ( "" )
}
2023-11-08 03:33:22 +03:00
2023-11-14 03:26:42 +03:00
if ( params . author )
pdfDoc . setAuthor ( params . author ) ;
if ( params . creationDate )
pdfDoc . setCreationDate ( params . creationDate )
if ( params . creator )
pdfDoc . setCreator ( params . creator )
if ( params . keywords )
pdfDoc . setKeywords ( params . keywords . split ( "," ) )
if ( params . modificationDate )
pdfDoc . setModificationDate ( params . modificationDate )
if ( params . producer )
pdfDoc . setProducer ( params . producer )
if ( params . subject )
pdfDoc . setSubject ( params . subject )
if ( params . title )
pdfDoc . setTitle ( params . title )
2023-11-08 03:33:22 +03:00
2023-11-11 20:27:28 +03:00
// TODO add trapped and custom metadata. May need another library
2023-11-08 03:33:22 +03:00
2023-11-14 23:14:08 +01:00
return params . file ;
2023-11-11 20:27:28 +03:00
} ;