diff --git a/news/2 Fixes/9403.md b/news/2 Fixes/9403.md new file mode 100644 index 000000000000..c3f8ae7dcaea --- /dev/null +++ b/news/2 Fixes/9403.md @@ -0,0 +1 @@ +Ensure plot fits within the page of the `PDF`. diff --git a/src/client/datascience/plotting/plotViewer.ts b/src/client/datascience/plotting/plotViewer.ts index d4619acbbe2a..826ce491adb9 100644 --- a/src/client/datascience/plotting/plotViewer.ts +++ b/src/client/datascience/plotting/plotViewer.ts @@ -145,12 +145,14 @@ export class PlotViewer extends WebViewHost implements IPlot const SVGtoPDF = require('svg-to-pdfkit'); const deferred = createDeferred(); // tslint:disable-next-line: no-require-imports - const pdfkit = require('pdfkit'); + const pdfkit = require('pdfkit') as typeof import('pdfkit'); const doc = new pdfkit(); const ws = this.fileSystem.createWriteStream(file.fsPath); traceInfo(`Writing pdf to ${file.fsPath}`); ws.on('finish', () => deferred.resolve); - SVGtoPDF(doc, payload.svg, 0, 0); + // See docs or demo from source https://cdn.statically.io/gh/alafr/SVG-to-PDFKit/master/examples/demo.htm + // How to resize to fit (fit within the height & width of page). + SVGtoPDF(doc, payload.svg, 0, 0, { preserveAspectRatio: 'xMinYMin meet' }); doc.pipe(ws); doc.end(); traceInfo(`Finishing pdf to ${file.fsPath}`); diff --git a/src/test/datascience/nativeEditor.functional.test.tsx b/src/test/datascience/nativeEditor.functional.test.tsx index c8e76b560771..b722be493ae5 100644 --- a/src/test/datascience/nativeEditor.functional.test.tsx +++ b/src/test/datascience/nativeEditor.functional.test.tsx @@ -2194,7 +2194,7 @@ df.head()`; await makeChangesAndConfirmFileIsUpdated(); await makeChangesAndConfirmFileIsUpdated(); await makeChangesAndConfirmFileIsUpdated(); - }); + }).retries(2); test('File saved with same format', async () => { // Configure notebook to save automatically ever 1s.