Create a PDF file from a Vapor 4 API

Hello everyone,

I'm looking for how to create a PDF file from a Vapor 4 API and save it to a database.

Thank you for your help,
Good day,
Eric

First off, what do you mean by "creating" a PDF file? And then, databases are not really suited to store files, ideally you'd be looking at something like S3, is there a specific reason you want to be using a DB? You can probably achieve it using a BLOB or BYTEA column and mapping it do a Data field in Fluent's Model but I'd honestly just store a reference to it in the db and store the file itself on S3 or whatever you prefer

I might think about it later but for now, I'm working with an existing MySQL database with Laravel. I'm already using a BLOB column. I will convert to Swift Vapor to separate the backend from the frontend. The frontend will only display by datatable.

@EricSt You'll probably need a library to convert whatever you have (markdown/HTML?) into PDF - there are a couple out there. wkhtmltopdf – Swift Package Index is a common one. Then write the data to the DB if that's where you're storing them

Hello Tim, I followed the installation of wkhtmltopdf but when I write import wkhtmltopdf, I get the error: No such module 'wkhtmltopdf'. I think I didn't understand in the installation: Specify the location of wkhtmltopdf in the Document initialize. The default is /usr/local/bin/wkhtmltopdf.

Where should I put this information: /usr/local/bin/wkhtmltopd

Thank you for your help,
Eric

Is that an error from building the project or just it indexing the error?

What does your Package.swift look like?