- Home /
PDFSharp working in editor but not in build
I'm working on a project in Unity and from within the build I need to be able to export data to a pdf.
For the export to PDF I'm using PDFSharp version 1.32.3057.
The player settings are as follows:
 - Unity 2018.1.0f2
 - Scripting Runtime Version: .NET 4.x Equivalent
 - Scripting Backend: Mono
 - Api Compatibility Level: .NET Standard 2.0
To produce the PDF, I use the following code:
 string in_img = "C:\\test.jpg"
 string out_pdf = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop), "test.pdf");
 
 PdfDocument doc = new PdfDocument();
 PdfPage page = doc.AddPage();
 
 page.Height = XUnit.FromInch(26.67f);
 page.Width = XUnit.FromInch(15f);
 page.Orientation = PdfSharp.PageOrientation.Landscape;
 
 using (XGraphics gfx = XGraphics.FromPdfPage(page)) {
     using (XImage image = XImage.FromFile(in_img)) {
         gfx.DrawImage(image, 0, 0, 3840, 2160);
     }
 }
 
 doc.Save(out_pdf);
 doc.Close();
Running the code in the editor produces a PDF as expected.
Building the code and running the build, however, results in the following error:
 TypeLoadException: Could not load type of field 'PdfSharp.Drawing.XGraphics:gfx' (12) due to: Could not resolve type with token 01000047 (from typeref, class/assembly System.Drawing.Graphics, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a) assembly:System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Drawing.Graphics member:(null) signature:<none>
   at PdfExport.Start () [0x00077] in C:\...\Unity PDF Test\Assets\PdfExport.cs:27 
I already searched on Google and Stackoverflow to find a clue to fix the error. Until now without success. I hope someone can point me into the right direction.
What is the cause of the error? And what do I have to do to fix it?
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to generate pdf for android? 2 Answers
Renderer on object disabled after level reload 1 Answer
Displaying PDF in unity 5.1.2f1 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                