https://forum.aspose.com/t/16381
Code snippet
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(this.templateFileSource.FilePath);
PersistenceHelper.SetConfiguration(PlatfromType.FileSplit);
// PageIterator itr = doc.GetPageIterator();
string finalTargetFolderPath = GetNextAvailableTempFolder(PersistenceHelper.GetMailMergeTempFolderPath());
List allocatedIDs = new List();
try
{
// doc.InitSecurityHandler();
int itemCounter = 0;
bool isTextFound = false;
bool isFirstTime = false;
//ArrayList copy_pages = new ArrayList();
Aspose.Pdf.Document copy_pages = new Aspose.Pdf.Document();
//Loop through all the pages
foreach (Aspose.Pdf.Page pdfPage in doc.Pages)
{
Aspose.Pdf.Text.TextAbsorber txt = new Aspose.Pdf.Text.TextAbsorber();
txt.Visit(pdfPage);
string pageText = txt.Text;
if (pageText.ToUpper().IndexOf(this.TemplateFileSource.Delimiter.ToUpper()) >= 0)
{
FindUniqueIdentifier(ref distributionItem, pageText, allocatedIDs);
copy_pages.Pages.Add(pdfPage);
isTextFound = true;
continue;
}
if (isTextFound)
{
if (pageText.ToUpper().IndexOf(this.TemplateFileSource.Delimiter.ToUpper()) < 0)
{
FindUniqueIdentifier(ref distributionItem, pageText, allocatedIDs);
copy_pages.Pages.Add(pdfPage);
}
}
}
try
{
string itemFolderName = string.Empty;
itemFolderName += "tmp" + ++itemCounter;
DirectoryInfo directory = new DirectoryInfo(finalTargetFolderPath + @"\" + itemFolderName);
if (!directory.Exists)
directory.Create();
//This is the handling of duplication file.
int suffix = GetFileNumberSuffix(distributionItem, distItemFileList);
string[,] itemInfo = new string[1, 2];
itemInfo[0, 0] = distributionItem.FileName;
itemInfo[0, 1] = distributionItem.folderId;
distItemFileList.Add(itemInfo);
Aspose.Pdf.Document newDocument = new Aspose.Pdf.Document();
foreach (Aspose.Pdf.Page pdfPage in copy_pages.Pages)
{
newDocument.Pages.Add(pdfPage);
}
//for (int j = 1; j != copy_pages.Pages.Count; ++j)
//{
// newDocument.Pages.Add(copy_pages.Pages[j]);
// // pdfDoc.PagePushBack((pdftron.PDF.Page)imported_pages[j]);
//}
distributionItem.GeneratedFilePath = directory.FullName + @"\" + Path.GetRandomFileName() + ".pdf";
newDocument.Save(distributionItem.GeneratedFilePath, Aspose.Pdf.SaveFormat.Pdf);
distributionItem.fileSize = CommonUtilities.BytesToString((new FileInfo(distributionItem.GeneratedFilePath)).Length);
distributionItem.MarkDirty();
if (itemCounter != distributionItems.Count)
}
}
catch (Exception ex)
{
}
}