Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

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

Liang Dingf003aac38451
diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts
index 054e251dc2..e63e06a6fe 100644
--- a/app/src/util/onGetConfig.ts
+++ b/app/src/util/onGetConfig.ts
@@ -3,7 +3,7 @@ import {exportLayout, getInstanceById, JSONToLayout, resetLayout, resizeDrag, re
import {hotKey2Electron, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
/// #if !BROWSER
import {dialog, getCurrentWindow} from "@electron/remote";
-import {webFrame, ipcRenderer, OpenDialogReturnValue} from "electron";
+import {ipcRenderer, OpenDialogReturnValue, webFrame} from "electron";
import * as fs from "fs";
import * as path from "path";
import {afterExport} from "../protyle/export/util";
@@ -418,7 +418,7 @@ export const initWindow = () => {
const pdfFilePath = path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle) + ".pdf");
fs.writeFileSync(pdfFilePath, pdfData);
window.siyuan.printWin.destroy();
- fetchPost("/api/export/addPDFOutline", {
+ fetchPost("/api/export/processPDF", {
id: ipcData.rootId,
merge: ipcData.mergeSubdocs,
path: pdfFilePath
diff --git a/kernel/api/export.go b/kernel/api/export.go
index 1985d5eefd..e7ccb58451 100644
--- a/kernel/api/export.go
+++ b/kernel/api/export.go
@@ -311,7 +311,7 @@ func exportHTML(c *gin.Context) {
}
}
-func addPDFOutline(c *gin.Context) {
+func processPDF(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
@@ -326,7 +326,7 @@ func addPDFOutline(c *gin.Context) {
if nil != arg["merge"] {
merge = arg["merge"].(bool)
}
- err := model.AddPDFOutline(id, path, merge)
+ err := model.ProcessPDF(id, path, merge)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
diff --git a/kernel/api/router.go b/kernel/api/router.go
index eaf1eec5c4..84cfd21911 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -233,7 +233,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/export/exportPreviewHTML", model.CheckAuth, exportPreviewHTML)
ginServer.Handle("POST", "/api/export/exportMdHTML", model.CheckAuth, exportMdHTML)
ginServer.Handle("POST", "/api/export/exportDocx", model.CheckAuth, exportDocx)
- ginServer.Handle("POST", "/api/export/addPDFOutline", model.CheckAuth, addPDFOutline)
+ ginServer.Handle("POST", "/api/export/processPDF", model.CheckAuth, processPDF)
ginServer.Handle("POST", "/api/export/preview", model.CheckAuth, exportPreview)
ginServer.Handle("POST", "/api/export/exportAsFile", model.CheckAuth, exportAsFile)
ginServer.Handle("POST", "/api/export/exportData", model.CheckAuth, exportData)
diff --git a/kernel/go.mod b/kernel/go.mod
index 1f107641b4..5b54492800 100644
--- a/kernel/go.mod
+++ b/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.20230222105639-68297f21b5d2
+ github.com/88250/pdfcpu v0.3.14-0.20230223023428-417e2a8897ac
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
diff --git a/kernel/go.sum b/kernel/go.sum
index 0fd87b5ccd..431469aceb 100644
--- a/kernel/go.sum
+++ b/kernel/go.sum
@@ -10,8 +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.20230222105639-68297f21b5d2 h1:M1JxCmcaLwI7qlQJD5UatAxaIT6tfLvq3GptOsMffn4=
-github.com/88250/pdfcpu v0.3.14-0.20230222105639-68297f21b5d2/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
+github.com/88250/pdfcpu v0.3.14-0.20230223023428-417e2a8897ac h1:deLsfAbzg+KJy53yJDGNe/+9RZr6RR813rbMKOiW/uI=
+github.com/88250/pdfcpu v0.3.14-0.20230223023428-417e2a8897ac/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=
diff --git a/kernel/model/export.go b/kernel/model/export.go
index f0bc3bd61c..6fd1132b23 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -654,7 +654,7 @@ func processIFrame(tree *parse.Tree) {
}
}
-func AddPDFOutline(id, p string, merge bool) (err error) {
+func ProcessPDF(id, p string, merge bool) (err error) {
inFile := p
links, err := api.ListToCLinks(inFile)
if nil != err {