Bug 465305 - Save page [r=mark.finkle]

This commit is contained in:
Vivien Nicolas 2010-03-26 15:06:58 -04:00
Родитель 489af45e8c
Коммит fd6ecd4456
3 изменённых файлов: 52 добавлений и 0 удалений

Просмотреть файл

@ -937,6 +937,55 @@ var PageActions = {
lm.setLoginSavingEnabled(host.prePath, true);
},
_savePageAsPDF: function saveAsPDF() {
let contentWindow = Browser.selectedBrowser.contentWindow;
let strings = Elements.browserBundle;
let picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
picker.init(window, strings.getString("pageactions.saveas.pdf"), Ci.nsIFilePicker.modeSave);
picker.appendFilter("PDF", "*.pdf");
picker.defaultExtension = "pdf";
picker.defaultString = contentWindow.document.title + ".pdf";
let rv = picker.show();
if (rv == Ci.nsIFilePicker.returnCancel)
return;
let printSettings = Cc["@mozilla.org/gfx/printsettings-service;1"]
.getService(Ci.nsIPrintSettingsService)
.newPrintSettings;
printSettings.printSilent = true;
printSettings.showPrintProgress = false;
printSettings.printBGImages = true;
printSettings.printBGColors = true;
printSettings.printToFile = true;
printSettings.toFileName = picker.file.path;
printSettings.printFrameType = Ci.nsIPrintSettings.kFramesAsIs;
printSettings.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF;
//XXX we probably need a preference here, the header can be useful
printSettings.footerStrCenter = '';
printSettings.footerStrLeft = '';
printSettings.footerStrRight = '';
printSettings.headerStrCenter = '';
printSettings.headerStrLeft = '';
printSettings.headerStrRight = '';
let webBrowserPrint = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebBrowserPrint);
webBrowserPrint.print(printSettings, null);
},
updatePageSaveAs: function updatePageSaveAs() {
if (Browser.selectedBrowser.contentDocument instanceof XULDocument)
return;
let strings = Elements.browserBundle;
let node = this.appendItem(strings.getString("pageactions.saveas.pdf"), "");
node.onclick = function(event) {
PageActions._savePageAsPDF();
}
},
appendItem: function appendItem(aTitle, aDesc, aImage) {
let container = document.getElementById("pageactions-container");
let item = document.createElement("pageaction");

Просмотреть файл

@ -2140,6 +2140,8 @@ IdentityHandler.prototype = {
// clean all the previous result
PageActions.removeAllItems();
PageActions.updatePageSaveAs();
// Update the search engines results
BrowserSearch.updatePageSearchEngines();

Просмотреть файл

@ -135,6 +135,7 @@ tabs.closeWarningPromptMe=Warn me when I attempt to close multiple tabs
homepage.custom=Custom
# Page Actions
pageactions.saveas.pdf=Save As PDF
pageactions.search.addNew=Add Search Engine
pageactions.password.forget=Forget Password
pageactions.reset=Clear Site Preferences