mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-29 08:46:55 +08:00
1 parent
b3c4bbc844
commit
961bc52038
43 files changed
+2283
-2594
No files matched your search
@@ -19,6 +19,7 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"github.com/tdewolff/canvas"
|
||||
@@ -150,6 +151,34 @@ func (r *pdfRenderer) glyphPath(path *canvas.Path, matrix canvas.Matrix) *canvas
|
||||
return converted
|
||||
}
|
||||
|
||||
// writePDF 传递后端资源记录及OFD导航修正,写出最终PDF
|
||||
// 入参: ctx 取消上下文, data 后端PDF数据, writer 输出流, optimization 优化配置
|
||||
// 返回: error 资源、压缩或写入错误
|
||||
func (r *pdfRenderer) writePDF(ctx context.Context, data []byte, writer io.Writer, optimization pdfgo.OptimizeOptions) error {
|
||||
if r.imageError != nil {
|
||||
return r.imageError
|
||||
}
|
||||
options := codecpdf.WriteOptions{
|
||||
Images: r.images,
|
||||
Text: r.text,
|
||||
ExactImages: r.exactImages,
|
||||
ExactText: r.exactText,
|
||||
Optimization: optimization,
|
||||
}
|
||||
if r.navigation != nil && r.navigation.nativeWrite {
|
||||
options.Links = make(map[int][]*pdfgo.LinkRegion, len(r.navigation.Link))
|
||||
for page, links := range r.navigation.Link {
|
||||
regions := make([]*pdfgo.LinkRegion, len(links))
|
||||
for i, link := range links {
|
||||
regions[i] = link.Region
|
||||
}
|
||||
options.Links[page] = regions
|
||||
}
|
||||
options.PrepareRewrite = r.navigation.prepareRewrite
|
||||
}
|
||||
return codecpdf.Write(ctx, data, writer, options)
|
||||
}
|
||||
|
||||
// newPDFNavigation 建立文档导航与输出页索引,不读取页面图元
|
||||
// 入参: renderer 渲染器, doc 文档结构, pages 输出页面描述
|
||||
// 返回: *pdfNavigation 导航信息, error 资源或目标错误
|
||||
|
||||
Reference in new issue
Block a user