当前位置:   article > 正文

【c#系列】PDF进行操作-浏览、分割、合并、插入、删除(2)_c# 操作 pdf

c# 操作 pdf

这节我们主要实现缩小、旋转、打印、分割、合并、放大等功能

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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

实现功能代码:

 private void FangDaBT_Tool_Click(object sender, EventArgs e)
        {
            ViewerPdf.Renderer.ZoomIn();
        }
  • 1
  • 2
  • 3
  • 4

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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

实现功能代码:

  private void SuoXiaoBT_Tool_Click(object sender, EventArgs e)
        {
            ViewerPdf.Renderer.ZoomOut();
        }
  • 1
  • 2
  • 3
  • 4

3、 宽度100%显示

单击宽度100%显示按钮,实现PDF宽度100%显示,效果如下:
宽度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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

实现功能代码:

 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;
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

实现功能代码:

 private void ShuxiangBT_Tool_Click(object sender, EventArgs e)
 {
            FitPage(PdfViewerZoomMode.FitHeight);
 }
  • 1
  • 2
  • 3
  • 4

FitPage函数上面有显示。

5、 顺时针旋转

单击顺时针旋转按钮,实现PDF旋转功能:
顺时针旋转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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

实现功能代码:

  /// <summary>
        /// 顺时针旋转PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ShunBT_Tool_Click(object sender, EventArgs e)
        {
            ViewerPdf.Renderer.RotateRight();
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

实现功能代码:

/// <summary>
        /// 逆时针旋转PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NiBT_Click(object sender, EventArgs e)
        {            
            ViewerPdf.Renderer.RotateLeft();
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

源代码下载

单击下载源代码

相关连接

  1. 【c#系列】PDF进行操作-浏览、分割、合并、插入、删除(1)
  2. 【c#系列】PDF进行操作-浏览、分割、合并、插入、删除(2)
  3. 【c#系列】PDF进行操作-浏览、分割、合并、插入、删除(3)
  4. 【c#系列】PDF进行操作-浏览、分割、合并、插入、删除(4)完
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/1018957
推荐阅读
相关标签
  

闽ICP备14008679号