Send multiple pdf files from one folder to printer. ASPOSE.PDF. C#

泪湿孤枕 提交于 2019-12-13 04:43:47

问题


I'm trying to send multiple files from one folder to printer. Now, I can send just one file from folder to printer. However I want to print the files from the folder. I'm using ASPOSE.PDF I was trying to modify the following code but without success:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Pdf;
using System.Drawing;
using Aspose.Pdf.Facades;


namespace Printer
class Program
{
    static void Main(string[] args)
    {


        PdfViewer viewer = new PdfViewer();
        viewer.BindPdf(@"C:\Printing\Hello.pdf");

        System.Drawing.Printing.PrinterSettings printersetting = new System.Drawing.Printing.PrinterSettings();
        printersetting.Copies = 1; //specify number of copies
        printersetting.PrinterName = "Conan-printer"; // name of default printer to be used

        System.Drawing.Printing.PageSettings pagesetting = new System.Drawing.Printing.PageSettings();
        pagesetting.PaperSource = printersetting.PaperSources[1]; //assign paper source to pagesettings object
        //you can either specify the index of the tray or you can loop through the trays as well.

        viewer.PrintDocumentWithSettings(pagesetting, printersetting);

        viewer.Close();

       }
    }

  }

回答1:


You can copy the above code to a new method, that accepts the pdf file path as argument. In the main method, load files from a folder and then call the method for each file. Below is an example.

// Load pdf files from a folder
string folderPath = @"E:\Loans\cirruslsdemo\HICODistributing";
string[] files = Directory.GetFiles(folderPath, "*.pdf");

// Print pdf files one by one
foreach (string pdfFile in files)
{
    printDocument(pdfFile);
}

private void printDocument(string pdfFile)
{
    PdfViewer viewer = new PdfViewer();
    viewer.BindPdf(pdfFile);

    System.Drawing.Printing.PrinterSettings printersetting = new System.Drawing.Printing.PrinterSettings();
    printersetting.Copies = 1; //specify number of copies
    printersetting.PrinterName = "Conan-printer"; // name of default printer to be used

    System.Drawing.Printing.PageSettings pagesetting = new System.Drawing.Printing.PageSettings();
    pagesetting.PaperSource = printersetting.PaperSources[1]; //assign paper source to pagesettings object
    //you can either specify the index of the tray or you can loop through the trays as well.

    viewer.PrintDocumentWithSettings(pagesetting, printersetting);

    viewer.Close();
}


来源:https://stackoverflow.com/questions/26550552/send-multiple-pdf-files-from-one-folder-to-printer-aspose-pdf-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!