Skip to content

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

:art: Improve embedded asset attachment usability in PDF exports https://github.com/siyuan-note/siyuan/issues/18827

Daniel43425477fd68
diff --git a/app/appearance/icons/index.html b/app/appearance/icons/index.html
index 3f5dbaadd0..62fe6823c2 100644
--- a/app/appearance/icons/index.html
+++ b/app/appearance/icons/index.html
@@ -412,6 +412,12 @@
</svg>
iconArrowDown
</div>
+ <div>
+ <svg>
+ <use xlink:href="#iconPaperclip"></use>
+ </svg>
+ iconPaperclip
+ </div>
<div>
<svg>
<use xlink:href="#iconUnpin"></use>
diff --git a/app/appearance/icons/litheness/icon.js b/app/appearance/icons/litheness/icon.js
index cfe73062ad..6307febba2 100644
--- a/app/appearance/icons/litheness/icon.js
+++ b/app/appearance/icons/litheness/icon.js
@@ -195,6 +195,9 @@ document.body.insertAdjacentHTML('afterbegin', `<svg id="iconsLitheness" style="
<symbol id="iconArrowDown" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 5v14"/><path d="m19 12-7 7-7-7"/>
</symbol>
+ <symbol id="iconPaperclip" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
+ <path d="m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"/>
+ </symbol>
<symbol id="iconUnpin" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 17v5"/><path d="M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89"/><path d="m2 2 20 20"/><path d="M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11"/>
</symbol>
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index 8a09268ddc..b6b319a251 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -299,6 +299,25 @@ const renderPDF = async (id: string) => {
#preview .render-node[data-subtype="plantuml"] object {
max-width: 100%;
}
+
+ #preview a.pdf-embedded-asset {
+ position: relative;
+ padding-right: 1em !important;
+ }
+
+ #preview .pdf-embedded-asset__icon {
+ position: absolute;
+ right: 0;
+ bottom: 0;
+ width: 1em;
+ height: 1em;
+ color: currentColor;
+ pointer-events: none;
+ }
+
+ .exporting #preview .pdf-embedded-asset__icon {
+ visibility: hidden;
+ }
${await setInlineStyle(false, servePath)}
${await getPluginStyle()}
</style>
@@ -674,6 +693,7 @@ ${getIconScript(servePath)}
mergeContentHeadingModeElement.addEventListener('change', () => {
refreshPreview();
});
+ const removeAssetsElement = actionElement.querySelector("#removeAssets");
const watermarkElement = actionElement.querySelector('#watermark');
const refreshPreview = () => {
previewElement.innerHTML = '<div class="fn__loading" style="left:0;height: 100vh"><img width="48px" src="${servePath}stage/loading-pure.svg"></div>'
@@ -690,6 +710,7 @@ ${getIconScript(servePath)}
}
setPadding();
renderPreview(response2.data);
+ reserveEmbeddedAssetSpace(removeAssetsElement.checked);
})
};
@@ -754,13 +775,30 @@ ${getIconScript(servePath)}
mergeDocHeadingMode: mergeDocHeadingModeElement.value,
mergeContentHeadingMode: mergeContentHeadingModeElement.value,
watermark: watermarkElement.checked,
- removeAssets: actionElement.querySelector("#removeAssets").checked,
+ removeAssets: removeAssetsElement.checked,
paged: !unPagedPageSize,
rootId: "${id}",
rootTitle: response.data.name,
parentWindowId: ${currentWindowId},
};
};
+ const reserveEmbeddedAssetSpace = (enabled) => {
+ // 为内嵌附件注解预留空间,避免覆盖后续文本。
+ previewElement.querySelectorAll("a[href]").forEach((item) => {
+ const url = new URL(item.href);
+ const embedded = enabled && url.hostname === "127.0.0.1" && url.pathname.includes("/assets/");
+ item.classList.toggle("pdf-embedded-asset", embedded);
+ const iconElement = item.querySelector(".pdf-embedded-asset__icon");
+ if (embedded && !iconElement) {
+ item.insertAdjacentHTML("beforeend", '<svg aria-hidden="true" class="pdf-embedded-asset__icon"><use xlink:href="#iconPaperclip"></use></svg>');
+ } else if (!embedded) {
+ iconElement?.remove();
+ }
+ });
+ };
+ removeAssetsElement.addEventListener("change", () => {
+ reserveEmbeddedAssetSpace(removeAssetsElement.checked);
+ });
const waitForImages = () => Promise.all(Array.from(previewElement.querySelectorAll("img")).map((image) => {
image.loading = "eager";
if (image.complete) {
@@ -788,6 +826,7 @@ ${getIconScript(servePath)}
if (result.canceled || result.filePaths.length === 0) {
return;
}
+ reserveEmbeddedAssetSpace(removeAssetsElement.checked);
await waitForImages();
const isPaged = actionElement.querySelector("#paged").checked;
let exportConfig;
@@ -825,6 +864,7 @@ ${getIconScript(servePath)}
});
setPadding();
renderPreview(response.data);
+ reserveEmbeddedAssetSpace(removeAssetsElement.checked);
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
const {ipcRenderer} = require("electron");
diff --git a/kernel/model/export.go b/kernel/model/export.go
index edcd434512..7456189b04 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -1945,10 +1945,11 @@ func processPDFLinkEmbedAssets(pdfCtx *model.Context, assetDests []string, boxID
continue
}
- lx := link.Rect.LL.X + link.Rect.Width()
- ly := link.Rect.LL.Y + link.Rect.Height()/2
- w := link.Rect.Height() / 2
- h := link.Rect.Height() / 2
+ // 附件注解放在前端预留的链接尾部空间内。
+ lx := link.Rect.LL.X + link.Rect.Width() - link.Rect.Height()
+ ly := link.Rect.LL.Y
+ w := link.Rect.Height()
+ h := link.Rect.Height()
d := types.Dict(
map[string]types.Object{
@@ -1963,7 +1964,7 @@ func processPDFLinkEmbedAssets(pdfCtx *model.Context, assetDests []string, boxID
"C": types.NewNumberArray(0.5, 0.0, 0.5),
"CA": types.Float(0.95),
"CreationDate": now,
- "Name": types.Name("FileAttachment"),
+ "Name": types.Name("Paperclip"),
"FS": *ir,
"NM": types.StringLiteral(""),
},