2个版本
0.1.1 | 2020年11月23日 |
---|---|
0.1.0 | 2020年11月23日 |
#1491 在 文本处理
65KB
1.5K SLoC
pdf-create
这是另一个PDF创建库,作为Signum!-Document-Toolbox的一部分开发。在某种程度上,它是pdf
crate缺失部分的原型。
理由
此crate的主要目标是能够使用自定义Type3字体创建文档。主要设计理念是将所有数据存储为 rustic 类型,并通过类似于 std::fmt
API 的 trait 进行序列化。
由于PDF本质上是一个通过其ID链接的对象列表,而序列化某些结构需要知道引用的ID,因此此crate具有一个 high
-level 和一个 low
-level 组件,用于表示在分配全局ID之前和之后的文档。
功能
- 任意内容 & 字形流
- 自定义
/Info
值 - Type3字体
- 轮廓
- 页面标签
Ascii85Decode
编码和PDFDocEncoding
的实现
基本用法
此示例创建了一个单个空白的A4页面,没有任何文本
use chrono::Local;
use pdf_create::{
common::Point,
common::{PdfString, Rectangle},
high::{Handle, Page, Resources},
};
// Create a new handle
let mut doc = Handle::new();
// Set some metadata
doc.info.author = Some(PdfString::new("Xiphoseer"));
doc.info.creator = Some(PdfString::new("SIGNUM (c) 1986-93 F. Schmerbeck"));
doc.info.producer = Some(PdfString::new("Signum! Document Toolbox"));
doc.info.title = Some(PdfString::new("EMPTY.SDO"));
doc.info.mod_date = Some(Local::now());
doc.info.creation_date = Some(Local::now());
// Create a page
let page = Page {
media_box: Rectangle {
ll: Point { x: 0, y: 0 },
ur: Point { x: 592, y: 842 },
},
resources: Resources::default(),
contents: Vec::new(),
};
// Add the page to the document
doc.pages.push(page);
// Write the PDF to the console
let stdout = std::io::stdout();
let mut stdolock = stdout.lock();
doc.write(&mut stdolock)?;
替代方案
- 如果您正在寻找可以生成具有任意内容的有效PDF文件的crate,您可能应该使用
lopdf
- 如果您正在寻找可以将图形和文本组合保存为PDF的crate,您可能应该使用
printpdf
,genpdf
或pdf-canvas
- 如果您正在寻找可以加载和渲染PDF的crate,您可能应该使用
pdf
依赖关系
~1MB
~18K SLoC