У меня есть PDF-файл, в котором есть некоторые страницы, которые необходимо удалить, основываясь на метке (миниатюры) страницы.Итак, я использую метод PdfCopy.GetImportedPage (...) для копирования только нужных страниц, но обнаружил, что метка миниатюры (метка страницы) удаляется.Единственный способ добавить метки страниц - это использовать Writer, но тогда я не могу копировать страницы.Может кто-нибудь помочь мне настроить правильную конструкцию?
public Boolean SplitByList(string povDocument, string povOutputDocument, PageLabelList povPageList)
{
PdfReader lorReader = null;
Document lorDocument = null;
PdfCopy lorPdfCopyProvider = null;
PdfImportedPage lorImportedPage = null;
PdfPageLabels lorLbls = null;
try
{
// Intialize a new PdfReader instance with the contents of the source Pdf file:
lorReader = new PdfReader(povDocument);
lorLbls = new PdfPageLabels();
if (povPageList == null || povPageList.GetLength() == 0) return false;
Boolean lbvFirstPage = false;
for (int livCntr = 1; livCntr <= povPageList.GetLength(); livCntr++)
{
PageLabel lorLabel = povPageList.GetItemAt(livCntr);
if (lorLabel != null && lorLabel.lbvPublish)
{
// Do only the first time
if (!lbvFirstPage)
{
lbvFirstPage = true;
lorDocument = new Document(lorReader.GetPageSizeWithRotation(lorLabel.livPageNumber));
// Initialize an instance of the PdfCopyClass with the source document and an output file stream:
lorPdfCopyProvider = new PdfCopy(lorDocument, new System.IO.FileStream(povOutputDocument, System.IO.FileMode.Create));
lorDocument.Open();
}
// Extract the desired page number:
lorImportedPage = lorPdfCopyProvider.GetImportedPage(lorReader, lorLabel.livPageNumber);
lorLbls.AddPageLabel(livCntr, 1, lorLabel.lorPageLabel);
lorPdfCopyProvider.AddPage(lorImportedPage);
}
}
lorPdfCopyProvider.Close();
lorDocument.Close();
lorReader.Close();
return true;
}
catch (Exception ex)
{
lorDocument.Close();
lorReader.Close();
return false;
}
}
Это ярлык страницы.