- Home /
Integrating IronPdf crashes unity
I worked with itextpdf which worked well with unity, but i had to switch to IronPdf as i needed to work with arabic, which was a problem because it needed an itextpdf add-on that wasn't free.
Anyway IronPdf seemed to work well when i tried it on a console app, but unity freezes as soon as i call the function that has the code.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using IronPdf;
public class ConvertPDF : MonoBehaviour
{
public TextMeshProUGUI txt;
public void Nothing()
{
Debug.Log("Nothing");
}
public void Html2PDF()
{
Debug.Break();
string msg = "";
try
{
IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
IronPdf.PdfDocument PDF = Renderer.RenderHTMLFileAsPdf("input.html");
string OutputPath = "output.pdf";
PDF.SaveAs(OutputPath);
msg = "Generated to " + OutputPath;
}
catch (Exception e)
{
msg = e.Message;
}
txt.text = msg;
Debug.Log(msg);
}
}
I call this function when a button is pressed and unity crashes even though i added the dll of the library to unity the same way i did with itextpdf.
And what's the error message? Have read through the player log? https://docs.unity3d.com/$$anonymous$$anual/LogFiles.html
I got in touch with the IronPDF developers, here is the answer:
"Currently Unity 3D isn't supported by IronPDF but it is something we plan on releasing for out next update."
Answer by rubenmueller · Oct 17, 2019 at 08:26 PM
Edit:
I got in touch with the IronPDF developers, here is the answer:
"Currently Unity 3D isn't supported by IronPDF but it is something we plan on releasing for out next update."
Edit End
I have got the same problem. Editor/Application freezes, in the logfile it says:
Building with mono:
SecurityException: Couldn't impersonate token.
at System.Security.Principal.WindowsImpersonationContext..ctor (System.IntPtr token) [0x0001a] in <1f0c1ef1ad524c38bbc5536809c46b48>:0
at System.Security.Principal.WindowsIdentity.Impersonate (System.IntPtr userToken) [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0
at IronPdf.ThreadSaftyManager.ThreadSafeConverter.Run () [0x00001] in <607c014b8c0046489fc16f0ce66751a3>:0
at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in <1f0c1ef1ad524c38bbc5536809c46b48>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <1f0c1ef1ad524c38bbc5536809c46b48>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in <1f0c1ef1ad524c38bbc5536809c46b48>:0
at System.Threading.ThreadHelper.ThreadStart () [0x00008] in <1f0c1ef1ad524c38bbc5536809c46b48>:0
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.UnhandledExceptionHandler:<RegisterUECatcher>m__0(Object, UnhandledExceptionEventArgs)
Building with il2cpp:
NotSupportedException: C:\Program Files\UnityVersions\2019.1.5f1\Editor\Data\il2cpp\libil2cpp\icalls\mscorlib\System.Security.Principal\WindowsImpersonationContext.cpp(27) : Unsupported internal call for IL2CPP:WindowsImpersonationContext::DuplicateToken - "This icall is not supported by il2cpp."
at System.Security.Principal.WindowsImpersonationContext..ctor (System.IntPtr token) [0x00000] in <00000000000000000000000000000000>:0
at System.Security.Principal.WindowsIdentity.Impersonate (System.IntPtr userToken) [0x00000] in <00000000000000000000000000000000>:0
at IronPdf.ThreadSaftyManager.ThreadSafeConverter.Run () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.DeserializationEventHandler.Invoke (System.Object sender) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
System.Xml.OnDefaultAttributeUseDelegate:Invoke(IDtdDefaultAttributeInfo, XmlTextReaderImpl)
I made a simple testapplication with WPF and there runs IronPDF like a charm.
Your answer
![](https://koobas.hobune.stream/wayback/20220612210533im_/https://answers.unity.com/themes/thub/images/avi.jpg)