Free Support Forum - aspose.com

Prinitng Multiple PDFs with a single click

I am working on a Windows Application that allows a user to select 5-6 pdf documents and then attempt to print it all at once. Right now I am using PDFEditor to concatenate the files and then use the PdfViewer to allow the user to select the printer and then print.

Is there a better way to do this? I want them to select the printer just once and then I want to call the PrintDocument as many times as the number of documents they wish to print.

Hi,

Thank you for considering Aspose.

Have you tried to set PrinterSetting and user PrintDocumentWithSettings function for printing. I think what you need is to set the page and printer setting and then use PrintDocumentWithSettings(PageSettings, PrinterSettings) function to get your required goals. Here is the chunk of code to use this function:

[C#]

Aspose.Pdf.Kit.PdfViewer pdv = new Aspose.Pdf.Kit.PdfViewer();

System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();

ps.PrinterName = @"Microsoft Office Document Image Writer";

System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();

pdv.OpenPdfFile("D:/AsposeTest/asposepdf_original.pdf");

pdv.PrintDocumentWithSettings(pgs, ps);

pdv.ClosePdfFile();

Hope this helps. If you need more help please do let us knew.

Thanks.

Thank you for your help. I used the windows print dialog to get the printer name and then printed the document one at a time.

Here is my code....its still work in progress but I thought I would share.

'select the printer

Dim p As New PrintDialog()

If p.ShowDialog = Windows.Forms.DialogResult.OK Then

Dim bytes() As Byte

Dim printerName As String = p.PrinterSettings.PrinterName

For i = 0 To lstInvoiceID.Count - 1

bytes = wsPrint.PrintInvoiceByInvoiceID(lstInvoiceID(i))

If Not bytes Is Nothing Then

Dim pdfViewer As New PdfViewer()

Dim ps As New PrinterSettings()

Dim pgs As New PageSettings()

ps.PrinterName = printerName

Dim pdfStream As New MemoryStream(bytes)

PdfViewer.OpenPdfFile(pdfStream)

PdfViewer.PrintDocumentWithSettings(pgs, ps)

PdfViewer.ClosePdfFile()

pdfStream.Close()

End If

bytes = Nothing

Next

End If