randomstate/camelot-php
Composer 安装命令:
composer require randomstate/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
Installation
composer require randomstate/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.
randomstate/camelot-php 适用场景与选型建议
randomstate/camelot-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.59k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2019 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 randomstate/camelot-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 randomstate/camelot-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-12