1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #18031 from Snuffleupagus/issue-18030

[api-minor] Expose the /Desc-attribute of file attachments in the viewer (issue 18030)
This commit is contained in:
Jonas Jenwald 2024-05-01 17:53:22 +02:00 committed by GitHub
commit 16dbf5dcfd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 48 additions and 12 deletions

View file

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { stringToPDFString, warn } from "../shared/util.js";
import { shadow, stringToPDFString, warn } from "../shared/util.js";
import { BaseStream } from "./base_stream.js";
import { Dict } from "./primitives.js";
@ -53,9 +53,6 @@ class FileSpec {
if (root.has("FS")) {
this.fs = root.get("FS");
}
this.description = root.has("Desc")
? stringToPDFString(root.get("Desc"))
: "";
if (root.has("RF")) {
warn("Related file specifications are not supported");
}
@ -102,10 +99,21 @@ class FileSpec {
return content;
}
get description() {
let description = "";
const desc = this.root?.get("Desc");
if (desc && typeof desc === "string") {
description = stringToPDFString(desc);
}
return shadow(this, "description", description);
}
get serializable() {
return {
filename: this.filename,
content: this.content,
description: this.description,
};
}
}

View file

@ -857,6 +857,9 @@ class LinkAnnotationElement extends AnnotationElement {
*/
#bindAttachment(link, attachment, dest = null) {
link.href = this.linkService.getAnchorUrl("");
if (attachment.description) {
link.title = attachment.description;
}
link.onclick = () => {
this.downloadManager?.openOrDownloadData(
attachment.content,
@ -2856,7 +2859,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
constructor(parameters) {
super(parameters, { isRenderable: true });
const { filename, content } = this.data.file;
const { filename, content, description } = this.data.file;
this.filename = getFilenameFromUrl(filename, /* onlyStripPath = */ true);
this.content = content;
@ -2864,6 +2867,7 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
source: this,
filename,
content,
description,
});
}