我 1.阅读PDF文件字段ID,
2.在词典中作为配对,
3.迭代所有字段和设置值。对于第2步和第3步添加代码,
var pdfContents = PDFHelper.GeneratePDF(pdfPath, formFieldMap);
public static byte[] GeneratePDF(string pdfPath, Dictionary<string, string> formFieldMap)
{
var output = new MemoryStream();
var reader = new PdfReader(pdfPath);
var stamper = new PdfStamper(reader, output);
var formFields = stamper.AcroFields;
foreach (var fieldName in formFieldMap.Keys)
{
if (formFieldMap[fieldName] != null)
{
formFields.SetField(fieldName, formFieldMap[fieldName]);
}
}
stamper.FormFlattening = true;
stamper.Writer.CloseStream = false;
stamper.Close();
reader.Close();
return output.ToArray();
}
4.使用以下代码在本地系统中下载
PDFHelper.ReturnPDF(pdfContents, "CMS-1500.pdf");
public static void ReturnPDF(byte[] contents, string attachmentFilename)
{
var response = HttpContext.Current.Response;
if (!string.IsNullOrEmpty(attachmentFilename))
response.AddHeader("Content-Disposition", "attachment; filename=" + attachmentFilename);
response.ContentType = "application/pdf";
response.BinaryWrite(contents);
response.End();
}
5.我可以下载文件,但是如果我尝试打开我会“无法打开”,然后我尝试使用https://www.pdf-online.com/osa/repair.aspx
修复PDF文件,我收到如下错误消息,
Open file.
0x80410108 - E - The end-of-file marker was not found.
- File: CMS-1500.pdf
0x8041010A - E - The 'startxref' keyword or the xref position was not found.
- File: CMS-1500.pdf
0x80410108 - E - The end-of-file marker was not found.
- File: CMS-1500.pdf
Recover XREF table.
0x80410306 - E - The "Length" key of the stream object is wrong.
- Object No.: 648
- File: CMS-1500.pdf
0x80410307 - E - The "endstream" keyword is missing.
- Object No.: 648
- File: CMS-1500.pdf
0x8041010E - E - The file trailer dictionary is missing or invalid.
- File: CMS-1500.pdf
Analyze Objects.
0x80410306 - E - The "Length" key of the stream object is wrong.
- Object No.: 648
- File: CMS-1500.pdf
0x80410307 - E - The "endstream" keyword is missing.
- Object No.: 648
- File: CMS-1500.pdf
0x80410306 - E - The "Length" key of the stream object is wrong.
- Object No.: 648
- File: CMS-1500.pdf
0x80410307 - E - The "endstream" keyword is missing.
- Object No.: 648
- File: CMS-1500.pdf
Analyze Outlines.
Analyze Pages.
0x80410113 - E - The file is corrupt and cannot be repaired. Some of the contents can possibly be recovered.
- Page No.: 2
- File: CMS-1500.pdf
Recover Pages.
Save output file.
0x80410515 - E - The form xobject Xi0 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi1 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi2 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi3 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi4 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi5 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi6 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi7 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi8 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi9 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi10 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi11 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi12 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi13 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi15 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi16 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi17 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi18 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi19 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi20 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi21 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi22 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi23 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi24 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi25 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi26 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi27 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi28 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi29 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi30 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi31 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi32 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi33 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi34 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi35 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi36 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi37 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi38 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi39 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi40 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi41 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi42 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi43 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi44 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi45 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi46 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi47 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi48 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi49 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi50 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi51 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi52 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi53 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi54 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi55 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi56 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi57 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi58 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi59 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi60 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi61 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi62 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi63 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi64 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi65 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi66 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi67 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi68 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi69 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi70 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
0x80410515 - E - The form xobject Xi71 has an empty or unreadable content stream.
- Page No.: 1
- File: CMS-1500.pdf
... (462 lines skipped)
Close file.
3-Heights(TM) PDF repair tool, evaluation license valid until unbounded