PNG JPG BMP TIFF PDF
Aspose.PDF  for PHP

PHP SDK で PDF のテーブルを置換

クラウド PHP SDK を使用して PDF ドキュメントのテーブルを置換

Get Started

クラウド PHP SDK を使用して PDF のテーブルを置換する方法

PDF のテーブルを置換するには、次を使用します。 Aspose.PDF Cloud PHP SDK このクラウド SDK は、PHP プログラマーが PHP プログラミング言語を使用して Aspose.PDF REST API 経由でクラウドベースの PDF クリエータ、アノテータ、エディタ、コンバータアプリを開発するのを支援します。Aspose for Cloud にアカウントを作成して、アプリケーション情報を取得してください。App SID & キーを取得したら、Aspose.PDF Cloud PHP SDK を使用する準備が整います。

パッケージ マネージャー コンソール コマンド

     
    composer install

クラウド PHP 経由で PDF のテーブルを置換する手順

Aspose.PDF Cloud 開発者は、わずか数行のコードで PDF のテーブルを簡単に読み込んで置換できます。

  1. PDF ドキュメントをアップロード
  2. 修正された PDF ドキュメントをダウンロード
  3. テーブルを初期化
  4. PDF 内の既存のテーブルを置換
 

PHP を使用して PDF のテーブルを置換


    private function _create_rest_api() {
        $credentials = json_decode(file_get_contents("../../../../Credentials/credentials.json"), true);

        $configAuth = new Configuration();
        $configAuth->setAppKey($credentials['key']);
        $configAuth->setAppSid($credentials['id']);

        $this->pdfApi = new PdfApi(null, $configAuth);
    }

    public function __construct($config) {
        $this->configParams = $config;
        $this->_create_rest_api();
    }

    public function uploadDocument() {
        $fileNamePath = $this->configParams['LOCAL_FOLDER'] . $this->configParams['PDF_DOCUMENT_NAME'];
        $pdfFileData = file_get_contents($fileNamePath);
        $this->pdfApi->uploadFile($this->configParams['PDF_DOCUMENT_NAME'], $pdfFileData);
    }

    public function downloadResult() {
        $changedPdfData = $this->pdfApi->downloadFile($this->configParams['PDF_DOCUMENT_NAME']);
        $filePath = $this->configParams['LOCAL_FOLDER'] . $this->configParams['LOCAL_RESULT_DOCUMENT_NAME'];
        file_put_contents($filePath, $changedPdfData);
        echo "Downloaded: " . $filePath . "\n";
    }

    private function _init_table() {
        $numOfCols = 5;
        $numOfRows = 5;
    
        $headerTextState = [
            "font" => "Arial Bold",
            "fontSize" => 11,
            "foregroundColor" => ["a" => 0xFF, "r" => 0xFF, "g" => 0xFF, "b" => 0xFF],
            "fontStyle" => "Bold"
        ];
    
        $commonTextState = [
            "font" => "Arial Bold",
            "fontSize" => 11,
            "foregroundColor" => ["a" => 0xFF, "r" => 0x70, "g" => 0x70, "b" => 0x70]
        ];
    
        $table = new \Aspose\PDF\Model\Table();
        $table->setRows([]);
        $table->setColumnWidths(str_repeat(" 70", $numOfCols));
    
        $borderTableBorder = new \Aspose\PDF\Model\GraphInfo();
        $borderTableBorder->setColor(["a" => 0xFF, "r" => 0x00, "g" => 0xFF, "b" => 0x00]);
        $borderTableBorder->setLineWidth(0.5);
    
        $table->setDefaultCellBorder([
            "top" => $borderTableBorder,
            "right" => $borderTableBorder,
            "bottom" => $borderTableBorder,
            "left" => $borderTableBorder,
            "roundedBorderRadius" => 0
        ]);
        $table->setLeft(150);
        $table->setTop(250);
    
        for ($rowIndex = 0; $rowIndex < $numOfRows; $rowIndex++) {
            $row = new \Aspose\PDF\Model\Row();
            $row->setCells([]);
    
            for ($colIndex = 0; $colIndex < $numOfCols; $colIndex++) {
                $cell = new \Aspose\PDF\Model\Cell();
                $cell->setDefaultCellTextState($commonTextState);
    
                if ($rowIndex == 0) {
                    $cell->setBackgroundColor(["a" => 0xFF, "r" => 0x80, "g" => 0x80, "b" => 0x80]);
                    $cell->setDefaultCellTextState($headerTextState);
                } else {
                    $cell->setBackgroundColor(["a" => 0xFF, "r" => 0xFF, "g" => 0xFF, "b" => 0xFF]);
                }
    
                $textRect = new \Aspose\PDF\Model\TextRect();
                $textRect->setText($rowIndex == 0 ? "header #" . $colIndex : "value #(" . $rowIndex . "," . $colIndex . ")");
                $cell->setParagraphs([$textRect]);
    
                $row->getCells()[] = $cell;
            }
            $table->getRows()[] = $row;
        }
        return $table;
    }

    public function replaceTable() {
        $newTable = $this->_init_table();

        $resultTabs = $this->pdfApi->putTable($this->configParams['PDF_DOCUMENT_NAME'], $this->configParams['TABLE_ID'], [$newTable]);
    
        if ($resultTabs->getCode() == 200) {
            echo "New table successfully replaced.\n";
            var_dump($newTable);
        } else {
            echo "Unexpected error: can't replace table !!!\n";
        }
    }

    function main() {
        global $configParams;
        $pdfTables = new PdfTables($configParams);
        try {
            $pdfTables->uploadDocument();
            $pdfTables->replaceTable();
            $pdfTables->downloadResult();
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage() . "\n";
        }
    }
 

PDF のテーブルを操作

テーブルはデータを体系的に提示するための構造化された形式を提供し、読者が情報を理解し分析しやすくします。また、ドキュメントにプロフェッショナルで組織的な外観を与え、視覚的な魅力を高めます。数値データや比較データを扱う場合、関連情報を読みやすい形式でグループ化することで、テーブルは明確さを向上させます。さらに、テーブルはデータベースや分析ダッシュボードからのデータなど、リアルタイムまたは動的に生成されたコンテンツを組み込むことができます。 Aspose.PDF Cloud PHP SDK を使用して PDF ドキュメント内のテーブルを置換します。

私たちの PHP ライブラリを使用すると、次のことができます:

  • PDF ドキュメントにテキストまたは画像形式のヘッダーとフッターを追加します。
  • PDF ドキュメントにテーブルとスタンプ(テキストまたは画像)を追加します。
  • 複数の PDF ドキュメントを既存のファイルに追加します。
  • PDF の添付ファイル、注釈、フォームフィールドを操作します。
  • PDF ドキュメントに暗号化または復号化を適用し、パスワードを設定します。
  • ページまたは PDF ドキュメント全体からすべてのスタンプとテーブルを削除します。
  • PDF ドキュメントから ID によって特定のスタンプまたはテーブルを削除します。
  • PDF ページまたはドキュメント全体からテキストの単一または複数のインスタンスを置換します。
  • PDF ドキュメントをさまざまな他のファイル形式に変換するための広範なサポート。
  • PDF ファイルのさまざまな要素を抽出し、PDF ドキュメントを最適化します。
  • 機能をオンラインでテストするために 無料アプリ を試すことができます。