Search Unity

Importing and displaying documents such as PDF, DOCX etc.

Discussion in 'Asset Importing & Exporting' started by MystFTG, Sep 18, 2019.

  1. MystFTG

    MystFTG

    Joined:
    Apr 28, 2013
    Posts:
    26
    Hi,
    is there a way for Unity to read and display external documents for example on a UI Canvas or a Texture 2D?

    For example:
    A project has a somewhat extensive ingame documentation, which uses text formatting, images etc.
    The current workflow is to create the document and then export it into a PNG file, import that into Unity and display it on the canvas.
    However, for small changes, the whole process has to be repeated every time.
    Now, if Unity could just read and display the document directly, that would save a lot of work for this particular project.
    Is there a way or document type that Unity can read and then show the contents as a Texture2D or on a canvas/image?

    So far I haven't found anything substantial.
    Having found a PDF renderer on the asset store, makes me believe that this option doesn't exist out of the box and I would have to resort to either buying an asset or writing something similar myself. Well, or just keep making PNGs for the ingame manual.

    But before I consider my options further, I wanted to ask around here, if someone knows a solution for this issue.

    I guess it would also be possible to create TextMeshPro texts by hand in Unity, but the interface doesn't really make a great word processor.



    Thanks for reading and offering any hints or suggestions. If it's impossible, that's also fine, I just want to make sure I don't overlook an obvious solution.
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,638
    There's no built-in way and both of these file formats are going to be difficult to parse in the general sense.

    Rather then trying to render these documents in Unity, it seems like it would be much better and easier to somehow invoke the operating system to open the file in the correct application based on the associated MIME type. I.e. The user clicks a link in your build and suddenly the PDF opens in Acrobat Reader. Not sure how to do that off the top of my head, though.

    Edit: Actually, try this:
    https://docs.unity3d.com/ScriptReference/Application.OpenURL.html
    I think that will do what described above.
     
  3. MystFTG

    MystFTG

    Joined:
    Apr 28, 2013
    Posts:
    26
    Thank you for confirming my suspicion that it's not possible to do with a stock Unity installation.

    Opening an application to just view the file is an easy option, but unfortunately it doesn't work for us. We want to provide a different mini-manual for different scenes. Seems like there's no way around a PDF renderer asset or continuing to use exported images.

    Thanks for the help!