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?

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:

1.) 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.
2.) 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).