ingmontoyav/camelot-php

该软件包最新版本(dev-master)没有可用的许可证信息。

dev-master 2023-09-04 17:29 UTC

This package is not auto-updated.

Last update: 2024-10-01 02:48:03 UTC


README

randomstate/camelot-php的分支,但已将symfony/process升级到最新版本

安装

composer require ingmontoyav/camelot-php

用法

该软件包与camelot CLI API用法紧密一致。默认输出为CSV格式的简单字符串。如果您需要解析CSV字符串,我们建议使用league/csv软件包(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();

高级处理

保存/提取

注意:在运行以下方法之一之前,不会执行任何Camelot操作

$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)   
设置格式
$camelot->json();
$camelot->csv();
$camelot->html();
$camelot->excel();
$camelot->sqlite();
指定页码

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

读取加密的PDF文件

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

处理背景行

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

可视化调试

$camelot->plot()

指定表格区域
<?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)
    );
指定表格区域
<?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)
    );
指定列分隔符

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

沿分隔符拆分文本

$camelot->split()

标记上标和下标

$camelot->flagSize()

从文本中删除字符

$camelot->strip("\n")

改进猜测的表格区域

$camelot->setEdgeTolerance(500)

改进猜测的表格行

$camelot->setRowTolerance(15)

检测短行

$camelot->lineScale(20)

调整跨单元格中的文本

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

复制跨单元格中的文本

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

许可证

MIT. 自行承担风险,我们不承担此代码使用的任何责任。