Fondah
Fondah

Reputation: 15

Mergefile requests in PDF Toolkit failing

New to Active PDF Toolkit, aattempting to merge up to 100 seperate PDFs into 1. Original PDFs are small, 1-4 pages, but testing has about 1/2 .MergeFile requests failing. Found a lot of pdtk options online, closest to address this issue had sample of just repeating the .MergeFile several times if its not successful, which helped but still getting failures after 500 attempts to .MergeFile and no exceptions are thrown. Hoping someone has another suggestion on how to merge more consistently or what to verify when Mergefile fails in order to fix the issue.

foreach (string pdfFileName in filesToMerge)
{
    filesEnumerated++;
    string fileName = Path.GetFileName(pdfFileName);
    bool mergeSuccessful = false;
    for (int i = 0; i < maxPdfMergeAttempts; i++)
    { 
        if (!mergedFiles.Contains(fileName))
         {
        try
         {
            pdfMergeResult = pdfToolkit.MergeFile(Path.Combine(currentWorkingDirectory, fileName), 0, 0);
            if (pdfMergeResult == 1)
            {
                mergedFiles.Add(fileName);
                mergeSuccessful = true;
                break;
            }
        }
        catch (Exception ex)
        {
            string text2 = String.Format("PDF {0} could not be merged for {1}. MergeReturnCode was  {2}.", fileName, ID,    pdfMergeResult);                                        
            WriteToAppLog(text2);
        }
     }
    }

    if (!mergeSuccessful)
    {
        string text2 = String.Format("PDF {0} could not be merged for ID {1}.", fileName, ID, pdfMergeResult);
        WriteToAppLog(text2);
    filesEnumerated--;
    }
}

Upvotes: 0

Views: 234

Answers (0)

Related Questions