-
-
Notifications
You must be signed in to change notification settings - Fork 182
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
How can fields of placeholder be visible. #250
Comments
Hi, |
@vbuch thanks for the quick response, but what is the significance of this parameter reason,location?
|
@pranay18997 Were you able to get the green tick in Adobe Acrobat after signing the PDF ? |
@ngvhob no, @vbuch could you please help with #250 (comment) query? |
@vbuch is there any way we can read signature values from the certificate? |
@vbuch got it, but is there a way to have every page of the PDF digitally signed? In my task, I need the ability to sign all pages, and I have a demo document too. I will attach a screenshot to provide my problem statement. Cause atm I get error if I try to place multiple place holders in the pdf doc. Is this possible ?? |
@vbuch I was trying to add digital signature in last page of pdf doc. Please find the code below. pdflibAddPlaceholder({
pdfDoc: pdfDoc,
pdfPage:pages[2],
reason: 'Digitally Signed by xxx',
contactInfo: '[email protected]',
name: 'xxxxxx',
signatureLength: 13786,
location: 'Signature Valid',
widgetRect: widgetRect,
signingTime: new Date(),
}); Issue:- Widget is not visible in last page. But if I am not passing 'pdfPage' parameter then widget is visible in first page. |
Hello y'all, if I understand correctly @pranay18997 and @ngvhob sign widgets seem to be displaying the correct information of their respective I don't know if this is the normal behavior of the For context, here is the relevant code: import { pdflibAddPlaceholder } from '@signpdf/placeholder-pdf-lib'
import { P12Signer } from '@signpdf/signer-p12'
import signpdf from '@signpdf/signpdf'
import { PDFDocument, PDFPage } from 'pdf-lib'
//...
const p12Signer = new P12Signer(p12Buffer, {
passphrase: process?.env?.CERT_PASSWORD,
})
const widgetRect = [50, 70, 200, 200]
// Add a placeholder for a signature.
pdflibAddPlaceholder({
appName: 'Some App',
pdfDoc: pdfDoc,
reason: 'The user is declaring consent through JavaScript.',
contactInfo: '[email protected]',
name: 'John Doe',
location: 'Some place on Earth',
signingTime: new Date(),
widgetRect: widgetRect, // ! <== This is where we tell the widget to be visible
})
// Get the modified PDFDocument bytes
const pdfSaveBytes = await pdfDoc.save({ updateFieldAppearances: true })
const pdfWithPlaceholderBuffer = Buffer.from(pdfSaveBytes)
// And finally sign the document.
const signedPdfBuffer = await signpdf.sign(
pdfWithPlaceholderBuffer,
p12Signer
)
const pdfBlob = new Blob([signedPdfBuffer])
// Save to disk
await Bun.write(`${process.cwd()}/public/pdf/some-pdf-signed.pdf`, pdfBlob) As you can see here, I am using I really appreciate any leads to a solution and I am thankful for your time (anybody reading this through). Thanks. (Also, very nice library/package. Any ways to support/donate? @vbuch) |
hi @YO-SC , 1st thing would to be to look around the "visual" tag. I think all of these ask the same question - "How do I make the signature visually appealing?". |
Thanks for your timely response @vbuch, I will check out the examples provided. Thanks 👍🏼 |
Hello, how are you? First of all, congratulations on the initiative. I am facing issues with multiple signatures because when I add a visible placeholder and then sign, everything works perfectly. However, any other signature with a new visual placeholder invalidates the previous ones (in terms of integrity). I used pdf-lib to add the visible placeholder. |
@jamesjhonatan123 pdf-lib does not support incremental updates (at least to my knowledge) and those are needed for multiple signatures. |
@vbuch Is there any library or possibility to do this without using pdfKit or pdf-lib? Unfortunately, I can't load an already signed PDF with pdfKit, as it does not allow editing. |
@jamesjhonatan123 the signing part you can do with |
I did it. I used a fork of HummusJS - Muhammara (maintained) - for incremental writing. Now I can sign as many times as necessary by adding the visible placeholder. Thank you. Here's the example for those who had the same problem: import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { SignPdf } from '@signpdf/signpdf';
import { P12Signer } from '@signpdf/signer-p12';
import { plainAddPlaceholder } from '@signpdf/placeholder-plain';
import { Recipe } from 'muhammara';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function addPlaceholder(pdfBuffer, options) {
return plainAddPlaceholder({
pdfBuffer,
reason: options.reason,
contactInfo: options.contactInfo,
name: options.name,
location: options.location,
widgetRect: options.widgetRect,
});
}
async function signPdf(pdfBuffer, certificatePath, passphrase, targetPath) {
const certificateBuffer = fs.readFileSync(path.join(__dirname, certificatePath));
const signer = new P12Signer(certificateBuffer, { passphrase });
const signPdf = new SignPdf();
const signedPdf = await signPdf.sign(pdfBuffer, signer);
fs.writeFileSync(targetPath, signedPdf);
return signedPdf;
}
function drawTextOnWidget(pdfPath, outputPath, text, widgetRect) {
const pdfDoc = new Recipe(pdfPath, outputPath);
pdfDoc
.editPage(1)
.text(text, widgetRect.x, widgetRect.y)
.endPage()
.endPDF();
}
async function work() {
const pdfPath = path.join(__dirname, 'multiple-signatures-buyer-seller-3.pdf');
const pdfBuffer = fs.readFileSync(pdfPath);
const pdfWithBuyerPlaceholder = await addPlaceholder(pdfBuffer, {
reason: 'Agrees to buy the truck trailer.',
contactInfo: '[email protected]',
name: 'John Doe',
location: 'Free Text Str., Free World',
widgetRect: [200, 200, 300, 300],
});
const buyerSignedPdfPath = path.join(__dirname, './multiple-signatures-buyer-seller-1.pdf');
const buyerSignedPdf = await signPdf(
pdfWithBuyerPlaceholder,
'1/1.p12',
'123456',
buyerSignedPdfPath
);
drawTextOnWidget(buyerSignedPdfPath, buyerSignedPdfPath, 'Buyer Signature', { x: 250, y: 250 });
const buyerSignedPdfBuffer = fs.readFileSync(buyerSignedPdfPath);
const pdfWithSellerPlaceholder = await addPlaceholder(buyerSignedPdfBuffer, {
reason: 'Agrees to sell a truck trailer to John Doe.',
contactInfo: '[email protected]',
name: 'Thug Dealer',
location: 'Automotive Str., Free World',
widgetRect: [400, 400, 500, 500],
});
const sellerSignedPdfPath = path.join(__dirname, './multiple-signatures-buyer-seller-2.pdf');
const finalSignedPdf = await signPdf(
pdfWithSellerPlaceholder,
'2/2.p12',
'654321',
sellerSignedPdfPath
);
drawTextOnWidget(sellerSignedPdfPath, path.join(__dirname, './multiple-signatures-buyer-seller-3.pdf'), 'Seller Signature', { x: 450, y: 450 });
console.log('PDF signed by both buyer and seller with text drawn on widgetRect.');
}
work(); |
@jamesjhonatan123 want to make it a package under packages/examples? Or at least start a PR that I can when I have the time help with/wrap up for you |
Sure, I'll do it. |
hey @jamesjhonatan123 thanks for your sample, but when executing that script on mac m1 it throws me this error, did you get it before? thanks for any comments |
Describe the bug and the expected behaviour
I am working on the digital signature, and I want it should look like this. But I am not getting any option in pdflib. Please help here.
Is it a bug in signing or in the helpers?
Its a doubt
To Reproduce
Help us reproduce.
Include any relevant code.
Point to where you are having issues with links.
Give us a failing test.
In all cases make sure to include at least a source PDF that you are trying and failing to sign.
To let us easily take a look, it would help if you also include a resulting document (thou probably corrupted one).
The text was updated successfully, but these errors were encountered: