Generate PDF

Hello, I need your help, please.

Is there any way of generating a PDF with some content and images from the game?

Sort of a screenshot, with more information, more text, etc.

I cannot find a PDF extension, but maybe you can help.
Thanks

There is no PDF extension as far as I know. This seems like a good starting point for anyone wanting to create a PDF extension though:

3 Likes

What is the use case for the need to export to this file format?

Perhaps there is an alternative solution to your issue, depending on the purpose of the proposed exported document.

1 Like

I’m not clear on the use case here.
Surely it will be a lot easier to grab screenshots from the editor/game, and also use them in your document? Also “more text” doesn’t really specify what text that should be. :thinking:

1 Like

I want to generate a map, roguelike map or maybe something closer to a maze.

To that map created in the game, I want to add some tables for rolling dice, etc.

So, I want to combine the maze generated in the game, with some tables etc and export this to a PDF to be printed and played. Kind of a Solo TTRPG / Print and Play game.

I believe that generating a PDF is better than exporting a PNG image to be printed.

If you have any ideas, I really appreciate.

Take a look at the image, this is just a little example.

3 Likes

There is this Defold-PNG extension already:

But I never used it - maybe exporting to PNG would be a first, quick catching point for prototype? Otherwise - yes, writing an extension for PDF would be necessary - if you decide to, here’s manual to help you start Writing native extensions for Defold. It’s good to write an extension like in a manual to get to know the workflow. Native extensions are written in C++, so you could search github for some Write-to-PDF extension and try to use it in such native extension for Defold (used e.g. in place of written function, but with changed arguments and output).

1 Like

A couple solutions come to mind if some assumptions are made. But I feel the use case in the context of Defold still isn’t clear enough to offer any solutions confidently. So more questions!

Are you hoping to use a Defold game build as a way to distribute the document generation to your intended players, or is Defold being used to act as a middleman for rendering the generation algorithm’s output (so more as a pipeline tool)?

Is the example you provided a close representation of what a final render of your document should look like? Are you planning to integrate more visual assets, etc?

1 Like

I want to use Defold to generate the PDF document, the idea is that we can generate different dungeons using the game created in Defold. Maybe Defold is not the right tool for he job, this can be done using some web app generator, but most of these tools are paid and with all of them, I have to work with HTML and CSS, I have some knowledge about, but thing is, I don’t want to work with HTML and CSS, or Java or any other tool, I just want to generate a web app/game to allow the user to configure the parameters for the generator and obtain a different PDF map each time. Some symbols or tiles will be added to the map.

This is more or less what I want to create, a full A4 PDF page, with a dungeon, more complex than what we see in the image, and maybe (still to be decided), some tables for rolling the dice.


The only other tool that sometimes I think I could use, is Lazarus IDE, it uses Object Pascal, allows me to place some graphics and shapes in the windows, and export to PDF, it allows to create native apps but I does not compile to Web, at least It is not as easy as using Defold.

I hope this can help you help me :slight_smile:

Thanks

I never created any extension or contributed to any open source project.

Maybe I can try to create the extension, but my original idea was not to spend time creating the PDF extension, just using something existing, because my free time is not much at this moment.

Anyways, thanks for the sugestion, I will think about it, or in the last case, just export to PNG.

1 Like

Understandable :wink:

There is also:

I found on github - it might be easier (it’s a Lua module, so you could use it directly in Defold, write some text and export PDF) - it has a lot of demos and examples, even ones with some graphical elements.

What if you just created the ‘pdf generator/server’ which would only be responsible for generating the pdf (from parameters supplied via HTTP(S) POST) and initiating the download/delivery of the pdf—and wouldn’t require a GUI. Everything else could be handled via your Defold app/game.

Thanks, this might be easier to implement.

I will do some test with this tool.

1 Like

This is also a good option.
I need to check what is needed, because this requires a nodejs server, I believe.

But it is a good option too.

Thanks

A custom webapp was my first thought, but it is very understandable not wanting to get into the whole mess of some parts of webdev just to build something that essentially just combines assets into a page layout.

For generating the map itself, Defold is certainly a fine choice for generation using tilemaps - although there is probably an even better solution where you could even have tilebased image construction run from a CLI rather than having to rely on Defold runtime. Perhaps someone else knows, would probably be a bit more technical too - and would bring you back to probably requiring a custom webapp to provide a GUI for users anyway.

I would split the problem into these parts:

  • generate the maze and export it to an image asset
  • generate the tables in a format that can be ingested into whatever you want to use to generate the page layout
  • create the document with whatever toolchain you have set up to use the resources as an input
  • deliver the document

How much of any part needs to involve Defold can vary depending on the exact solution.
As a possible part of the solution, have a look at this:

If you can get your rendered asset bundle into an XML, you will be able to setup your page layout for print.

So to get the tool usable to your users, as @bryanrieger suggested you could have Defold communicate with a server that you run using something like this to generate pages then have Defold download that file and write it to your user’s filesystem.

As an aside for the Defold veterans,
Would this be possible to implement as an extension?
Would something based in lua be more reasonable?

Also, something mentioned in the docs to be aware if you are thinking of having the Defold runtime in HTML at the end using this kind of solution:

For security reasons browsers (and by extension any JavaScript running in a browser) is prevented from accessing system files. File operations in HTML5 builds in Defold still work, but only on a “virtual file system” using the IndexedDB API in the browser. What this means is that there is no way to access system files in HTML5 builds.

I’m sure there’s a way to work around this limitation in the client-server method described above, but I personally wouldn’t know. Anyways, it’s only a problem if you’re serving the game build through HTML if I’m understanding correctly.

If you want to deal mostly with Defold, the suggestion from @Pawel seems most promising, as it puts the PDF generation straight into your build. The difference with the webserver method is that your users won’t have to update their client to receive updates to your map generator (if the Defold assets are unchanged), since you can just make those changes on the server. But you can also mimic this UX choice using Defold’s Live Update feature to push the content without requiring a true update to the game build.

1 Like

I believe the easiest way forward for you is not to use a PDF extension at all, but instead target a HTML5 build instead. A html5 page can easily be printed, and you probably want the page accessible online too.

Then you can display images using the engine, and sending text to the html document.
(I think text should be as a text so it can easily be changed by the user: e.g size of map, etc)

Other than that, I would personally go for scripting this in (custom) offline tools using python or something.

3 Likes

Oh whoa that’s super cool, I wasn’t aware this was possible (flashbacks to people trying to print out Youtube videos in 2007). Printing through the browser will grab what’s currently being rendered in the build in this case? Or am I misunderstanding?

I believe this can work too, just make the display the size of the map, and then the user just prints the page. Looks like the simplest solution.

Thanks for the sugestion.

1 Like

I like the idea, but can take sometime to develop.

Maybe I the solutions of @Pawel or @Mathias_Westerdahl are the most easiests, I have to test and see which is better/easier.

Thanks

1 Like

I did a little test in a web game from itch.io, it seems to work, it will print what is rendered on the screen, so if I make the map big enough, it will be easy to fit in a page.

4 Likes