如何阅读PDF图层并使用iTextSharp
将其添加到其他页面?
我想从一个PDF页面复制图层并将它们移动到C#中的另一个PDF页面。
我尝试从一个页面读取PDF图层,但我无法复制该图层。
var document = new Document();
FileStream outfile = new FileStream(outPutFilePath, FileMode.Create);
var writer = new PdfCopy(document, outfile);
document.Open();
foreach (var fileName in filesPath)
{
var reader = new PdfReader(fileName);
PdfStamper stamper = new PdfStamper(reader, outfile);
Dictionary<String, PdfLayer> layers = stamper.GetPdfLayers();
//PdfLayer layer = layers.get("Nested layer 1");
//layer.setOn(false);
for (var i = 1; i <= reader.NumberOfPages; i++)
{
var page = writer.GetImportedPage(reader, i);
page.ContentTagged = true;
writer.AddPage(page);
}
stamper.Close();
reader.Close();
}
writer.Close();
document.Close();