Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the generate function to allow for custom pre-processing and post-processing. #391

Open
hand-dot opened this issue Dec 27, 2023 · 0 comments

Comments

@hand-dot
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

Context: #389 (comment)


idea

const inputs = [
  { headline: { name: "han-dot", favoriteColor: "blue" }, address: "aa-aa-a" },
];

const template = {
  schemas: [
    {
      headline: {
        type: "text",
        position: { x: 4.69, y: 7.15 },
        width: 186.51,
        height: 41.98,
        rotate: 0,
        opacity: 1,
        fontSize: 36,
        fontColor: "#14b351",
        fontName: "NotoSerifJP-Regular",
        readOnly: true,
        readOnlyValue: "Hi {name}, Your favorite color is {favoriteColor}",
      },
      address: {
        type: "text",
        position: { x: 4.69, y: 7.15 },
        width: 186.51,
        height: 41.98,
        rotate: 0,
        opacity: 1,
        fontSize: 36,
        fontColor: "#14b351",
        fontName: "NotoSerifJP-Regular",
      },
    },
  ],
  basePdf: "base64pdf...",
};

const pdf = await generate({
  inputs,
  template,
  options: {
    preprocessing: ({ inputs, template }) => {
      const newInputs = inputs.map((input) => {
        const newInput = {};
        Object.keys(input).forEach((key) => {
          const value = input[key];
          if (typeof value === "object") {
            const schemaIndex = template.schemas.findIndex(
              (schema) => schema[key]
            );
            const schema = template.schemas[schemaIndex][key];
            const { readOnlyValue } = schema;
            newInput[key] = readOnlyValue.replace(
              /{([^}]+)}/g,
              (_, key) => value[key]
            );
          } else {
            newInput[key] = key;
          }
        });
        return newInput;
      });
      return { inputs: newInputs, template };
    },
  },
});

Using post-processing, it would be possible to add digital signatures.

Describe the solution you'd like

Add the generate function to allow for custom pre-processing and post-processing.

Describe alternatives you've considered

  • pre-processing: Process inputs before passing them to the generate function.
  • post-processing: None.

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant