这节我们主要实现缩小、旋转、打印、分割、合并、放大等功能
1、 放大功能
单击放大按钮,实现PDF放大预览,效果如下:
设计代码:
System.Windows.Forms.ToolStripButton FangDaBT_Tool;
FangDaBT_Tool = new System.Windows.Forms.ToolStripButton();
//
// FangDaBT_Tool
//
FangDaBT_Tool.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
FangDaBT_Tool.Image = ((System.Drawing.Image)(resources.GetObject("FangDaBT_Tool.Image")));
FangDaBT_Tool.ImageTransparentColor = System.Drawing.Color.Magenta;
FangDaBT_Tool.Name = "FangDaBT_Tool";
FangDaBT_Tool.Size = new System.Drawing.Size(29, 25);
FangDaBT_Tool.Text = "放大页面";
FangDaBT_Tool.Click += new System.EventHandler(this.FangDaBT_Tool_Click);
实现功能代码:
private void FangDaBT_Tool_Click(object sender, EventArgs e)
{
ViewerPdf.Renderer.ZoomIn();
}
2、 缩小功能
单击缩小按钮,实现PDF缩小预览,效果如下:
设计代码:
private System.Windows.Forms.ToolStripButton SuoXiaoBT_Tool;
this.SuoXiaoBT_Tool = new System.Windows.Forms.ToolStripButton();
//
// SuoXiaoBT_Tool
//
this.SuoXiaoBT_Tool.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.SuoXiaoBT_Tool.Image = ((System.Drawing.Image)(resources.GetObject("SuoXiaoBT_Tool.Image")));
this.SuoXiaoBT_Tool.ImageTransparentColor = System.Drawing.Color.Magenta;
this.SuoXiaoBT_Tool.Name = "SuoXiaoBT_Tool";
this.SuoXiaoBT_Tool.Size = new System.Drawing.Size(29, 24);
this.SuoXiaoBT_Tool.Text = "缩小页面";
this.SuoXiaoBT_Tool.Click += new System.EventHandler(this.SuoXiaoBT_Tool_Click);
实现功能代码:
private void SuoXiaoBT_Tool_Click(object sender, EventArgs e)
{
ViewerPdf.Renderer.ZoomOut();
}
3、 宽度100%显示
单击宽度100%显示按钮,实现PDF宽度100%显示,效果如下:
设计代码:
private System.Windows.Forms.ToolStripButton HengBT_Tool;
this.HengBT_Tool = new System.Windows.Forms.ToolStripButton();
//
// HengBT_Tool
//
this.HengBT_Tool.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.HengBT_Tool.Image = ((System.Drawing.Image)(resources.GetObject("HengBT_Tool.Image")));
this.HengBT_Tool.ImageTransparentColor = System.Drawing.Color.Magenta;
this.HengBT_Tool.Name = "HengBT_Tool";
this.HengBT_Tool.Size = new System.Drawing.Size(29, 24);
this.HengBT_Tool.Text = "横向100%";
this.HengBT_Tool.Click += new System.EventHandler(this.HengBT_Tool_Click);
实现功能代码:
private void HengBT_Tool_Click(object sender, EventArgs e)
{
FitPage(PdfViewerZoomMode.FitWidth);
}
/// <summary>
/// 适时显示页面
/// </summary>
/// <param name="zoomMode"></param>
private void FitPage(PdfViewerZoomMode zoomMode)
{
int page = ViewerPdf.Renderer.Page;
ViewerPdf.ZoomMode = zoomMode;
ViewerPdf.Renderer.Zoom = 1;
ViewerPdf.Renderer.Page = page;
}
4、 高度100%显示
单击高度100%显示按钮,实现PDF高度100%显示:
设计代码:
private System.Windows.Forms.ToolStripButton ShuxiangBT_Tool;
this.ShuxiangBT_Tool= new System.Windows.Forms.ToolStripButton();
//
// ShuxiangBT_Tool
//
this.ShuxiangBT_Tool.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.ShuxiangBT_Tool.Image = ((System.Drawing.Image)(resources.GetObject("ShuxiangBT_Tool.Image")));
this.ShuxiangBT_Tool.ImageTransparentColor = System.Drawing.Color.Magenta;
this.ShuxiangBT_Tool.Name = "ShuxiangBT_Tool";
this.ShuxiangBT_Tool.Size = new System.Drawing.Size(29, 24);
this.ShuxiangBT_Tool.Text = "竖向100%";
this.ShuxiangBT_Tool.Click += new System.EventHandler(this.ShuxiangBT_Tool_Click);
实现功能代码:
private void ShuxiangBT_Tool_Click(object sender, EventArgs e)
{
FitPage(PdfViewerZoomMode.FitHeight);
}
FitPage函数上面有显示。
5、 顺时针旋转
单击顺时针旋转按钮,实现PDF旋转功能:
设计代码:
private System.Windows.Forms.ToolStripButton ShunBT_Tool;
this.ShunBT_Tool= new System.Windows.Forms.ToolStripButton();
//
// ShunBT_Tool
//
this.ShunBT_Tool.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.ShunBT_Tool.Image = ((System.Drawing.Image)(resources.GetObject("ShunBT_Tool.Image")));
this.ShunBT_Tool.ImageTransparentColor = System.Drawing.Color.Magenta;
this.ShunBT_Tool.Name = "ShunBT_Tool";
this.ShunBT_Tool.Size = new System.Drawing.Size(29, 24);
this.ShunBT_Tool.Text = "顺时针旋转Pdf";
this.ShunBT_Tool.Click += new System.EventHandler(this.ShunBT_Tool_Click);
实现功能代码:
/// <summary>
/// 顺时针旋转PDF
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ShunBT_Tool_Click(object sender, EventArgs e)
{
ViewerPdf.Renderer.RotateRight();
}
6、 逆时针旋转
单击向逆时针旋转按钮,实现PDF旋转功能:
设计代码:
private System.Windows.Forms.ToolStripButton NiBT_Tool;
this.NiBT_Tool= new System.Windows.Forms.ToolStripButton();
// NiBT_Tool
//
this.NiBT_Tool.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.NiBT_Tool.Image = ((System.Drawing.Image)(resources.GetObject("NiBT_Tool.Image")));
this.NiBT_Tool.ImageTransparentColor = System.Drawing.Color.Magenta;
this.NiBT_Tool.Name = "NiBT_Tool";
this.NiBT_Tool.Size = new System.Drawing.Size(29, 24);
this.NiBT_Tool.Text = "逆时针旋转Pdf";
this.NiBT_Tool.Click += new System.EventHandler(this.NiBT_Click);
实现功能代码:
/// <summary>
/// 逆时针旋转PDF
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NiBT_Click(object sender, EventArgs e)
{
ViewerPdf.Renderer.RotateLeft();
}