- Home /
How can I make PDF files in a Unity WebGL build?
I've been using PDFSharp, which works in the editor and standalone builds, but in the WebGL build the PDF isn't even being created in memory:
PdfDocument doc = new PdfDocument();
The error is "NotImplementedException: Cannot create value for key: /Info". I've looked through the PDFSharp source code, but I don't know what WebGL build limitation could be causing this exception.
Does anybody know what changes need to be made so that PDFSharp works with WebGL or know of another library for creating/processing PDF files that works with WebGL?
UPDATE: I've found the problem. In the PDFSharp source code, type.GetFields(...); is returning null in the WebGL build when it shouldn't be (and doesn't in the editor or standalone build). Does anybody know why this would be happening?
Answer by FortisVenaliter · Apr 07, 2017 at 04:05 PM
WebGL is sort of streamed to the browser in question. It doesn't have file system access, so that's probably your issue. If PDFSharp uses a temporary file, or any filename to create it's data, it won't be able to access that file handle. Generally, most .NET plugins (other than the most basic, or ones designed for Unity) won't work outside of PC builds.
If you really need to create a PDF for the user, the only way I know how would be as follows:
You need to write a separate process on the server that can accept requests from the WebGL game and generate a PDF on the server in an accessible location via HTTP.
You can then use the WebGL application to point to the newly generated document URL, which will kick off a download of that document (usually after prompting the user).
I'm not using any of the methods from PDFSharp that involve creating temporary files. Also, I don't have access to the server which the app will be posted on.
So, just to confirm, there are no restrictions with WebGL creating content (IE images, text, xml, etc) and sending to the server? You would basically have the app create all the important data and it would be the responsibility of the server to cobble it all together and produce a final download?
Your answer
![](https://koobas.hobune.stream/wayback/20220612114923im_/https://answers.unity.com/themes/thub/images/avi.jpg)