mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-22 23:45:02 +00:00
updateMetadata
This commit is contained in:
parent
edd4e0c39a
commit
dbadfe50e6
@ -58,8 +58,13 @@ export function GenericField({ fieldName, joiDefinition }: GenericFieldProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: Implement unrestrained text input
|
return (
|
||||||
return (<div>string, unrestrained text input is not implemented</div>)
|
<Fragment>
|
||||||
|
<label htmlFor={fieldName}>{flags.label}:</label>
|
||||||
|
<input type="text" list={fieldName} name={fieldName}/>
|
||||||
|
<br/>
|
||||||
|
</Fragment>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "comma_array":
|
case "comma_array":
|
||||||
@ -114,6 +119,22 @@ export function GenericField({ fieldName, joiDefinition }: GenericFieldProps) {
|
|||||||
<br/>
|
<br/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
|
case "boolean":
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<label htmlFor={fieldName}>{flags.label}:</label>
|
||||||
|
<input type="checkbox" list={fieldName} name={fieldName}/>
|
||||||
|
<br/>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
case "date":
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<label htmlFor={fieldName}>{flags.label}:</label>
|
||||||
|
<input type="date" list={fieldName} name={fieldName}/>
|
||||||
|
<br/>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
console.log(joiDefinition);
|
console.log(joiDefinition);
|
||||||
return (<div>GenericField.tsx: <br/> "{fieldName}": requested type "{joiDefinition.type}" not found. Check console for further info.</div>)
|
return (<div>GenericField.tsx: <br/> "{fieldName}": requested type "{joiDefinition.type}" not found. Check console for further info.</div>)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { PdfFile, RepresentationType } from "../wrappers/PdfFile";
|
import { PdfFile } from "../wrappers/PdfFile";
|
||||||
import { Operator, Progress, oneToN } from ".";
|
import { Operator, Progress, oneToN } from ".";
|
||||||
|
|
||||||
import Joi from "@stirling-tools/joi";
|
import Joi from "@stirling-tools/joi";
|
||||||
@ -21,7 +21,7 @@ export class SplitPdfByIndex extends Operator {
|
|||||||
protected static valueSchema = Joi.object({
|
protected static valueSchema = Joi.object({
|
||||||
pageIndexes: CommaArrayJoiExt.comma_array().items(Joi.number().integer()).required()
|
pageIndexes: CommaArrayJoiExt.comma_array().items(Joi.number().integer()).required()
|
||||||
.label(i18next.t("values.pageIndexes.friendlyName", { ns: "splitPdfByIndex" })).description(i18next.t("values.pageIndexes.description", { ns: "splitPdfByIndex" }))
|
.label(i18next.t("values.pageIndexes.friendlyName", { ns: "splitPdfByIndex" })).description(i18next.t("values.pageIndexes.description", { ns: "splitPdfByIndex" }))
|
||||||
.example("1").example("1, 2, 3, 4").example("4, 2, 4, 3").required()
|
.example("1").example("1, 2, 3, 4").example("4, 2, 4, 3")
|
||||||
});
|
});
|
||||||
protected static outputSchema = JoiPDFFileSchema.label(i18next.t("outputs.pdffile.name")).description(i18next.t("outputs.pdffile.description"));
|
protected static outputSchema = JoiPDFFileSchema.label(i18next.t("outputs.pdffile.name")).description(i18next.t("outputs.pdffile.description"));
|
||||||
|
|
||||||
|
@ -1,25 +1,73 @@
|
|||||||
|
|
||||||
import { PdfFile } from "../wrappers/PdfFile";
|
import { PdfFile } from "../wrappers/PdfFile";
|
||||||
|
import { Operator, Progress, oneToOne } from ".";
|
||||||
|
|
||||||
export interface UpdateMetadataParams {
|
import Joi from "@stirling-tools/joi";
|
||||||
file: PdfFile,
|
|
||||||
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
|
|
||||||
//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
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateMetadata(params: UpdateMetadataParams): Promise<PdfFile> {
|
import { JoiPDFFileSchema } from "../wrappers/PdfFileJoi";
|
||||||
const pdfDoc = await params.file.pdfLibDocument;
|
|
||||||
|
|
||||||
if (params.deleteAll) {
|
import i18next from "i18next";
|
||||||
|
|
||||||
|
export class UpdateMetadata extends Operator {
|
||||||
|
static type = "updateMetadata";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validation & Localisation
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected static inputSchema = JoiPDFFileSchema.label(i18next.t("inputs.pdffile.name")).description(i18next.t("inputs.pdffile.description"));
|
||||||
|
protected static valueSchema = Joi.object({
|
||||||
|
deleteAll: Joi.boolean().invalid(false)
|
||||||
|
.label(i18next.t("values.deleteAll.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.deleteAll.description", { ns: "updateMetadata" }))
|
||||||
|
.example("true").example("false"),
|
||||||
|
author: Joi.string().optional().allow('')
|
||||||
|
.label(i18next.t("values.author.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.author.description", { ns: "updateMetadata" }))
|
||||||
|
.example("John Doe").example("Anthony Stirling"), // The author of the document
|
||||||
|
creationDate: Joi.date().allow("").allow(null)
|
||||||
|
.label(i18next.t("values.creationDate.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.creationDate.description", { ns: "updateMetadata" }))
|
||||||
|
.example("YYYY-MM-DD").example("2023-01-27"), // The creation date of the document (format: yyyy/MM/dd HH:mm:ss)
|
||||||
|
creator: Joi.string().optional().allow('')
|
||||||
|
.label(i18next.t("values.creator.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.creator.description", { ns: "updateMetadata" }))
|
||||||
|
.example("John Doe").example("Anthony Stirling"), // The creator of the document
|
||||||
|
keywords: Joi.string().optional().allow('')
|
||||||
|
.label(i18next.t("values.keywords.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.keywords.description", { ns: "updateMetadata" }))
|
||||||
|
.example("General").example("finances, leisure").example("finances leisure"), // The keywords for the document
|
||||||
|
modificationDate: Joi.date().allow("").allow(null)
|
||||||
|
.label(i18next.t("values.modificationDate.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.modificationDate.description", { ns: "updateMetadata" }))
|
||||||
|
.example("YYYY-MM-DD").example("2023-01-27"), // The modification date of the document (format: yyyy/MM/dd HH:mm:ss)
|
||||||
|
producer: Joi.string().optional().allow('')
|
||||||
|
.label(i18next.t("values.producer.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.producer.description", { ns: "updateMetadata" }))
|
||||||
|
.example("John Doe").example("Anthony Stirling"), // The producer of the document
|
||||||
|
subject: Joi.string().optional().allow('')
|
||||||
|
.label(i18next.t("values.subject.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.subject.description", { ns: "updateMetadata" }))
|
||||||
|
.example("Subject").example("This is an example Subject."), // The subject of the document
|
||||||
|
title: Joi.string().optional().allow('')
|
||||||
|
.label(i18next.t("values.title.friendlyName", { ns: "updateMetadata" })).description(i18next.t("values.title.description", { ns: "updateMetadata" }))
|
||||||
|
.example("Title").example("This is an example title."), // The title of the document
|
||||||
|
|
||||||
|
// TODO: trapped?: string, // The trapped status of the document
|
||||||
|
|
||||||
|
// TODO: 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
|
||||||
|
});
|
||||||
|
protected static outputSchema = JoiPDFFileSchema.label(i18next.t("outputs.pdffile.name")).description(i18next.t("outputs.pdffile.description"));
|
||||||
|
|
||||||
|
static schema = Joi.object({
|
||||||
|
input: UpdateMetadata.inputSchema,
|
||||||
|
values: UpdateMetadata.valueSchema.required(),
|
||||||
|
output: UpdateMetadata.outputSchema
|
||||||
|
}).label(i18next.t("friendlyName", { ns: "updateMetadata" })).description(i18next.t("description", { ns: "updateMetadata" }));
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logic
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** PDF extraction, specify pages from one pdf and output them to a new pdf */
|
||||||
|
async run(input: PdfFile[], progressCallback: (state: Progress) => void): Promise<PdfFile[]> {
|
||||||
|
return oneToOne<PdfFile, PdfFile>(input, async (input, index, max) => {
|
||||||
|
|
||||||
|
const pdfDoc = await input.pdfLibDocument;
|
||||||
|
|
||||||
|
if (this.actionValues.deleteAll) {
|
||||||
pdfDoc.setAuthor("");
|
pdfDoc.setAuthor("");
|
||||||
pdfDoc.setCreationDate(new Date(0));
|
pdfDoc.setCreationDate(new Date(0));
|
||||||
pdfDoc.setCreator("");
|
pdfDoc.setCreator("");
|
||||||
@ -30,25 +78,29 @@ export async function updateMetadata(params: UpdateMetadataParams): Promise<PdfF
|
|||||||
pdfDoc.setTitle("");
|
pdfDoc.setTitle("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(params.author)
|
if(this.actionValues.author)
|
||||||
pdfDoc.setAuthor(params.author);
|
pdfDoc.setAuthor(this.actionValues.author);
|
||||||
if(params.creationDate)
|
if(this.actionValues.creationDate)
|
||||||
pdfDoc.setCreationDate(params.creationDate);
|
pdfDoc.setCreationDate(this.actionValues.creationDate);
|
||||||
if(params.creator)
|
if(this.actionValues.creator)
|
||||||
pdfDoc.setCreator(params.creator);
|
pdfDoc.setCreator(this.actionValues.creator);
|
||||||
if(params.keywords)
|
if(this.actionValues.keywords)
|
||||||
pdfDoc.setKeywords(params.keywords.split(","));
|
pdfDoc.setKeywords(this.actionValues.keywords.split(","));
|
||||||
if(params.modificationDate)
|
if(this.actionValues.modificationDate)
|
||||||
pdfDoc.setModificationDate(params.modificationDate);
|
pdfDoc.setModificationDate(this.actionValues.modificationDate);
|
||||||
if(params.producer)
|
if(this.actionValues.producer)
|
||||||
pdfDoc.setProducer(params.producer);
|
pdfDoc.setProducer(this.actionValues.producer);
|
||||||
if(params.subject)
|
if(this.actionValues.subject)
|
||||||
pdfDoc.setSubject(params.subject);
|
pdfDoc.setSubject(this.actionValues.subject);
|
||||||
if(params.title)
|
if(this.actionValues.title)
|
||||||
pdfDoc.setTitle(params.title);
|
pdfDoc.setTitle(this.actionValues.title);
|
||||||
|
|
||||||
// TODO add trapped and custom metadata. May need another library
|
// TODO: add trapped and custom metadata. May need another library
|
||||||
|
|
||||||
params.file.filename += "_updatedMetadata";
|
progressCallback({ curFileProgress: 1, operationProgress: index/max });
|
||||||
return params.file;
|
|
||||||
|
input.filename += "_updatedMetadata";
|
||||||
|
return input;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user