C# Распечатать PDF-файл программно?

Мой код печати, приведенный ниже

void SaveReport(Telerik.Reporting.Report report, string fileName)
{
    ReportProcessor reportProcessor = new ReportProcessor();
    Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
    instanceReportSource.ReportDocument = report;
    RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

    using (FileStream fs = new FileStream(fileName, FileMode.Create))
    {
        fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
    }

    // initialize PrintDocument object
    PrintDocument doc = new PrintDocument()
    {
        PrinterSettings = new PrinterSettings()
        {
            // set the printer to 'Microsoft Print to PDF'
            PrinterName = "Canon LBP3000",

            // tell the object this document will print to file
            // PrintToFile = true,

            // set the filename to whatever you like (full path)
            PrintFileName = fileName,
        }
    };
    doc.DocumentName = "My";
    doc.Print();
}

Затем я вызываю функцию, например

SaveReport(new ThermalPrint(), Server.MapPath(@"~\Report\123.pdf"));

Функция выполняется без ошибок, но принтер не печатает PDF-файл. Диалоговое окно печати принтера, например введите здесь описание изображения

Я не могу понять проблему.


person Prasanna Kumar J    schedule 19.12.2017    source источник


Ответы (1)


Если вы хотите распечатать отчет, вызовите reportProcessor.PrintReport(typeReportSource, printerSettings). но убедитесь, что вы предоставили действительный PrinterSettings.

person rene    schedule 17.01.2019