定制 kayukoff/camelot-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kayukoff/camelot-php

最新稳定版本:v1.1.0

Composer 安装命令:

composer require kayukoff/camelot-php

包简介

PHP Wrapper library for interfacing with the Camelot PDF table extraction library built in Python

README 文档

README

A PHP wrapper for Camelot, the python PDF table extraction library.

A fork from randomstate/camelot-php updated for user with Symfony 6 and PHP 8.

Installation

composer require kayukoff/camelot-php

Usage

The package adheres closely with the camelot CLI API Usage. Default output is in CSV format as a simple string. If you need to parse CSV strings we recommend the league/csv package (https://csv.thephpleague.com/)

<?php

use RandomState\Camelot\Camelot;
use League\Csv\Reader;

$tables = Camelot::lattice('/path/to/my/file.pdf')
       ->extract();

$csv = Reader::createFromString($tables[0]);
$allRecords = $csv->getRecords();

Advanced Processing

Saving / Extracting

Note: No Camelot operations are run until one of these methods is run

$camelot->extract(); // uses temporary files and automatically grabs the table contents for you from each
$camelot->save('/path/to/my-file.csv'); // mirrors the behaviour of Camelot and saves files in the format /path/to/my-file-page-*-table-*.csv
$camelot->plot(); // useful for debugging, it will plot it in a separate window (see Visual Debugging below)   
Set Format
$camelot->json();
$camelot->csv();
$camelot->html();
$camelot->excel();
$camelot->sqlite();
Specify Page Numbers

$camelot->pages('1,2,3-4,8-end')

Reading encrypted PDFs

$camelot->password('my-pass')

Processing background lines

$camelot->stream()->processBackgroundLines()

Visual debugging

$camelot->plot()

Specify table areas
<?php

use RandomState\Camelot\Camelot;
use RandomState\Camelot\Areas;

Camelot::stream('my-file.pdf')
    ->inAreas(
        Areas::from($xTopLeft, $yTopLeft, $xBottomRight, $yBottomRight)
            // ->add($xTopLeft2, $yTopLeft2, $xBottomRight2, $yBottomRight2)
            // ->add($xTopLeft3, $yTopLeft3, $xBottomRight3, $yBottomRight3)
    );
Specify table regions
<?php

use RandomState\Camelot\Camelot;
use RandomState\Camelot\Areas;

Camelot::stream('my-file.pdf')
    ->inRegions(
        Areas::from($xTopLeft, $yTopLeft, $xBottomRight, $yBottomRight)
            // ->add($xTopLeft2, $yTopLeft2, $xBottomRight2, $yBottomRight2)
            // ->add($xTopLeft3, $yTopLeft3, $xBottomRight3, $yBottomRight3)
    );
Specify column separators

$camelot->stream()->setColumnSeparators($x1,$x2...)

Split text along separators

$camelot->split()

Flag superscripts and subscripts

$camelot->flagSize()

Strip characters from text

$camelot->strip("\n")

Improve guessed table areas

$camelot->setEdgeTolerance(500)

Improve guessed table rows

$camelot->setRowTolerance(15)

Detect short lines

$camelot->lineScale(20)

Shift text in spanning cells

$camelot->shiftText('r', 'b')

Copy text in spanning cells

$camelot->copyTextSpanningCells('r', 'b')

License

MIT. Use at your own risk, we accept no liability for how this code is used.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固