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);