打印文本文件

时间:2018-04-27 08:07:00

标签: c# printing printf

我正在尝试在执行此代码时打印文本文件,它正在打印一个空文档。 生成的pdf中没有内容(默认打印机是pdf995或adobe pdf)。如果有人可以帮助我,这将有所帮助。

using System;
using System.Activities;
using System.ComponentModel;
using System.Drawing.Printing;

namespace Advanced.PDF.Extended
{
    public class PrintTxtFile : CodeActivity
    {
        [Category("Input")]
        [Description(@" For Ex : C:\Users\userid\Desktop\Input\exam.txt")]
        [DisplayName("Input File Name")]
        [RequiredArgument]
        public InArgument<string> SourceFile { get; set; }

        [Category("Input")]
        [DisplayName("Print in Landscape")]
        public bool Landscape { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            var fileName = SourceFile.Get(context);
            try
            {
                var pd = new PrintDocument
                {
                    DocumentName = fileName,
                    DefaultPageSettings =
                    {
                        Landscape = this.Landscape
                    }
                };
                pd.Print();
            }
            catch (Exception ex) { }
            finally { }
        }
    }
}

0 个答案:

没有答案