Quellcode durchsuchen

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

Liang Ding vor 2 Jahren
Ursprung
Commit
c07a58131f
3 geänderte Dateien mit 10 neuen und 8 gelöschten Zeilen
  1. 2 3
      kernel/go.mod
  2. 2 0
      kernel/go.sum
  3. 6 5
      kernel/model/export.go

+ 2 - 3
kernel/go.mod

@@ -7,7 +7,7 @@ require (
 	github.com/88250/css v0.1.2
 	github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798
 	github.com/88250/lute v1.7.6-0.20230220030205-b0f64d7ba66e
-	github.com/88250/pdfcpu v0.3.14-0.20230223023428-417e2a8897ac
+	github.com/88250/pdfcpu v0.3.14-0.20230223031826-d2ae187e1c38
 	github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
 	github.com/ClarkThan/ahocorasick v0.0.0-20230216061320-bccdb98581a3
 	github.com/ConradIrwin/font v0.0.0-20210318200717-ce8d41cc0732
@@ -141,7 +141,6 @@ replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20
 //replace github.com/siyuan-note/httpclient => D:\88250\httpclient
 //replace github.com/siyuan-note/filelock => D:\88250\filelock
 //replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute
-replace github.com/88250/pdfcpu => D:\88250\pdfcpu
-
+//replace github.com/88250/pdfcpu => D:\88250\pdfcpu
 //replace github.com/88250/gulu => D:\88250\gulu
 //replace github.com/mattn/go-sqlite3 => D:\88250\go-sqlite3

+ 2 - 0
kernel/go.sum

@@ -10,6 +10,8 @@ github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798 h1:sR/s/Y9wyl79ZRCUER
 github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
 github.com/88250/lute v1.7.6-0.20230220030205-b0f64d7ba66e h1:7UgFzsksh+z6IX2z+BKG3tt1TU7LJNb0zOHDbhLEaUc=
 github.com/88250/lute v1.7.6-0.20230220030205-b0f64d7ba66e/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
+github.com/88250/pdfcpu v0.3.14-0.20230223031826-d2ae187e1c38 h1:MaFRabDTXOpLBrdP4qkZnjFBIUTu/rk8S6fu7hC6jCY=
+github.com/88250/pdfcpu v0.3.14-0.20230223031826-d2ae187e1c38/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
 github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
 github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1/go.mod h1:U3pckKQIgxxkmZjV5yXQjHdGxQK0o/vEZeZ6cQsxfHw=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=

+ 6 - 5
kernel/model/export.go

@@ -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)