⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 C#操作pdf,创建PDF文件并能操作文字和图像合成
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;

namespace PDFWork
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();            
        }

        /// <summary>
        /// 创建PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreatePdf_Click(object sender, EventArgs e)
        {
            PdfCreator pCreator = new PdfCreator();
            
            try
            {
                this.Cursor = Cursors.WaitCursor;
                pCreator.SuccessEvent += new PdfCreator.SuccessEventHandler(SuccessTip);
                pCreator.CreateImagePDF();
                string strPath = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\", string.Empty) + "Output\\Demo.pdf";
                if (File.Exists(strPath))
                {
                    labTip.Text = string.Empty;
                    PdfContainer.src = strPath;
                    PdfContainer.Update();

                }
                else
                {
                    labTip.Text = "PDF文件不存在";
                }

                this.Cursor = Cursors.Default;   
            }
            catch
            {
                labTip.Text = "出现内部错误.";
            }                
        }

        /// <summary>
        /// 写入操作日志
        /// </summary>
        /// <param name="strTip"></param>
        public static void SuccessTip(string strTip)
        {
            string path = @"C:\\log.txt";

            if (!File.Exists(path))
            {
                using (StreamWriter sw = File.CreateText(path))
                {
                    sw.WriteLine(strTip);
                    sw.Flush();
                    sw.Close();
                }
            }
            else
            {
                using (StreamWriter sw = File.AppendText(path))
                {
                    sw.WriteLine(strTip);
                    sw.Flush();
                    sw.Close();
                }
            }
        }     
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -