Free PHP Library for Converting Microsoft® Word Processing Files
Open & Convert Microsoft Word Processing (DOCX & DOC) Documents to PDF Files using Open Source Free PHP Library
What is Gotenberg PHP client?
Gotenberg PHP client is an open-source PHP library that gives software developers the capability to convert Microsoft Word Processing documents to PDF inside their own applications. Gotenberg is a Docker-powered stateless API for converting Office documents to PDF. Using the API, you can easily convert DOCX, DOC, RTF, and TXT file format to PDF.
By using the API, you can convert one or more word processing documents at the same time and save the resultant document in PDF format. The API provides structured logging allowing you to have relevant information about what’s going on.
Getting Started with Gotenberg PHP client
The recommended way to install the Gotenberg PHP client into your project is by using GitHub. Please use the following command for a smooth installation.
Install Gotenberg PHP client via GitHub
$ PHP get -u github.com/thecodingmachine/gotenberg-php-client/v7
Convert DOCX to PDF via Free PHP API
The Open source library Gotenberg PHP client allows computer programmers to convert DOCX to PDF inside their own PHP applications. In order to convert your DOCX to PDF, you just need to load your document and convert it using gotenberg.NewOfficeRequest() method. By using the following lines of code, you can easily convert DOCX to PDF. Software developers can also convert other MS Office documents to PDF file format and merge them with just a couple of lines of PHP code. The following example shows how PHP developers can load and Convert DOCX to PDF document inside PHP applications.
Convert Word Processing to PDF in PHP
- Load two DOCX files using NewDocumentFromPath() method and pass filename and file path as parameters
- Convert both files to PDF using gotenberg.NewOfficeRequest() method and pass doc objects
- Save PDF document
Convert DOCX to PDF via Free PHP API
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
doc, _ := gotenberg.NewDocumentFromPath("document.docx", "/path/to/file")
doc2, _ := gotenberg.NewDocumentFromPath("document2.docx", "/path/to/file")
req := gotenberg.NewOfficeRequest(doc, doc2)
dest := "result.pdf"
c.Store(req, dest)
Convert Office Documents and Merge Them via Free PHP API
use Gotenberg\Gotenberg;
use Gotenberg\Stream;
// Converts Office documents to PDF and merges them.
$response = Gotenberg::send(
Gotenberg::libreOffice($apiUrl)
->merge()
->convert(
Stream::path($pathToDocx),
Stream::path($pathToXlsx)
)
);