Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Oct 19, 2023 5:33 pm

Hello -

We are having an issue converting PDFs to TIFs using version 9.4.12.0 of Spire.PDF from within with our full framework .NET 4.8 WinForms application. Intermittently users are getting errors (still tracking down exactly the error) or the converted TIF has blank pages or portions of pages. Users are working around the issue by closing and opening the application or having a colleague work with the image they are having problems with. The same image that is failing for one user works fine for another or after a restart.

The twist to this issue is the environment in which our uses are working with this legacy desktop app. Our users log into Azure Virtual Desktops (AVDs) to use this app. That means that multiple users are essentially logging into the same OS instance at the same time and are running the app concurrently in their own slice of a shared memory pool. Testing in isolation works just fine. This library works fine from within the context of an IIS Application Pool correct? How would a multi-user-Windows scenario be any different? In other instances we have seen issues where memory from one user degrades performance for others. Could that be related here?

For what its worth, we are using a .NET 6 version of this library in a multi-threaded background process for very similar reasons with great success. That process converts PDFs to TIFs without problems and its code is identical to the WinForms process.

Code: Select all
public static bool SaveCertImage(byte[] pdfBytes, string destination, int dpiOverride = 0)
{
    using (var document = new PdfDocument(pdfBytes))
    {
        Image[] images = new Image[document.Pages.Count];
        int dpi = (dpiOverride > 0) ? dpiOverride : (document.Pages.Count <= 5) ? 200 : 140;

        for (int i = 0; i < document.Pages.Count; i++)
        {
            images[i] = document.SaveAsImage(i, dpi, dpi);
        }

        //use the save encoder
        Encoder enc = Encoder.SaveFlag;
        EncoderParameters ep = new EncoderParameters(2);
        ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.MultiFrame);
        ep.Param[1] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionLZW);

        ImageCodecInfo info = ImageCodecInfo
            .GetImageEncoders()
            .FirstOrDefault(encoder => encoder.MimeType == "image/tiff");

        if (info == null)
            throw new Exception("image/tiff" + " mime type not found in ImageCodecInfo");

        using (Image tiff = images[0])
        {
            //save the first frame
            tiff.Save(destination, info, ep);

            //save the intermediate frames
            for (int frame = 1; frame < images.Length; frame++)
            {
                ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.FrameDimensionPage);
                tiff.SaveAdd(images[frame], ep);
            }

            //flush and close.
            ep.Param[0] = new EncoderParameter(enc, (long)EncoderValue.Flush);
            tiff.SaveAdd(ep);
        }
       
        Array.ForEach(images, i => i.Dispose());
        return File.Exists(destination);
    }
}

brianchick_truckstop
 
Posts: 3
Joined: Wed Jul 12, 2023 10:45 pm

Fri Oct 20, 2023 2:34 am

Hi,

Thank you for reaching out to us with your feedback.

Regarding the issue you mentioned, our product works properly in an IIS application pool. However, we understand that you are running the project in an Azure Virtual Desktops (AVDs) environment, which we have limited experience with. Unfortunately, we cannot provide a definite answer to your last two questions due to our unfamiliarity with that specific environment.

We suggest that you try updating to the latest version of our product to see if the issues persist.

We apologize for any inconvenience caused by our inability to provide direct answers in this case. If you have any further questions or concerns related to our product, please feel free to reach out to us, and we will do our best to assist you.

Thank you once again for your feedback and your understanding.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri Oct 20, 2023 8:40 pm

Is there anything that looks out of place in my conversion code? Anything that might be something that could cause issues? It works great in isolation and in a multi-threaded background process. Just causes intermittent issues from the WinForms app.

brianchick_truckstop
 
Posts: 3
Joined: Wed Jul 12, 2023 10:45 pm

Mon Oct 23, 2023 2:55 am

Hi,

Thanks for your reply. I have created a WinForms project and successfully utilized your code to convert a PDF document to TIFF format. This successful conversion indicates that there doesn't seem to be any problem with your code.

To further investigate the issue, could you please confirm if the code runs without any problems on your local computer? This will help us determine if the issue is specific to running the code on an Azure virtual desktop or if it extends to other environments as well.

If the code works fine locally, I recommend checking the Azure virtual desktop environment for any possible factors causing the problem or consult Azure's technical support team.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Oct 23, 2023 11:08 pm

Yes, the code works as expected when running in isolation on my local machine. It only has issues when running on the Production AVDs when multiple people are logged in and using the same machine. Keep in mind, this is .NET 4.8 WinForms.

brianchick_truckstop
 
Posts: 3
Joined: Wed Jul 12, 2023 10:45 pm

Tue Oct 24, 2023 9:59 am

Hi,

Thanks for your feedback.
Due to the inability of both you and our team to reproduce this issue locally. This makes it challenging for us to pinpoint the specific issue occurring in the Azure virtual desktop environment. As a result, it is difficult for our developers to conduct an investigation.

Is there any way to help us reproduce this problem? This can help us investigate further.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF

cron