I'm attempting to use Spire.PDF with Unity.. I've installed the free evaluation version spire.pdf-fe_4.3 and copied sprire.pdf.dll and spire.licence.dll from the NET 3.5 directory to my assets directory.
I'm using the following code for testing...
- Code: Select all
using Spire.License; // Not sure if this is needed but makes no difference to my error
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
public class SavePDF : MonoBehaviour
{
public void savePDF()
{
pdfTest();
}
void pdfTest()
{
PdfDocument doc = new PdfDocument();
PdfSection section = doc.Sections.Add();
PdfPageBase page = doc.Pages.Add();
//Load a tiff image from system
PdfImage image = PdfImage.FromFile("c:/users/Alex/Desktop/Logo.png");
//Set image display location and size in PDF
float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
float fitRate = Mathf.Max(widthFitRate, heightFitRate);
float fitWidth = image.PhysicalDimension.Width / fitRate;
float fitHeight = image.PhysicalDimension.Height / fitRate;
page.Canvas.DrawImage(image, 30, 30, fitWidth, fitHeight);
doc.SaveToFile("c:/users/Alex/Desktop/Test.pdf");
doc.Close();
}
}
but as soon as pdfTest() is triggered I get the following error...
- Code: Select all
InvalidProgramException: Invalid IL code in Spire.License.LicenseProvider:.cctor (): IL_0014: pop
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Spire.License.LicenseProvider
System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:513)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:519)
System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:528)
System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:77)
System.Activator.CreateInstance (System.Type type, Boolean nonPublic) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Activator.cs:372)
System.Activator.CreateInstance (System.Type type) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Activator.cs:254)
System.ComponentModel.LicenseManager.privateGetLicense (System.Type type, System.Object instance, Boolean allowExceptions, System.ComponentModel.License& license)
System.ComponentModel.LicenseManager.IsValid (System.Type type, System.Object instance, System.ComponentModel.License& license)
Spire.Pdf.PdfDocumentBase.ᜀ ()
Spire.Pdf.Pdf
Any idea what might be causing this issue? Do I need to manually set a licence file location?
Many thanks!