Skip to content

Commit

Permalink
EPUB/Snapshot: Override print options to correct title & URL
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek committed Nov 7, 2024
1 parent c1a538a commit a47febd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/dom/epub/epub-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,21 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {
);

if (typeof this._iframeWindow.zoteroPrint === 'function') {
await this._iframeWindow.zoteroPrint();
await this._iframeWindow.zoteroPrint({
overrideSettings: {
// Set title based on the book's title
title: this.book.packaging.metadata.title || '',
// Remove 'about:srcdoc' URL
docURL: '',
// And disable printing either of those things in the margins by default
headerStrLeft: '',
headerStrCenter: '',
headerStrRight: '',
footerStrLeft: '',
footerStrCenter: '',
footerStrRight: '',
}
});
}
else {
this._iframeWindow.print();
Expand Down
11 changes: 9 additions & 2 deletions src/dom/snapshot/snapshot-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class SnapshotView extends DOMView<SnapshotViewState, SnapshotViewData> {
getData() {
return {
srcDoc: this._iframe.srcdoc,
url: this._iframeDocument.head.querySelector('base')?.href
url: this._iframeDocument.head.querySelector('base')?.href,
importedFromURL: this._options.data.importedFromURL,
};
}

Expand Down Expand Up @@ -506,7 +507,11 @@ class SnapshotView extends DOMView<SnapshotViewState, SnapshotViewData> {

async print() {
if (typeof this._iframeWindow.zoteroPrint === 'function') {
await this._iframeWindow.zoteroPrint();
await this._iframeWindow.zoteroPrint({
overrideSettings: {
docURL: this._options.data.importedFromURL || '',
},
});
}
else {
this._iframeWindow.print();
Expand All @@ -524,6 +529,8 @@ export interface SnapshotViewState extends DOMViewState {

export interface SnapshotViewData {
srcDoc?: string;
url?: string;
importedFromURL?: string;
}

export default SnapshotView;
2 changes: 1 addition & 1 deletion src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare interface Window {

DarkReader: typeof import('darkreader');

zoteroPrint?: () => Promise<void>;
zoteroPrint?: (options?: { overrideSettings?: Record<string, string> }) => Promise<void>;
}

declare interface Document {
Expand Down

0 comments on commit a47febd

Please sign in to comment.