🎨 导出 PDF 时支持将资源文件作为附件嵌入 https://github.com/siyuan-note/siyuan/issues/7414

This commit is contained in:
Liang Ding 2023-02-23 12:41:50 +08:00
parent a576708916
commit c07a58131f
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 10 additions and 8 deletions

View file

@ -791,6 +791,7 @@ func ProcessPDF(id, p string, merge, removeAssets bool) (err error) {
linkMap := map[int][]pdfcpu.AnnotationRenderer{}
for _, link := range otherLinks {
link.URI, _ = url.PathUnescape(link.URI)
if 1 > len(linkMap[link.Page]) {
linkMap[link.Page] = []pdfcpu.AnnotationRenderer{link}
} else {
@ -798,7 +799,7 @@ func ProcessPDF(id, p string, merge, removeAssets bool) (err error) {
}
}
attachementMap := map[int][]*pdfcpu.IndirectRef{}
attachmentMap := map[int][]*pdfcpu.IndirectRef{}
now := pdfcpu.StringLiteral(pdfcpu.DateString(time.Now()))
for _, link := range assetLinks {
link.URI = strings.ReplaceAll(link.URI, "http://127.0.0.1:6806/export/temp/", "")
@ -883,10 +884,10 @@ func ProcessPDF(id, p string, merge, removeAssets bool) (err error) {
continue
}
if 1 > len(linkMap[link.Page]) {
attachementMap[link.Page] = []*pdfcpu.IndirectRef{ann}
if 1 > len(attachmentMap[link.Page]) {
attachmentMap[link.Page] = []*pdfcpu.IndirectRef{ann}
} else {
attachementMap[link.Page] = append(attachementMap[link.Page], ann)
attachmentMap[link.Page] = append(attachmentMap[link.Page], ann)
}
}
@ -897,7 +898,7 @@ func ProcessPDF(id, p string, merge, removeAssets bool) (err error) {
}
// 添加附件注解指向内嵌的附件
for page, anns := range attachementMap {
for page, anns := range attachmentMap {
pageDictIndRef, pageErr := pdfCtx.PageDictIndRef(page)
if nil != pageErr {
logging.LogWarnf("page dict ind ref failed: %s", pageErr)