Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPUB/Snapshot: Override print options to correct title & URL #149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading