InvalidCastException when running into a PDF page

Hi,

I got System.InvalidCastException:Unable to cast object of type '#=zmaPilsttvsIvdV2DclQIxSNM2sLLoJRB2Q==' to type '#=zDWSpJJBRHP0zQB1mC3DHDtSapyDYEdQiVQ=='. when loading a pdf file.
Using SDK: Aspose.PDF for .Net 24.1
Using Code:

    Document pdfDocument = new Document("[现代名中医高血压中风治疗绝技].吴大真等.扫描版.pdf");
    Page pdfPage = pdfDocument.Pages[69];

Using file:
[现代名中医高血压中风治疗绝技].吴大真等.扫描版.7z (5.2 MB)

@kngstr

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-56397

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as PDFNET-56397) have been fixed in Aspose.PDF for .NET 24.3.

Hi,
Error occurs when I try to compress this pdf file.

Tested OSs were Win7 and Win10
.NET target platform is .net 6.0
Using SDK: Aspose.PDF for .Net 24.3

Test code

void testCompressPdf(string filename)
{
    Document pdfDocument = new Document(filename);

    OptimizationOptions pdfOptions = new OptimizationOptions();
    pdfOptions.CompressObjects = true;
    pdfOptions.LinkDuplcateStreams = true;
    pdfOptions.RemoveUnusedObjects = true;
    pdfOptions.RemoveUnusedStreams = true;
    pdfOptions.AllowReusePageContent = true;
    pdfOptions.UnembedFonts = false;
    pdfOptions.SubsetFonts = true;
    pdfOptions.MaxResoultion = 300;


    pdfOptions.ImageCompressionOptions.CompressImages = true;
    pdfOptions.ImageCompressionOptions.ResizeImages = true;
    pdfOptions.ImageCompressionOptions.ImageQuality = 80; // 图片清晰度

    pdfDocument.OptimizeResources(pdfOptions);

    pdfDocument.Save(filename + ".output.zip.pdf");
}

testCompressPdf("[现代名中医高血压中风治疗绝技].吴大真等.扫描版.pdf");

Exception detail

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type '#=z1XA5xQdtCYRfL0R0rtKDai5YzqrEj1H89Q==' to type '#=zOswZtf8rRu8dLRk6h3fontEkm053wfG8KA=='.
  Source=Aspose.PDF
  StackTrace:
   在 #=zNnZKUM1IXHHjum$VoZx634swJFmTcVJECw==.#=zDCbt_zjmk$6U()
   在 #=zNnZKUM1IXHHjum$VoZx634swJFmTcVJECw==.#=zGqRzlNmX0XkY(Int32 #=zO9_QvbZcU6VV, Int32& #=zDlDFc6FDOkhC)
   在 #=zNnZKUM1IXHHjum$VoZx634swJFmTcVJECw==.#=z1Tcg434=(Int32 #=zO9_QvbZcU6VV)
   在 Aspose.Pdf.PageCollection.#=zOMrprj5IA2SE55B_FUWX98Q=(Int32 #=zsL0pJ3Y=)
   在 #=zrb$IqnzKCkb7G2bW6ptsbiouvkdZiA9d9ZHxAnk6BAhZzVmin6DYdSo=.#=z504fJP4=()
   在 #=zrb$IqnzKCkb7G2bW6ptsbiouvkdZiA9d9ZHxAnk6BAhZzVmin6DYdSo=.#=zKJ2fzh1l_iTb(FontSubsetStrategy #=z$BLY$LQKz$uy)
   在 #=za7F2JHR8490dB3uL4ASTsNyXwk0r.#=z9kDE0uY=(OptimizationOptions #=zHRmC4pg=)
   在 Aspose.Pdf.Document.OptimizeResources(OptimizationOptions strategy)
   在 Program.<<Main>$>g__testCompressPdf|0_1(String filename) 在 C:\.NET\ConsoleApp1\ConsoleApp1\Program.cs 中: 第 34 行
   在 Program.<Main>$(String[] args) 在 C:\.NET\ConsoleApp1\ConsoleApp1\Program.cs 中: 第 39 行

@kngstr

Can you please share your sample PDF document as well so that we can test the scenario in our environment and address it accordingly.

@asad.ali
It’s the same file which was provided in this topic.

@kngstr

We are testing it and will get back to you shortly.

@asad.ali

Hi, is there any news?

@kngstr

We have been busy in testing and investigating other issues in the queue, we are afraid that we could not test the case. However, we will be sharing updates with you today shortly.

@kngstr

We faced different i.e NullReferenceException in our environment while testing the scenario with 24.4 version of the API.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-57142

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@asad.ali

OK. Thanks.

1 Like

The issues you have found earlier (filed as PDFNET-57142) have been fixed in Aspose.PDF for .NET 24.10.