我使用下面的函数使用itextsharp生成pdf。问题是生成的文档将Acro字段展平(不可由用户编辑)。 是否可以使用itextsharp生成/合并pdf,而不使acroform字段变平?
protected override Document ConvertToPdf(XElement rptXData, Document doc, PdfWriter writer)
{
var rptcfg = ReportContext<ReportConfig>.Me;
var pageHeaderFooter = ReportContext<PageHeaderFooter>.Me;
#region values from xml
var showheader = rptXData.Attribute("showheader").BooleanValue();
var showfooter = rptXData.Attribute("showfooter").BooleanValue();
var src = rptXData.Attribute("src").StringValue();
if (src != "") src = System.IO.Path.Combine(rptcfg.ResourceRootPath, src);
#endregion
pageHeaderFooter.IsShowHeader = showheader;
pageHeaderFooter.IsShowFooter = showfooter;
var content = writer.DirectContent;
if (src == "" || !System.IO.File.Exists(src))
{
ReportTable wrapper = new ReportTable(new float[] { DocWidth }, true);
if (System.IO.Path.GetFileNameWithoutExtension(src).ToUpper() == "BLANKPAGE")
wrapper.AddCellEx("");
else
wrapper.AddCellEx("Error in merging outside pages: Page " + src + " does not exist");
doc.Add(wrapper);
return doc;
}
try
{
// Create pdf reader
PdfReader reader = new PdfReader(src);
int numberOfPages = reader.NumberOfPages;
// Iterate through all pages
for (int currentPageIndex = 1; currentPageIndex <= numberOfPages; currentPageIndex++)
{
// Determine page size for the current page
doc.SetPageSize(reader.GetPageSizeWithRotation(currentPageIndex));
// Create page and get the imported page
doc.NewPage();
PdfImportedPage importedPage = writer.GetImportedPage(reader, currentPageIndex);
// Determine page orientation
int pageOrientation = reader.GetPageRotation(currentPageIndex);
if ((pageOrientation == 90) || (pageOrientation == 270))
{
content.AddTemplate(importedPage, 0, -1f, 1f, 0, 0,
reader.GetPageSizeWithRotation(currentPageIndex).Height);
}
else if (pageOrientation == 180) //NEW JUN13; GF-357
{
content.AddTemplate(importedPage, -1f, 0, 0, -1f,
reader.GetPageSizeWithRotation(currentPageIndex).Width,
reader.GetPageSizeWithRotation(currentPageIndex).Height);
}
else
{
content.AddTemplate(importedPage, 1f, 0, 0, 1f, 0, 0);
}
}
}
catch (Exception exception)
{
throw new Exception("PDF Merging Exception:", exception);
}
return doc;
}