0

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--;
    }
}
Fondah
  • 15
  • 3
  • Is the code you are sharing based on Active PDF Toolkit or pdftk? It looks like it is based on Active PDF Toolkit, I am not really familiar with either enough to be able to say for certain though. In the [documentation](http://www.activepdf.com/AltDownloads/Documentation/TK2011/MergeFile.html) for Active PDF Toolkit's merge functionality though it says it closes the input files and appends to the current output file, have you set an output file to be used? – Brandon Haugen Apr 18 '16 at 14:48
  • this is active pdf, and yes an outputfile is defined initially (string finalMergedPdfPath) and yes the output file does get created, put it doesn't include all the files to be merged, for example if there are 20 files to merge the 1st 15 merge the next 2 do not and then the remaining 3 merge. The only message i'm getting is the 'could not be merged...' message from the !mergeSuccessful condition – Fondah Apr 21 '16 at 00:03
  • Is there something specific about those two files that do not merge? Are they corrupt/damaged? Are they password protected or have permissions applied to them that do not allow merging? If you try just merging those two documents together, does it succeed? – Brandon Haugen Apr 22 '16 at 15:29
  • No, nothing unique about the files being merged, they can be merged separately, without an issue, if I rerun the merge, with the same group of files, the files merge successfully, the merge results aren't consistent – Fondah Apr 25 '16 at 16:01
  • That is really strange. I would love to help further, I don't know Active PDF though and the input files would need to be provided. Have you tried contacting Active PDF about the issue? – Brandon Haugen Apr 26 '16 at 14:11
  • Thank you for reviewing. I have not had a response from the vendor, but will try them again. Thank you again. – Fondah May 01 '16 at 11:31

0 Answers0