PHP Classes

Bitrix24 PHP LibreOffice Convert DOCX to PDF and JPEG: Convert Microsoft Word DOCX documents to PDF

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 98 All time: 9,830 This week: 40Up
Version License PHP version Categories
bitrix24docxtopdf 1.0.0The PHP License5PHP 5, Files and Folders, Content man..., W..., A...
Description 

Author

This package can convert Microsoft Word DOCX documents to PDF.

It provides an application that can be deployed with a Docker container and can use RabbitMQ queue Microsoft Word documents to be converted.

The application can pull document files and uses the LibreOffice program to convert the documents to PDF or JPEG files.

The converted files are uploaded to the Bitrix24 service using its API.

Innovation Award
PHP Programming Innovation award nominee
May 2023
Number 6
PDF is a popular format used to store files of documents that are meant for printing.

DOCX is a popular format used by Microsoft Word application to store documents created by people that use that application to create and share documents.

The DOCX format may also store document files generated by other software tools. Some of those tools can be written in PHP.

PHP document generation tools may also process template documents stored in DOCX format files.

When document files in DOCX formats need to be printed, converting those files to PDF could be a good solution because the PDF format considers the physical dimensions of the published document.

This package provides a solution to convert one or more DOCX documents to PDF or JPEG using the LibreOffice application. This way, you can implement a conversion system based on free software.

Manuel Lemos
Picture of Alexey Starikov
  Performance   Level  
Name: Alexey Starikov <contact>
Classes: 3 packages by
Country: Russian Federation Russian Federation
Age: 47
All time rank: 300983 in Russian Federation Russian Federation
Week rank: 170 Up9 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 4x

Example

<?php
include __DIR__ . '/vendor/autoload.php';
use
PhpAmqpLib\Connection\AMQPStreamConnection;
use
PhpAmqpLib\Exchange\AMQPExchangeType;
use
PhpAmqpLib\Message\AMQPMessage;

/*
 * ????????? ??????? https://transformer-de.bitrix.info/json/add_queue.php
 * ???? http://bitrix24.host.ru/secret_url/add_queue.php
 * */

define('HOST', getenv('RABBITMQ_HOST') ? getenv('RABBITMQ_HOST') : '127.0.0.1');
define('PORT', getenv('RABBITMQ_PORT') ? getenv('RABBITMQ_PORT') : 5672);
define('USER', getenv('RABBITMQ_USER') ? getenv('RABBITMQ_USER') : 'guest');
define('PASS', getenv('RABBITMQ_PASS') ? getenv('RABBITMQ_PASS') : 'guest');
define('VHOST', '/');
define('AMQP_DEBUG', getenv('AMQP_DEBUG') !== false ? (bool)getenv('AMQP_DEBUG') : false);
define('DEBUG', getenv('DEBUG') !== false ? (bool)getenv('DEBUG') : false);

try {
   
$exchange = 'bitrix';
   
$queue = '';

   
file_put_contents('/tmp/abb_traqnsform.log', date('d.m.y H:i:s') . PHP_EOL, FILE_APPEND);
   
file_put_contents('/tmp/abb_traqnsform.log', json_encode($_POST) . PHP_EOL, FILE_APPEND);
   
file_put_contents('/tmp/abb_traqnsform.log', json_encode($_SERVER) . PHP_EOL, FILE_APPEND);
   
# ???????? ???????
    // {"command":"Bitrix\\TransformerController\\Document","params":{"documentId":"9","queue":"documentgenerator_create","file":"https:\/\/bitrix24.ru\/upload\/documentgenerator\/920\/5ln4gt0wbnzh8h8035gkpk0wobvo2s2s\/Schet_faktura_Rossiya_1.docx","fileSize":"29232","formats":{"jpg":"jpg","pdf":"pdf"},"back_url":"https:\/\/bitrix24.ru\/bitrix\/tools\/transformer_result.php?id=XWeti6XidT625428cb0978c"},"QUEUE":"documentgenerator_create","BX_LICENCE":"6b78d816e3","BX_DOMAIN":"https:\/\/bitrix24.ru","BX_TYPE":"BOX","BX_VERSION":"1","BX_HASH":"a31ff1c2c72f10b20d9bf814d0b7"}
   
$in = &$_POST;
   
$ret = [
       
'success' => true,
       
'result' => [
           
'code' => 400,
        ]
    ];

    if (
$in['command'] == 'Bitrix\\TransformerController\\Document') {
       
$queue=$in['QUEUE'];
       
$connection = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);
       
$channel = $connection->channel();
       
$channel->queue_declare($queue, false, true, false, false, false, ['x-message-ttl' => ['I', 86400000]]);
       
$channel->exchange_declare($exchange, AMQPExchangeType::DIRECT, false, true, false);
       
$channel->queue_bind($queue, $exchange);
       
$messageBody = json_encode($in['params'], 256);
       
$message = new AMQPMessage($messageBody, array('content_type' => 'text/plain', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT));
       
$channel->basic_publish($message, $exchange);
       
$channel->close();
       
$connection->close();
       
# ????????? ? ??????????? ???????? ???? url ? $in['params']
        # ???????????? ? ??????????? ???????
        # echo exec('docker run --rm -it -v '.__DIR__.':/tmp --name libreoffice-headless ipunktbs/docker-libreoffice-headless:latest --convert-to jpg "???????????? (??????) 1.docx"');
        # ??????????? ????????? ????? ??? ???????? ??????? ?? ???? ? ?????????? ????????????????? ????? ?? 1 ??, ??????? ??? ??????? ????????
        # ?????????? ????????????? ?????????? ??????
   
} else {
        throw new
Exception('??????? ?? ??????????????');
    }
} catch (
Exception $e) {
   
$ret['success'] = false;
   
$ret['result']['code'] = 1000;
   
$ret['result']['msg'] = $e->getMessage();
}
echo
json_encode($ret);


  Files folder image Files (7)  
File Role Description
Files folder imageadd_queue (2 files)
Files folder imageconverter (2 files, 1 directory)
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (7)  /  add_queue  
File Role Description
  Accessible without login Plain text file add_queue.php Example Example script
  Accessible without login Plain text file composer.json Data Auxiliary data

  Files folder image Files (7)  /  converter  
File Role Description
Files folder imageapp (2 files)
  Accessible without login Plain text file docker-compose.yml Data Auxiliary data
  Accessible without login Plain text file Dockerfile Data Auxiliary data

  Files folder image Files (7)  /  converter  /  app  
File Role Description
  Plain text file app.php Class Class source
  Accessible without login Plain text file composer.json Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:98
This week:0
All time:9,830
This week:40Up