Skip to content

Commit 00cffe8

Browse files
committed
Ensure plot fits within page
1 parent 0aa6088 commit 00cffe8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

news/2 Fixes/9403.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure plot fits within the page of the `PDF`.

src/client/datascience/plotting/plotViewer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,15 @@ export class PlotViewer extends WebViewHost<IPlotViewerMapping> implements IPlot
145145
const SVGtoPDF = require('svg-to-pdfkit');
146146
const deferred = createDeferred<void>();
147147
// tslint:disable-next-line: no-require-imports
148-
const pdfkit = require('pdfkit');
148+
const pdfkit = require('pdfkit') as typeof import('pdfkit');
149149
const doc = new pdfkit();
150150
const ws = this.fileSystem.createWriteStream(file.fsPath);
151151
traceInfo(`Writing pdf to ${file.fsPath}`);
152152
ws.on('finish', () => deferred.resolve);
153-
SVGtoPDF(doc, payload.svg, 0, 0);
153+
// See docs or demo from source https://cdn.statically.io/gh/alafr/SVG-to-PDFKit/master/examples/demo.htm
154+
// How to resize to fit (fit within the height & width of page).
155+
const options = { preserveAspectRatio: 'xMinYMin meet' };
156+
SVGtoPDF(doc, payload.svg, 0, 0, options);
154157
doc.pipe(ws);
155158
doc.end();
156159
traceInfo(`Finishing pdf to ${file.fsPath}`);

0 commit comments

Comments
 (0)