How to batch print PDF in WPF PDFViewer control?
You can batch print the multiple PDF files using WPF PdfViewer by loading and printing the PDFs one by one in a loop. Add the PDFs present in a directory to a ListView and batch print the multiple PDFs that are selected from the ListView. Refer to the following code sample.
C#
char[] charSplitter = new char[] { '/' };
//Get the PDF files from the directory
files = Directory.GetFiles("../../Data/", "*.pdf");
foreach (string file in files)
{
//Splitting the file name from the file path
string[] fileName = file.Split(charSplitter);
//Adding the file into the list view
list.Items.Add(fileName[3]);
}
if (list.SelectedItems.Count > 0)
{
for (int i = 0; i < list.SelectedItems.Count; i++)
{
string fileName = list.SelectedItems[i].ToString();
for (int j = 0; j < files.Length; j++)
{
if (files[j].Contains(fileName))
{
//Initialize the PdfLoadedDocument
ldoc = new PdfLoadedDocument(files[j]);
//Load the PdfDocument into PdfViewerControl/PdfDocumentView
pdfViewer.Load(ldoc);
//Silent print the PDF document
pdfViewer.Print();
//Unload the PdfViewerControl after printing
pdfViewer.Unload();
//Close the PdfLoadedDocument
ldoc.Close(true);
}
}
}
}
UG link: https://help.syncfusion.com/wpf/pdf-viewer/printing-pdf-files#silent-printing