We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Page iterator loop breaks after two loops



Following issue was reported was fixed long back. it was fixed but with latest Aspose.pdf this issue ss still reproducible.We are using Aspose.17.2 licensed version.

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)
{
}
}

Hi Viral,


Thanks for you inquiry.

I have tried to use your code snippet to test the scenario but I could not execute it as there are undefined objects in the code. Though I have tested the scenario with following code snippet by splitting the PDF and I did not notice any exception. I have tested the scenario with both Aspose.Pdf for .NET 17.2.0 and 17.3.0.

var pdfDocument = new Document(dataDir + “DifferentStyles.pdf”);<o:p></o:p>

for(int i = 1; i<= pdfDocument.Pages.Count; i++)

{

Document doc = new Document();

doc.Pages.Add(pdfDocument.Pages[i]);

doc.Save(dataDir + "out-page-" + i.ToString() + ".pdf");

}


Please note that sometimes issue may be related with specific input file. We will really appreciate if you please can share you sample input file along with working sample code snippet so that we can test the scenario in our environment. We are sorry for the inconvenience.


Best Regards,