我使用PDFsharp和MigraDoc创建一个新的PDF文件。现在,我想添加一个字段,用户可以在其中单击并选择用于数字签名文件的证书。
我在网上发现,使用AcroForms应该可以做到这一点。但是我无法使用,AcroForm因为它始终为null。
我当前的示例代码:
Document document = new Document();
Section section = document.AddSection();
section.AddParagraph("Signature Test");
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
// NullPointerException at the following line. AcroForm is null
pdfRenderer.PdfDocument.AcroForm.Elements.Add(PdfAcroForm.Keys.SigFlags, new PdfInteger(3));
const string filename = "HelloWorld.pdf";
pdfRenderer.PdfDocument.Save(filename);
Process.Start(filename);
Run Code Online (Sandbox Code Playgroud)
为什么此属性为null?我该怎么做才能将其设置为正确的值?
或者更好的是,如何添加一个字段来选择数字证书?
我正在寻找一个函数来获取图像并确保目标文件的大小小于给定的大小,但尽可能大。
原因是创建最大的 vcard。照片大小为 224KB。
(Apple 或 vcard 限制:https : //support.apple.com/en-us/HT202158)
我想要一个这样的功能:
function (imageBase64, maxFileSize)
{
// Check if image is smaller
// If yes, return the old one.
// If not, reduce image size proportional to fit in maxFileSize
// return newImage
}
Run Code Online (Sandbox Code Playgroud)
你有任何提示如何解决它吗?
我更喜欢在 js 中做这个客户端。但如果不可能,我也接受服务器端 php 解决方案。