Hello aspose team.
We need to print generated aspose pdf document at one printing job with some pages printed simplex, some duplex.
How could it be done using aspose pdf?
Hello aspose team.
Hi Victor,
Tilal Ahmad Sana -
Hi Sherri,
Hi Victor,
Thanks for your patience.
We have further investigated the feature of Printing some pages simplex and some duplex within a print job requested earlier. During our investigations, we have figured out that there is no possibility to change the duplex mode within one printing job. Please take a look at the code snippet that uses page ranges to print a document with different types of duplex mode. Therefore you should double-check it with a printer that supports duplex mode:
C#
struct PrintingJobSettings
{
public int ToPage { get; set; }
public int FromPage { get; set; }
public string OutputFile { get; set; }
public System.Drawing.Printing.Duplex Mode { get; set; }
}
public void PrintDocument()
{
int printingJobIndex = 0;
string inPdf = @"c:\35925.pdf";
string output = @"c:\output_dir\";
IList<PrintingJobSettings> printingJobs = new List<PrintingJobSettings>();
PrintingJobSettings printingJob1 = new PrintingJobSettings();
printingJob1.FromPage = 1;
printingJob1.ToPage = 3;
printingJob1.OutputFile = output + "35925_1_3.xps";
printingJob1.Mode = Duplex.Default;
printingJobs.Add(printingJob1);
PrintingJobSettings printingJob2 = new PrintingJobSettings();
printingJob2.FromPage = 4;
printingJob2.ToPage = 6;
printingJob2.OutputFile = output + "35925_4_6.xps";
printingJob2.Mode = Duplex.Simplex;
printingJobs.Add(printingJob2);
PrintingJobSettings printingJob3 = new PrintingJobSettings();
printingJob3.FromPage = 7;
printingJob3.ToPage = 7;
printingJob3.OutputFile = output + "35925_7.xps";
printingJob3.Mode = Duplex.Default;
printingJobs.Add(printingJob3);
PdfViewer viewer = new PdfViewer();
viewer.BindPdf(inPdf);
viewer.AutoResize = true;
viewer.AutoRotate = true;
viewer.PrintPageDialog = false;
PrinterSettings ps = new PrinterSettings();
PageSettings pgs = new PageSettings();
ps.PrinterName = "Microsoft XPS Document Writer";
ps.PrintFileName = System.IO.Path.GetFullPath(printingJobs[printingJobIndex].OutputFile);
ps.PrintToFile = true;
ps.FromPage = printingJobs[printingJobIndex].FromPage;
ps.ToPage = printingJobs[printingJobIndex].ToPage;
ps.Duplex = printingJobs[printingJobIndex].Mode;
ps.PrintRange = PrintRange.SomePages;
pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);
ps.DefaultPageSettings.PaperSize = pgs.PaperSize;
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
viewer.EndPrint += (sender, args) =>
{
if (++printingJobIndex < printingJobs.Count)
{
ps.PrintFileName = System.IO.Path.GetFullPath(printingJobs[printingJobIndex].OutputFile);
ps.FromPage = printingJobs[printingJobIndex].FromPage;
ps.ToPage = printingJobs[printingJobIndex].ToPage;
ps.Duplex = printingJobs[printingJobIndex].Mode;
viewer.PrintDocumentWithSettings(pgs, ps);
}
};
viewer.PrintDocumentWithSettings(pgs, ps);
}