PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PDFsharp doesn't work in Unity Build (InvalidCastException)
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4192
Page 1 of 1

Author:  NiklasDanzHDS [ Mon Oct 26, 2020 3:13 pm ]
Post subject:  PDFsharp doesn't work in Unity Build (InvalidCastException)

Hey,

when I try to generate a PDF through PDFsharp in a Unity Development Build, I get an InvalidCastException:
Code:
 InvalidCastException: Unable to cast object of type 'PdfDictionary' to type 'PdfCatalog'.
  at PdfSharp.Pdf.Advanced.PdfTrailer.get_Root () [0x00000] in <00000000000000000000000000000000>:0
  at PdfSharp.Pdf.PdfDocument.get_Catalog () [0x00000] in <00000000000000000000000000000000>:0
  at PdfSharp.Pdf.PdfDocument.get_Pages () [0x00000] in <00000000000000000000000000000000>:0
  at PdfSharp.Pdf.PdfDocument.get_PageCount () [0x00000] in <00000000000000000000000000000000>:0

When I do the same thing in Play mode in the Unity Editor, it works just fine.

This always happens when importing an editable PDF file (with fields) and getting the first page out of it.

Code:
PdfDocument _importedBgPDF = PdfReader.Open(streamingAssetsPath + "pdf_cover_bg_INTERAKTIV.pdf", PdfDocumentOpenMode.Import);
PdfPage _importedBGPage = _importedBgPDF.Pages[0]; // error happens whenever I try to access the Pages enumerable (also when I call _importedBGPage.PageCount)


I'm using Unity 2019.4.10f1, Windows Plattform, IL2CPP and .NET 4.x.
Thanks for your help, in advance.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/