跳轉到

商業信函範例

需求套件nextpdf/core 難度:入門

完整程式碼

<?php

declare(strict_types=1);

use NextPDF\Core\Document;
use NextPDF\Core\ValueObjects\PageSize;
use NextPDF\Core\ValueObjects\Margin;
use NextPDF\Core\ValueObjects\Position;
use NextPDF\Core\ValueObjects\Color;

$document = Document::createStandalone(
    pageSize: PageSize::A4,
    margin:   Margin::symmetric(vertical: 20.0, horizontal: 25.0),
);

$page    = $document->pages()->add();
$text    = $document->text();
$drawing = $document->drawing();

// ─── 信頭 ─────────────────────────────────────────────────────
$logo = $document->images()->embed('/assets/company-logo.png');
$drawing->image(image: $logo, x: 25.0, y: 15.0, width: 45.0);

$text->write(
    text:     'NextPDF 科技有限公司',
    position: Position::at(x: 185.0, y: 18.0),
    fontSize: 10.0,
    fontName: 'NotoSansCJKtc-Bold',
    color:    Color::fromHex('#1E3A8A'),
    alignment: 'right',
    maxWidth:  90.0,
);
$text->write(
    text:     "台北市信義區信義路五段 7 號 10 樓\n(02) 1234-5678  |  [email protected]\nhttps://nextpdf.dev",
    position: Position::at(x: 185.0, y: 26.0),
    fontSize: 8.0,
    fontName: 'NotoSansCJKtc',
    color:    Color::fromHex('#6B7280'),
    alignment: 'right',
    maxWidth:  90.0,
    lineHeight: 1.6,
);

$drawing->line(
    x1: 25.0, y1: 50.0, x2: 185.0, y2: 50.0,
    color: Color::fromHex('#1E3A8A'), width: 1.0,
);

// ─── 日期與收件人 ─────────────────────────────────────────────
$text->write(
    text:     '2024 年 3 月 15 日',
    position: Position::at(x: 25.0, y: 60.0),
    fontSize: 10.0,
    fontName: 'NotoSansCJKtc',
    color:    Color::fromHex('#374151'),
);

$text->write(
    text:     "李大明 先生  敬啟\n台北科技股份有限公司\n研發部",
    position: Position::at(x: 25.0, y: 75.0),
    fontSize: 11.0,
    fontName: 'NotoSansCJKtc',
    color:    Color::fromHex('#111827'),
    lineHeight: 1.8,
);

// ─── 主旨 ─────────────────────────────────────────────────────
$text->write(
    text:     '主旨:NextPDF 企業授權合作提案',
    position: Position::at(x: 25.0, y: 105.0),
    fontSize: 11.0,
    fontName: 'NotoSansCJKtc-Bold',
    color:    Color::fromHex('#111827'),
);

$drawing->line(
    x1: 25.0, y1: 113.0, x2: 185.0, y2: 113.0,
    color: Color::fromHex('#E5E7EB'), width: 0.5,
);

// ─── 正文 ─────────────────────────────────────────────────────
$bodyText = <<<EOT
敬啟者:

    感謝  貴公司對 NextPDF 企業版的持續支持與信任。依據日前洽談內容,本公司特此提出正式合作提案,敬請  惠予審閱。

    NextPDF Enterprise 版本提供完整的 PDF 2.0 生成能力,包含 PAdES B-LTA 數位簽章、ZUGFeRD 電子發票、PDF/A-4 長期保存格式,以及 HSM 硬體安全模組整合,全面符合  貴公司在文件合規與安全性方面的需求。

    此次提案內容詳見隨附報價單(附件一),如有任何疑問,歡迎隨時與本公司業務團隊聯繫。

    期待與  貴公司建立長期合作關係,謹此。
EOT;

$text->write(
    text:      $bodyText,
    position:  Position::at(x: 25.0, y: 120.0),
    fontSize:  10.5,
    fontName:  'NotoSansCJKtc',
    color:     Color::fromHex('#374151'),
    lineHeight: 2.0,
    maxWidth:   160.0,
    indent:     0.0,
);

// ─── 結尾敬語與署名 ───────────────────────────────────────────
$text->write(
    text:     "此致\n\n敬上",
    position: Position::at(x: 25.0, y: 220.0),
    fontSize: 11.0,
    fontName: 'NotoSansCJKtc',
    color:    Color::fromHex('#374151'),
    lineHeight: 2.5,
);

$text->write(
    text:     'NextPDF 科技有限公司',
    position: Position::at(x: 25.0, y: 248.0),
    fontSize: 11.0,
    fontName: 'NotoSansCJKtc-Bold',
    color:    Color::fromHex('#111827'),
);
$text->write(
    text:     '執行長  陳小華  敬上',
    position: Position::at(x: 25.0, y: 258.0),
    fontSize: 10.5,
    fontName: 'NotoSansCJKtc',
    color:    Color::fromHex('#374151'),
);

// 簽名圖片(可選)
$signature = $document->images()->embed('/assets/signature.png');
$drawing->image(image: $signature, x: 25.0, y: 263.0, width: 40.0);

// ─── 輸出 ────────────────────────────────────────────────────
$document->save('/output/business-letter.pdf');

程式碼說明

延伸閱讀