PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
转换前完成文档加载,准备与源文件不同、父目录已存在且可写的输出路径。
import { CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';
async function convertStandard(reader: CPDFReaderView, outputPath: string) {
const document = reader._pdfDocument;
const currentType = await document.getPdfStandardType();
if (!await reader.save()) throw new Error('保存文档失败');
const success = await document.convertToPdfStandard(
outputPath, 'pdf_a_2b', true,
);
if (!success) throw new Error('PDF 标准转换失败');
return { currentType, outputPath };
}getPdfStandardType() 读取文档声明的标准,不是完整的合规校验。convertToPdfStandard(outputPath, type, fontSubset) 返回 boolean;fontSubset 默认为 true,用于保存时的字体子集处理。
| 标准 | type |
|---|---|
| PDF/A-1 | pdf_a_1a、pdf_a_1b |
| PDF/A-2 | pdf_a_2a、pdf_a_2u、pdf_a_2b |
| PDF/A-3 | pdf_a_3a、pdf_a_3u、pdf_a_3b |
| PDF/X | pdf_x_1a、pdf_x_3、pdf_x_4 |
| PDF/E | pdf_e_1 |
| PDF/UA | pdf_ua_1 |
| PDF/VT | pdf_vt_1、pdf_vt_2 |
saveAs(path, true, true) 输出无密码副本,并打开该副本后转换。应先具备相应文档权限。content:// URI。document.open(outputPath),再读取类型或检查输出。false 或 Promise 拒绝。只有确认成功后,才继续使用输出文件。