From 9eeebedf5fcde6de4289aba6bc84f04dab4bb640 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sun, 26 Jul 2015 11:43:23 +0800 Subject: [PATCH] Add pageSize option in printToPDF API. --- atom/browser/api/lib/web-contents.coffee | 80 ++++++++++++++++-------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index b2232b72cda6..cb6cc7c0b3d8 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -6,6 +6,34 @@ ipc = require 'ipc' nextId = 0 getNextId = -> ++nextId +PDFPageSize = + A4: + custom_display_name: "A4" + height_microns: 297000 + name: "ISO_A4" + is_default: "true" + width_microns: 210000 + A3: + custom_display_name: "A3" + height_microns: 420000 + name: "ISO_A3" + width_microns: 297000 + Legal: + custom_display_name: "Legal" + height_microns: 355600 + name: "NA_LEGAL" + width_microns: 215900 + Letter: + custom_display_name: "Letter" + height_microns: 279400 + name: "NA_LETTER" + width_microns: 215900 + Tabloid: + height_microns: 431800 + name: "NA_LEDGER" + width_microns: 279400 + custom_display_name: "Tabloid" + wrapWebContents = (webContents) -> # webContents is an EventEmitter. webContents.__proto__ = EventEmitter.prototype @@ -41,32 +69,27 @@ wrapWebContents = (webContents) -> webContents.printToPDF = (options, callback) -> printingSetting = - pageRage:[], - mediaSize: - height_microns:297000, - is_default:true, - name:"ISO_A4", - width_microns:210000, - custom_display_name:"A4", - landscape:false, - color:2, - headerFooterEnabled:false, - marginsType:0, - isFirstRequest:false, - requestID: getNextId(), - previewModifiable:true, - printToPDF:true, - printWithCloudPrint:false, - printWithPrivet:false, - printWithExtension:false, - deviceName:"Save as PDF", - generateDraftData:true, - fitToPageEnabled:false, - duplex:0, - copies:1, - collate:true, - shouldPrintBackgrounds:false, - shouldPrintSelectionOnly:false + pageRage: [] + mediaSize: {} + landscape: false + color: 2 + headerFooterEnabled: false + marginsType: 0 + isFirstRequest: false + requestID: getNextId() + previewModifiable: true + printToPDF: true + printWithCloudPrint: false + printWithPrivet: false + printWithExtension: false + deviceName: "Save as PDF" + generateDraftData: true + fitToPageEnabled: false + duplex: 0 + copies: 1 + collate: true + shouldPrintBackgrounds: false + shouldPrintSelectionOnly: false if options.landscape printingSetting.landscape = options.landscape @@ -77,6 +100,11 @@ wrapWebContents = (webContents) -> if options.printBackgrounds printingSetting.shouldPrintBackgrounds = options.printBackground + if options.pageSize and PDFPageSize[options.pageSize] + printingSetting.mediaSize = PDFPageSize[options.pageSize] + else + printingSetting.mediaSize = PDFPageSize['A4'] + @_printToPDF printingSetting, callback binding._setWrapWebContents wrapWebContents