Search code examples
pdfsavegodotgdscript

What do I should use for saving a text like a pdf in gdscript


I want to make a multi-device software with godot engine and I want to make it as lite as I can, so I just want to use a Line edit node and a button for saving the text but, is there any way to save it as .txt and .pdf files with code or I need an extra plugin?


Solution

  • Writing a plain text file is relatively easy:

    var file = File.new()
    file.open("user://some_file.txt", File.WRITE)
    file.store_string("Some text")
    file.close()
    

    PDF is more difficult. I don't think that there are any out of the box solutions. But remember that PDF is also just a text file with specific commands embedded into the text. You would have to study the specifications of a PDF file and then generate the required structures yourself via the method described above.