GdPicturePDF RenderPageToGdPictureImage is generating blank page

Discussions about PDF management.
Post Reply
diogosouza
Posts: 3
Joined: Mon Sep 25, 2017 8:26 pm

GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by diogosouza » Mon Sep 25, 2017 8:53 pm

I'm getting an existing PDF and generating a new PDF from it.

The method was working until very recently when it started generating PDFs with all blank pages. No error is being thrown and GdPictureStatus is always OK.

The only change that has occurred is that the infrastructure team has applied some updates on Windows, which is in the 2012 R2 version.

A curious fact is that if I change the RenderPageToGdPictureImage method to RenderPageToGdPictureImageEx, one PDF file has been generated correctly, but another file has remained blank.

On my machine the problem does not occur, just in production.

We have the GdPicture.NET version 12.0.0.65.

My code looks like this:

Code: Select all

               
               this.gdPictureOriginalPDF = new GdPicturePDF();
                status = this.gdPictureOriginalPDF.LoadFromStream(stream);

                if (status == GdPictureStatus.OK)
                {
                    if (this.gdPictureOriginalPDF.IsEncrypted())
                    {
                        ////PDF is encrypted, try to decrypt by using empty password
                        if (this.gdPictureOriginalPDF.SetPassword(string.Empty) == GdPictureStatus.OK)
                        {
                            this.gdPictureOriginalPDF.CloseDocument();
                            return PDFStatus.PasswordNeeded;
                        }
                    }
                }

                this.gdPicturePDF = new GdPicturePDF();
                this.gdPicturePDF.NewPDF(true);
                this.gdPicturePDF.EnableCompression(true);
                this.gdPicturePDF.SetCompressionForBitonalImage(PdfCompression.PdfCompressionJBIG2);
                this.gdPicturePDF.SetCompressionForColorImage(PdfCompression.PdfCompressionJPEG);
                this.gdPicturePDF.SetTitle(this.gdPictureOriginalPDF.GetTitle());
                this.gdPicturePDF.SetAuthor(this.gdPictureOriginalPDF.GetAuthor());

                for (int i = 1; i <= this.gdPictureOriginalPDF.GetPageCount(); i++)
                {
                    if (this.gdPictureOriginalPDF.SelectPage(i) == GdPictureStatus.OK)
                    {
                        using (GdPictureImaging oGdPictureImaging = new GdPictureImaging())
                        {
                            int imageID = this.gdPictureOriginalPDF.RenderPageToGdPictureImage(300, true);

                            if (this.gdPictureOriginalPDF.GetStat() == GdPictureStatus.OK)
                            {
                                this.gdPicturePDF.AddImageFromGdPictureImage(imageID, PdfAdvancedImageCompression.PdfAdvancedImageCompressionNone);
                            }

                            oGdPictureImaging.ReleaseGdPictureImage(imageID);
                        }
                    }
                }
                
                //this line is just for test
                status = this.gdPicturePDF.SaveToFile(@"c:\temp\PDF" + DateTime.Now.ToString("dd-MM-yyyy_HHmmss") + ".pdf", PdfEncryption.PdfEncryptionNone, string.Empty, string.Empty, true, false, false, false, false, false, false, true);

oha
Posts: 5
Joined: Mon Oct 03, 2016 2:38 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by oha » Thu Sep 28, 2017 10:46 am

We face exactly the same problem.

What we know:

- RenderPageToGdPictureImage method fails with default Rasterizer engine if run as Windows Service ONLY!
- RenderPageToGdPictureImageEx method works if PDF contains just images -> whole page is filled by an image
- If one explicitly choose "PdfRasterizerEngineGdiplus":

RenderPageToGdPictureImage(pResolution, true, PixelFormat.Format32bppPArgb, PdfRasterizerEngine.PdfRasterizerEngineGdiplus);

everything seems to work again.
It seems that "PdfRasterizerEngineWPF" is used by default. Or in some cases "PdfRasterizerEngineHybrid" one?

What we don't know:

- what exactly MS update/hotfix (KB number) brings the problem
- if the problem occurs just on Win Server 2012 R2

