using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.IO;
using Word = Microsoft.Office.Interop.Word;
namespace WordAddInPublishing
{
public partial class Ribbon
{
private void Ribbon_Load(object sender, RibbonUIEventArgs e)
{
}
private void btnPDF_Click(object sender, RibbonControlEventArgs e)
{
string desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string fileName = "QuickExport.pdf";
Globals.ThisAddIn.Application.ActiveDocument.ExportAsFixedFormat(
Path.Combine(desktopFolder, fileName),
Word.WdExportFormat.wdExportFormatPDF,
OpenAfterExport: true);
}
private void btnXps_Click(object sender, RibbonControlEventArgs e)
{
string desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string fileName = "QuickExport.xps";
Globals.ThisAddIn.Application.ActiveDocument.ExportAsFixedFormat(
Path.Combine(desktopFolder, fileName),
Word.WdExportFormat.wdExportFormatXPS,
OpenAfterExport: true);
}
}
}
Ribbon.cs
namespace WordAddInPublishing
{
partial class Ribbon : Microsoft.Office.Tools.Ribbon.RibbonBase
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
public Ribbon()
: base(Globals.Factory.GetRibbonFactory())
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tabPublishing = this.Factory.CreateRibbonTab();
this.groupSaveAs = this.Factory.CreateRibbonGroup();
this.btnXps = this.Factory.CreateRibbonButton();
this.btnPDF = this.Factory.CreateRibbonButton();
this.tabPublishing.SuspendLayout();
this.groupSaveAs.SuspendLayout();
//
// tabPublishing
//
this.tabPublishing.ControlId.ControlIdType = Microsoft.Office.Tools.Ribbon.RibbonControlIdType.Office;
this.tabPublishing.Groups.Add(this.groupSaveAs);
this.tabPublishing.Label = "Publishing";
this.tabPublishing.Name = "tabPublishing";
//
// groupSaveAs
//
this.groupSaveAs.Items.Add(this.btnXps);
this.groupSaveAs.Items.Add(this.btnPDF);
this.groupSaveAs.Label = "Save As";
this.groupSaveAs.Name = "groupSaveAs";
//
// btnXps
//
this.btnXps.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.btnXps.Image = global::WordAddInPublishing.Properties.Resources.XPS_icon_48x48;
this.btnXps.Label = "XPS";
this.btnXps.Name = "btnXps";
this.btnXps.ShowImage = true;
this.btnXps.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnXps_Click);
//
// btnPDF
//
this.btnPDF.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge;
this.btnPDF.Image = global::WordAddInPublishing.Properties.Resources.PDFicon_48x48;
this.btnPDF.Label = "PDF";
this.btnPDF.Name = "btnPDF";
this.btnPDF.ShowImage = true;
this.btnPDF.Click += new Microsoft.Office.Tools.Ribbon.RibbonControlEventHandler(this.btnPDF_Click);
//
// Ribbon
//
this.Name = "Ribbon";
this.RibbonType = "Microsoft.Word.Document";
this.Tabs.Add(this.tabPublishing);
this.Load += new Microsoft.Office.Tools.Ribbon.RibbonUIEventHandler(this.Ribbon_Load);
this.tabPublishing.ResumeLayout(false);
this.tabPublishing.PerformLayout();
this.groupSaveAs.ResumeLayout(false);
this.groupSaveAs.PerformLayout();
}
#endregion
internal Microsoft.Office.Tools.Ribbon.RibbonTab tabPublishing;
internal Microsoft.Office.Tools.Ribbon.RibbonGroup groupSaveAs;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnPDF;
internal Microsoft.Office.Tools.Ribbon.RibbonButton btnXps;
}
partial class ThisRibbonCollection
{
internal Ribbon Ribbon
{
get { return this.GetRibbon<Ribbon>(); }
}
}
}
ThisAddIn.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
namespace WordAddInPublishing
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}