0 votes

Is it possible to export all my scripts as PDF or word document without having to copy and paste each script?

Godot version v3.2.3
in Engine by (12 points)

Why would you want to do this. Word/PDF are terrible formats for code. Code is plain text.

Its because I need it for documentation, for my A-Level coursework

Well, copy & paste is going to be your solution, then. This is not something that any programmer ever needs, so it's not going to be built in to the engine.

If you want syntax highlighted code, you can use a web-based code formatter (there are a bunch you can search for - Github does it too if you're keeping your code there) and when you c&p into word it will keep the HTML formatting.

Why would you want to do this. Word/PDF are terrible formats for code. Code is plain text.

I was thinking the exact same thing

thank you this was helpful :)

You know what's really helpful ........ my answer

1 Answer

0 votes

Go to Project > Project Settings > Plugins Tab
Create a new plugin and add the following to the script file

extends EditorPlugin

var button = Button.new()
var editor_file_dialog = EditorFileDialog.new()

var property_info = {
    "name": "filesystem/chrome/chrome_exec",
    "type": TYPE_STRING,
    "hint_string": "*chrome.exe"

func _on_Button_pressed():
    var scriptEditor = get_editor_interface().get_script_editor()
    var script = scriptEditor.get_current_script()
    if script:
        var chrome
        if (not ProjectSettings.has_setting("filesystem/chrome/chrome_exec") or 
        not ProjectSettings.get_setting("filesystem/chrome/chrome_exec")):
            editor_file_dialog.window_title = "Choose chrome file"
        chrome = ProjectSettings.get_setting("filesystem/chrome/chrome_exec")

        var source_file = ProjectSettings.globalize_path(script.resource_path)
        var file_name
        var options = ["--headless", "--disable-gpu", "--print-to-pdf="]
        var output_file = source_file.replace(".gd", ".pdf")
        var print_options = "--no-margins"

        if not File.new().file_exists(chrome):
            print("Chome missing cannot do conversion")

        var everything : PoolStringArray
        everything[-1] += output_file

        if OS.execute(chrome, everything, false):
            if File.new().file_exists(output_file):

func file_selected(file_name):
    ProjectSettings.set("filesystem/chrome/chrome_exec", file_name)

func _enter_tree():
    button.text = "Convert to Pdf"

    button.connect("button_up", self, "_on_Button_pressed")
    var scriptEditor = get_editor_interface().get_script_editor()
    var script_panel = scriptEditor.get_child(0).get_child(0)
    var debug = script_panel.get_child(4)

    editor_file_dialog.set_current_dir("c:/Program Files")
    if OS.get_name() == "X11":
    editor_file_dialog.rect_position = Vector2(200, 200)
    editor_file_dialog.rect_size = Vector2(800, 600)
    editor_file_dialog.name = "editor_file_dialog"

    if scriptEditor.has_node("editor_file_dialog"):
        editor_file_dialog = scriptEditor.get_node("editor_file_dialog")
        script_panel.add_child_below_node(debug, button)

    editor_file_dialog.connect("file_selected", self, "file_selected")
    if OS.get_name() == "X11":
        property_info.hint_string = "chrome"

func _exit_tree():

func get_plugin_name():
    return "GD2PDF"

The way its works is to use chrome to do the conversion so if you don't have chrome then you must be an alien who doesn't know what this (1e100) means

While on the script workspace press convert and it will make a pdf of the active script in the same directory with the same name.

Once again i say

This is not something that any programmer ever needs to do

So not tested for all use cases and i'm pretty sure i'm breaking all kinds a rules
Also if you wanted to do batch converting you're on you own but its pretty easy to loop through the project filesystem to achieve it

by (4,972 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.