DigitalSignature - Run Time
How to insert the signature by digital certificate at runtime.
The goal is to generate the PDF with the signature already in place without user intervention.
The PDF will have several pages, and each page will have a place for the digital signature.
The signature file will be "ANY NAME.PFX, "PASSWORD""
FastReport .NET
Version=2022.2.8.0
Comments
I found a solution:
try
{
string protocolo = "1234567890";
string certificado = "SEU_CERTIFICADO.PFX";
string senha = "999999";
WebReport webReport = new WebReport();
webReport.Report.Load(Server.MapPath("") + "\\SEU_RELATORIO.frx");
webReport.Report.SetParameterValue("ID_PROTOCOLO", protocolo);
webReport.Report.Prepare();
X509Certificate2 cert = new X509Certificate2(certificado, senha);
using (MemoryStream memoryStream = new MemoryStream())
{
PDFExport pdfExport = new PDFExport
{
AllowPrint = true,
Compressed = true,
EmbeddingFonts = true,
ShowProgress = true,
DigitalSignCertificate = cert,
DigitalSignCertificatePassword = senha,
IsDigitalSignEnable = true,
DigitalSignReason = "MOTIVO DO RELATÓRIO: " + protocolo,
DigitalSignLocation = "CIDADE / UF",
DigitalSignContactInfo = "contato@contato.com.br",
Creator = "NOME DE QUEM ESTÁ GERANDO O RELATÓRIO",
HasMultipleFiles = true,
PrintOptimized = true,
};
webReport.Report.Export(pdfExport, memoryStream);
byte[] pdfBytes = memoryStream.ToArray();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=SEU_RELATORIO" + protocolo + ".pdf");
Response.BinaryWrite(pdfBytes);
Response.End();
}
}
catch (Exception erro)
{
string error = erro.Message;
labMensagem.Text = error ;
}