Handling an error using the get pdf page count for a slowly downloaded file

Hello,
I am working on a project that is running great but has one issue. I am taking pdf files generated from an external source and getting dropped into a folder. It starts by putting the file in the folder with 0kb then as it downloads it finally gets to its full size and can be opened. I am using a for each file in folder function and then progressing to get the pdf page count. The Get pdf page count errors out each time since the file cannot be opened at first. The time it takes to populate the PDF is variable and it needs to be processed as soon as it is able to be opened. I tired using a retry scope on it but that did not fix it. Any help would be greatly appreciated!

Matt

there’s a Wait for Download activity - but i don’t think it would work given your scenario but worth a shot

other than that, you can keep polling the file size attribute or last write until there’s no more change confirmed. You can then proceed.

Thank you! I will give that a try :slight_smile: I did think of the wait for download but i couldnt figure out what to have it wait for …

If you are encountering issues with the “Get PDF Page Count” activity due to the PDF file not being fully generated or available at the beginning, you can implement a retry mechanism to handle this situation. Here’s a possible approach to address the issue:

  1. Use a “Do While” or “While” loop: Instead of using a “For Each File in Folder” activity directly, you can wrap it within a “Do While” or “While” loop. This loop will continue executing until the PDF file is fully generated and available for processing.

  2. Check file size: Within the loop, add a condition to check the file size of the PDF file. You can use the File.Exists and FileInfo classes to check the size. If the file size is still 0KB, continue the loop. Once the file size exceeds 0KB, proceed to the next step.

  3. Use a “Retry Scope”: Within the loop, encapsulate the “Get PDF Page Count” activity with a “Retry Scope” activity. Configure the “Retry Scope” to retry a certain number of times with a suitable delay between retries.

  4. Handle exceptions: In case the “Get PDF Page Count” activity throws an exception, catch the exception within the “Retry Scope” and allow the retry mechanism to execute again. This will ensure that the activity is retried until the PDF file is successfully processed.

  5. Exit the loop: Once the “Get PDF Page Count” activity successfully retrieves the page count without any exception, exit the loop and proceed with the next steps in your workflow.

By implementing this retry mechanism, your workflow will keep attempting to read the page count of the PDF file until it is fully generated and available for processing. It allows for variations in the time it takes to populate the PDF file, ensuring that the activity executes as soon as the file is ready.

Adjust the number of retries and the delay between retries in the “Retry Scope” activity based on your specific requirements and the expected time it takes for the PDF file to become fully available.

Note: Make sure to handle any other exceptions that may occur within the loop to ensure proper error handling and prevent the workflow from getting stuck in an infinite loop.

thank you for your suggestion, I will try this as well! I did have get pdf page count wrapped in retry scope but it would still error out. It was my first time using retry scope, seems like it needs a few extra steps.

I tried this and it is still giving me a file does not exist error and it will not retry the activity. So far the only way i have gotten this to work is to put a delay in before the get pdf page count. but this could cause issues if the file takes a bit longer to download… I have attached a screenshot of my workflow, maybe i did something wrong?