Page count is returning as zero

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Rasterizer for .NET (v3)  /  Page count is returning as zero

DynamicPDF Rasterizer for .NET (v3) Forum

 Feb 15 2022 10:45 PM
Hello,

We are using Rasterizer in our .Net Core API to generate thumbnail for a given PDF page. We have all varieties of documents including signed PDFs, large PDFs etc and these are stored in SAN path. We are creating an instance of InputPdf and then passing it to PdfRasterizer.  After that, we are getting total number of pages with the below code. Occassionally, the total number of pages is coming as zero even though we have the file on the SAN path. After few minutes, for the same PDF file, we get correct number of pages. This is happenning multiple times on a single day on multiple servers. We are not getting document load exceptions while loading pdf using InputPdf. So, the pdf exists in the path.  While the code is returning zero pages for one PDF file, we are getting proper results for other PDF files at the same time on the same server.

Can you please help me to find out the possible reasons for this behavior?

using (var inputPdf = new InputPdf(pdfPath))
{
      using (var pdfDoc = new PdfRasterizer(inputPdf))
      {
          int totalPages = inputPdf.Pages.Count();
      }
}

Thanks
 Feb 16 2022 9:29 AM
Posted by a ceTe Software moderator
Hi,

We tested this on our end and are unable to recreate the issue. Please try reading the file into a byte array and load it to InputPdf object and see it works for you.

Here is a code sample.

            string pdfPath = @"input PDF file path";
            byte[] pdfBytaData = System.IO.File.ReadAllBytes(pdfPath);

            using (var inputPdf = new InputPdf(pdfBytaData))
            {
                using (var pdfDoc = new PdfRasterizer(inputPdf))
                {
                    int totalPages = inputPdf.Pages.Count;
                   
                }
             }

If you continue facing an issue then please send over the following information to support@dynamicpdf.com so we can look into it further.

1. Code sample which uses static data to recreate the behavior.
2. Source PDFs to recreate the behavior.
3. Exact version and build number of the DynamicPDF Rasterizer DLL file used in your application. You can find this information by right clicking on the DLL file>>Properties>>Details tab>>Product version. Take a screenshot of Details tab and send it over to us.

Please include link for this forum in your email to support.

Thanks,
ceTe Software Support Team
 Feb 16 2022 10:40 AM
Thank you for your time and quick response. We will try with byte array as suggested.

Could you please let me know the advantage of using byte array in this scenario when compared to file path? I see that you suggested to use byte array in some of the previous cases, so just wondering about the reason for this.

Thanks
 Feb 16 2022 1:47 PM
Posted by a ceTe Software moderator
Hi,

Using a byte array moves the file handling to your code so you can make sure the file exists, is loaded and do further troubleshooting. We also recommend updating the v3.15 if you are using an older version.

Thanks,
ceTe Software Support Team
 Feb 19 2022 1:49 PM
Thank you for quick reply and details about byte array. We will try with that.

Thanks

All times are US Eastern Standard time. The time now is 12:54 PM.