mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 03:01:59 +10:00
✨🚧 signDocument using node signpdf and custom placeholder insert
This commit is contained in:
@ -12,6 +12,7 @@ const withTM = require("next-transpile-modules")([
|
||||
"@documenso/ui",
|
||||
"@documenso/pdf",
|
||||
"@documenso/features",
|
||||
"@documenso/signing",
|
||||
"react-signature-canvas",
|
||||
]);
|
||||
const plugins = [];
|
||||
|
||||
@ -32,9 +32,12 @@
|
||||
"next": "13.0.3",
|
||||
"next-auth": "^4.18.3",
|
||||
"next-transpile-modules": "^10.0.0",
|
||||
"node-forge": "^1.3.1",
|
||||
"node-signpdf": "^1.5.0",
|
||||
"nodemailer": "^6.9.0",
|
||||
"nodemailer-sendgrid": "^1.0.3",
|
||||
"npm": "^9.1.3",
|
||||
"pdf-lib": "^1.17.1",
|
||||
"placeholder-loading": "^0.6.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
|
||||
@ -7,6 +7,7 @@ import prisma from "@documenso/prisma";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { Document as PrismaDocument } from "@prisma/client";
|
||||
import { getDocument } from "@documenso/lib/query";
|
||||
import { signDocument } from "@documenso/signing/signDocument";
|
||||
|
||||
async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const user = await getUserFromToken(req, res);
|
||||
@ -24,7 +25,11 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!document)
|
||||
res.status(404).end(`No document with id ${documentId} found.`);
|
||||
|
||||
const buffer: Buffer = Buffer.from(document.document.toString(), "base64");
|
||||
const signedDocumentAsBase64 = await signDocument(
|
||||
document.document.toString()
|
||||
);
|
||||
|
||||
const buffer: Buffer = Buffer.from(signedDocumentAsBase64, "base64");
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
res.setHeader(
|
||||
"Content-Disposition",
|
||||
|
||||
30
apps/web/pages/api/test-sign/[id].ts
Normal file
30
apps/web/pages/api/test-sign/[id].ts
Normal file
@ -0,0 +1,30 @@
|
||||
import {
|
||||
defaultHandler,
|
||||
defaultResponder,
|
||||
getUserFromToken,
|
||||
} from "@documenso/lib/server";
|
||||
import prisma from "@documenso/prisma";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { Document as PrismaDocument } from "@prisma/client";
|
||||
import { getDocument } from "@documenso/lib/query";
|
||||
import { signDocument } from "@documenso/signing/signDocument";
|
||||
|
||||
async function getHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const documentId = req.query.id || 1;
|
||||
const document: PrismaDocument = await getDocument(+documentId, req, res);
|
||||
const signedDocumentAsBase64 = await signDocument(document.document.toString());
|
||||
const buffer: Buffer = Buffer.from(signedDocumentAsBase64, "base64");
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
res.setHeader(
|
||||
"Content-Disposition",
|
||||
`attachment; filename=${document.title}`
|
||||
);
|
||||
res.setHeader("Content-Length", buffer.length);
|
||||
|
||||
res.status(200).send(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
export default defaultHandler({
|
||||
GET: Promise.resolve({ default: defaultResponder(getHandler) }),
|
||||
});
|
||||
Reference in New Issue
Block a user