0
아래 주어진 C# 코드를 사용하여 itextsharp를 사용하여 pdf 문서에서 페이지를 추출합니다. 페이지가 잘 추출되지만 어쨌든 acro 필드가 엉망입니다. 내가보고 추출 된 페이지 아크로 필드에 데이터를 입력 할 수 있어요하지만 코드에서 아크로 필드의 수를 확인할 때이 추출 "0"itextsharp를 사용하여 페이지로 PDF를 유출하는 동안 Acro 필드 유지
코드로 다가오고 :
public void ExtractPage(string sourcePdfPath, string outputPdfPath, int pageNumber)
{
PdfReader reader = null;
Document document = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage = null;
try
{
// Intialize a new PdfReader instance with the contents of the source Pdf file:
reader = new PdfReader(sourcePdfPath);
// Capture the correct size and orientation for the page:
document = new Document(reader.GetPageSizeWithRotation(pageNumber));
// Initialize an instance of the PdfCopyClass with the source
// document and an output file stream:
pdfCopyProvider = new PdfCopy(document,
new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));
document.Open();
// Extract the desired page number:
importedPage = pdfCopyProvider.GetImportedPage(reader, pageNumber);
pdfCopyProvider.AddPage(importedPage);
document.Close();
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
}
코드 아크로 필드를 확인합니다 : 당신은 페이지를 추출하는 잘못된 코드를 사용하는
private static int GetNumberOfSignatures(string FileName)
{
int best = 0; if (Path.GetExtension(FileName) != ".pdf" || !File.Exists(FileName)) return 0;
var form = new PdfReader(FileName).AcroFields;
var formFields = form.Fields;
foreach (var cur in formFields)
{
if (cur.Key.ToLower().StartsWith("signature_placeholder_"))
{
int val = 0;
if (!int.TryParse(cur.Key.Substring(22), out val)) val = 0;
if (val > best) best = val;
}
if (cur.Key.ToLower() == "signature_placeholder" && best < 1) best = 1;
}
return best;
}