Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 动态配置打印设置_C#_Wpf - Fatal编程技术网

C# 动态配置打印设置

C# 动态配置打印设置,c#,wpf,C#,Wpf,在我的WPF应用程序中有这样一个类,在这里我想分配打印设置,如页面大小、纸盘,而不向用户显示对话框。 我可以设置除打印托盘以外的其他值。如果有人能在这方面帮助我,那将是非常有帮助的 using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; public class Print { /// <summary> /// Ini

在我的WPF应用程序中有这样一个类,在这里我想分配打印设置,如页面大小、纸盘,而不向用户显示对话框。 我可以设置除打印托盘以外的其他值。如果有人能在这方面帮助我,那将是非常有帮助的

using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

public class Print
{
    /// <summary>
    /// Initializes a new instance of the <see cref="Print"/> class.
    /// </summary>
    public Print() { }

    /// <summary>
    /// Prints the document.
    /// </summary>
    /// <param name="outputStream">The output stream.</param>
    public void PrintDocument(MemoryStream outputStream)
    {
        FlowDocument fd = new FlowDocument();

        TextRange tr = new TextRange(fd.ContentStart, fd.ContentEnd);
        tr.Load(outputStream, DataFormats.Rtf);

        PrintDialog printDlg = new PrintDialog();



        fd.PageHeight = printDlg.PrintableAreaHeight;
        fd.PageWidth = printDlg.PrintableAreaWidth;
        fd.PagePadding = new Thickness(25);

        fd.ColumnGap = 0;
        fd.ColumnWidth = (fd.PageWidth -
                               fd.ColumnGap -
                               fd.PagePadding.Left -
                               fd.PagePadding.Right);

        if (printDlg.ShowDialog() == true)
        {              
            IDocumentPaginatorSource idpSource = fd;
            idpSource.DocumentPaginator.PageSize = new Size { Height = 600, Width = 600 };
            printDlg.PrintDocument(idpSource.DocumentPaginator, "Printing Document");
        }
    }
使用System.IO;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
公共类打印
{
/// 
///初始化类的新实例。
/// 
公共打印(){}
/// 
///打印文档。
/// 
///输出流。
公共作废打印文档(MemoryStream outputStream)
{
FlowDocument fd=新的FlowDocument();
TextRange tr=新的TextRange(fd.ContentStart,fd.ContentEnd);
tr.Load(outputStream,DataFormats.Rtf);
PrintDialog printDlg=新建PrintDialog();
fd.PageHeight=printDlg.PrintableAreaHeight;
fd.PageWidth=printDlg.PrintableAreaWidth;
fd.PagePadding=新厚度(25);
fd.columnpag=0;
fd.ColumnWidth=(fd.PageWidth-
fd.ColumnGap-
fd.PagePadding.Left-
fd.PagePadding.Right);
if(printDlg.ShowDialog()==true)
{              
IDocumentPaginatorSource idpSource=fd;
idpSource.DocumentPaginator.PageSize=新大小{高度=600,宽度=600};
printDlg.PrintDocument(idpSource.DocumentPaginator,“打印文档”);
}
}

请使用以下代码设置C语言中的默认页面大小#


PaperSize接受参数NewPageSizeName、Width、Height

查看此相关信息,我能够获得这些值,但找不到任何设置来指定特定的打印机托盘。
    PaperSize paperSize = new PaperSize("papersize", 200, 100);//set the paper size