简体   繁体   中英

How to display a digital signature was signed in PDF file

I signed a PDF file by MakeSignature.SignDetached of iTextSharp 5.5.11.0. After I converted it into string and saved it in database.
I request it from web browser by the below paragraph, but can not display the digital signature. Who can help me explain?

//PDFSigned is string get from database
byte[] info = System.Convert.FromBase64String(PDFSigned);
PdfReader reader = new PdfReader(info);
Document doc = new Document(PageSize.A4, 25, 10, 25, 10);
PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
//open doc to create page of PDF
doc.Open();
PdfContentByte cb = writer.DirectContent;               
doc.NewPage();
PdfImportedPage page = writer.GetImportedPage(reader, reader.NumberOfPages);
cb.AddTemplate(page, 0, 0);
                    
doc.Close();
writer.CloseStream = false;
reader.Close();           

Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.End();

Thanks!

Your code mutilates the pdf from the database and throws away everything except static page content of the last page. That in particular discards the signature.

If you actually merely want to allow users to download any pdf files from database , you can simply directly respond the PDF bytes you get by base64 decoding the string from the database.

That should be something like this:

//PDFSigned is string get from database
byte[] info = System.Convert.FromBase64String(PDFSigned);

Response.OutputStream.Write(info, 0, info.Length);

Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.End();

(I'm not really into.Net web service programming, so details might be less than optimal.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM