定制 phppdf/markdown-converter 二次开发

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

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

phppdf/markdown-converter

Composer 安装命令:

composer require phppdf/markdown-converter

包简介

Convert Markdown into PDF documents on top of phppdf/phppdf

README 文档

README

CI

Convert Markdown into PDF documents on top of phppdf/phppdf.

Markdown is parsed directly into layout primitives (text, lists, tables) — there is no intermediate HTML step.

Installation

composer require phppdf/markdown-converter

Requires PHP 8.4+.

Usage

MarkdownConverter::fromMarkdown() never registers fonts for you — you must register a font under each resource name MarkdownConverterConfig expects (F1F5 by default) before calling $builder->build().

use PhpPdf\Builder\PdfDocumentBuilder;
use PhpPdf\Markdown\MarkdownConverter;
use PhpPdf\Markdown\MarkdownConverterConfig;
use PhpPdf\Output\PdfMemoryOutput;
use PhpPdf\Serialization\PdfDocumentSerializer;

$markdown = "# Hello World\n\nWelcome to the PDF.";

$config = new MarkdownConverterConfig();

$builder = new PdfDocumentBuilder();
$builder->globalFont($config->getRegularFontName(), 'Helvetica')
    ->globalFont($config->getBoldFontName(), 'Helvetica-Bold')
    ->globalFont($config->getItalicFontName(), 'Helvetica-Oblique')
    ->globalFont($config->getBoldItalicFontName(), 'Helvetica-BoldOblique')
    ->globalFont($config->getCodeFontName(), 'Courier');

MarkdownConverter::fromMarkdown($markdown, $config, $builder);

$output = new PdfMemoryOutput();
(new PdfDocumentSerializer($output))->writeDocument($builder->build());

header('Content-Type: application/pdf');
echo $output->getContent();

Supported Markdown

ATX and Setext headings, paragraphs, bold, italic, bold italic, inline code, fenced code blocks, ordered/unordered lists (with nesting and GFM task-list checkboxes), blockquotes, thematic breaks, GFM pipe tables (with column alignment), hyperlinks, standalone images, and footnotes.

See the full syntax reference and known limitations.

Documentation

Full documentation, including custom layout and custom fonts, is available at phppdf.github.io/markdown-converter.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固