oha
Posts: 5
Joined: Mon Oct 03, 2016 2:38 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by oha » Thu Sep 28, 2017 3:36 pm

This one seems to be the trouble-maker: KB 4040972

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by Cedric » Fri Sep 29, 2017 11:17 am

This is a known problem introduced by Microsoft lately. See https://connect.microsoft.com/VisualStu ... ls/3141218
You can of course uninstall the problematic Windows update patch and wait for Microsoft to fix it properly or implement a workaround.
The workaround is to use the overload that lets you choose the rasterization engine and select GDI+ here:
https://www.gdpicture.com/guides/gdpicture/we ... gine).html

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by Cedric » Fri Sep 29, 2017 11:20 am

oha wrote:
Thu Sep 28, 2017 10:46 am
It seems that "PdfRasterizerEngineWPF" is used by default. Or in some cases "PdfRasterizerEngineHybrid" one?
That's correct, default is PdfRasterizerEngineHybrid.
oha wrote:
Thu Sep 28, 2017 3:36 pm
This one seems to be the trouble-maker: KB 4040972
This is only partially true for Windows Server 2012 R2, other versions have different KB involved, as far as we know here is the list:

Windows Server 2008: KB4040977, KB4040973, KB4041086
Windows Server 2008 R2: 4040977, 4040973, 4041083
Windows 7: KB4040977, KB4040973, KB4041083
Windows Server 2012: KB4040975, KB4040971, KB4041084
Windows Server 2012 R2: KB4040974, KB4040972, KB4041085
Windows 8.1: KB4040974, KB4040972, KB4041085

oha
Posts: 5
Joined: Mon Oct 03, 2016 2:38 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by oha » Fri Sep 29, 2017 11:47 am

Okay, cool. :-)
Is the "PdfRasterizerEngineGdiplus" 100% replacement?
I'm afraid we can't test "all possible" PDFs in short time.

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by Cedric » Fri Sep 29, 2017 11:54 am

Yes, GDI+ rasterization engine is not impacted by this Microsoft blunder, the difference could be about the performances as GDI+ is supposedly slower.
That being said, the difference should be barely noticeable if at all, GDI+ has been greatly improved since a few months.

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by Cedric » Tue Oct 24, 2017 2:14 pm

It looks like Microsoft has fixed the issues in the October updates.

bsi
Posts: 1
Joined: Wed Oct 25, 2017 3:15 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by bsi » Wed Oct 25, 2017 3:34 pm

Microsoft's October "fix to the fix" appears to be that they make the September "fix", that caused the issue, optional and inactive by default.

MS writes in https://support.microsoft.com/en-us/help/4043601/ that they do not recommend to use WPF rendering in a windows service. And in https://support.microsoft.com/en-us/help/4043762 they state that using WPF in that way can lead to performance issues and crashes, which can be addressed by reinstating the now optional "fix" provided in the September rollup, bringing us back the blank pages from GDPicture's default rasterization.

Now the question is if Orpalis recommends the use of RenderPageToGdPictureImage in Windows services or not? Maybe the performance & crashing issues mentioned by MS are prevented in some other way?

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: GdPicturePDF RenderPageToGdPictureImage is generating blank page

Post by Cedric » Wed Oct 25, 2017 3:57 pm

Now the question is if Orpalis recommends the use of RenderPageToGdPictureImage in Windows services or not?
The issue is much bigger than just RenderPageToGdPictureImage. For instance DocuVieware, being hosted on a IIS instance, it runs as a service thus it is also impacted by the blank pages issue. We have a lot of customers that are running services with imaging features in it without being able to easily fall back on the GDI+ rasterization engine if at all.

The only reliable way to get this resolved is still to uninstall the culprit patch and separately install the security updates which is exactly what they have done in the October fix apparently. I don't know if this will be really fixed the way it should one day.

Microsoft has been pushing everyone to adopt WPF for years, it was working before the September fix, they broke it and now they say they do not recommend to use WPF rendering in a Windows service. How convenient...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests