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

📄 pdfcreate.cs

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

namespace PDFWork
{
    internal class PdfCreator
    {
        /// <summary>
        /// 创建Image PDF
        /// </summary>
        public  void CreateImagePDF()
        {
            PDFDocument MyPDF=null;
            PDFPage page = null;
            PDFImage gifimage = null;

            try
            {
                PDFCreationOptions options = new PDFCreationOptions();
                options.LeftMargin = 10;
                options.RightMargin = 10;

                MyPDF = new PDFDocument("..\\Output\\Demo.pdf", options);

                MyPDF.PageHeader.SetActiveFont("Helvetica", PDFFontStyles.Regular, 25);
                MyPDF.PageHeader.SetTextAlignment(TextAlign.Center);
                MyPDF.PageHeader.AddText("Demo");
                MyPDF.PageHeader.Shapes.DrawLine(new PDFPen());
                MyPDF.AutoLaunch = false;

                page = MyPDF.CurrentPage;
                page.Body.SetActiveFont("Helvetica", PDFFontStyles.Regular, 20);
                page.Body.TextOut(100, 200, 0, "The Image Location is : X:620,Y:800(at the right bottom)");
                page.Body.TextOut(100, 160, 0, "This is the Text and  Location is : X:100,Y:160");

                gifimage = new PDFImage("..\\images\\merlin.gif");
                page.Body.TextOut(600, 820, 0, "PDF Co.Ltd");
                gifimage.Transparency = 50;
                page.Body.AddImage(gifimage, 620, 800);
               
                if (!MyPDF.Save())
                {
                    if (SuccessEvent != null)
                    {
                        SuccessEvent("操作失败--" + MyPDF.Error + DateTime.Now.ToString());
                    }
                }
                else
                {

                    if (SuccessEvent != null)
                    {
                        SuccessEvent("操作成功--" + DateTime.Now.ToString());
                    }
                }
                
            }
            catch (Exception ex)
            {
                SuccessEvent("操作异常--" + ex.ToString() + "--" + DateTime.Now.ToString());
            }
            finally
            {
                MyPDF = null;
                page = null;
                gifimage = null;
            }
        }

        /// <summary>
        /// 代理
        /// </summary>
        /// <param name="strTip"></param>
        public delegate void SuccessEventHandler(string strTip);

        /// <summary>
        /// 事件
        /// </summary>
        public  event SuccessEventHandler SuccessEvent;
    }
}

⌨️ 快捷键说明

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