承接 machinateur/php-qpdf-ffi 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

machinateur/php-qpdf-ffi

最新稳定版本:1.1.0

Composer 安装命令:

composer require machinateur/php-qpdf-ffi

包简介

A really simple PHP integration for qpdf leveraging its JSON job file functionality with PHP-FFI to C.

README 文档

README

A really simple PHP integration for qpdf leveraging its JSON job file functionality with PHP-FFI to C.

The name really says it all.

Requirements

  • At least PHP >=7.4 is required
    • Extensions ext-json and ext-ffi are required
  • A compatible qpdf binary, version 11.9
    • Some earlier versions might also work, as long as the C API is untouched

The PHP-FFI extension is supported since PHP version 7.4, so that's why it is the minimum PHP version this library supports and will support indefinitely.

Installation

composer require machinateur/php-qpdf-ffi

The path to the C library should be specified by means of the LIB_QPDF_PATH constant. If not defined, a \CompileError will be thrown upon calling a function.

Where to get the qpdf binaries

Since qpdf is a separate C library, the binaries are not included here (yet). The Apache 2 license allows redistribution.

https://github.com/qpdf/qpdf/blob/11.9/README-what-to-download.md

Advantages

Use the full set of features provided by qpdf JSON job files directly from within PHP, without the need to write any C glue code for a custom PHP extension.

No need for \exec() shenanigans. The PHP-FFI layer handles the direct interaction. This library only integrates one single function, therefor very little can break.

The JSON format can be dynamically generated based on the requirements of your application. As JSON is supported in a wide range of programming languages, the input does not necessarily have to come from PHP.

https://qpdf.readthedocs.io/en/latest/qpdf-job.html#qpdf-job

Usage

<?php

// Define the required constant value, the path to the qpdf binary
\define('LIB_QPDF_PATH', '/path/to/your/qpdf');

require_once __DIR__ . '/vendor/autoload.php';

$result = \qpdfjob_run_from_json(
    \file_get_contents(__DIR__ . '/example.json')
);

switch ($result)
{
    case \qpdf_exit_code_e::QPDF_EXIT_SUCCESS:
        echo 'Success';
        return;
    case \qpdf_exit_code_e::QPDF_EXIT_WARNING:
    case \qpdf_exit_code_e::QPDF_EXIT_IS_NOT_ENCRYPTED:
        echo 'Warning / IS_NOT_ENCRYPTED';
        return;
    case \qpdf_exit_code_e::QPDF_EXIT_ERROR:
    case \qpdf_exit_code_e::QPDF_EXIT_CORRECT_PASSWORD:
        echo 'Error   / CORRECT_PASSWORD';
        return;
}

Job file format

The format is documented extensively on qpdf's docs:

https://qpdf.readthedocs.io/en/latest/cli.html

Tests

The test-suite is built based on resources from py-pdf/sample-files. The QpdfJobTest.php is implemented in a way that makes adding addition qpdf JSON job files very ease. As of now, there is only one example.json file, taken from the qpdf docs.

All example jobs should use the same output file, that way the cleanup before each test stays simple (unlink()).

License

It's MIT.

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固