use versin width System.Drawing.Printing dependency like 23.5
2.update to 24.8
end
I use System.Drawing.Printing.PrinterSettings and System.Drawing.Printing.PageSettings
i set paper source by name and use ToAsposePageSettings and ToAsposePrinterSettings funtion to Convert type for PrintDocumentWithSettings
but paper source not work
I tried to use a paperless tray for printing,normally the printer should not print,And when I use System.Drawing.Printing.PrintDocument to do it, it doesn’t print either
When I print with PdfViewer, it prints from other tray that have paper
Aspose.Pdf version:24.6.0
PdfViewer viewer = new PdfViewer();
foreach (var filePath in filePaths)
{
viewer.BindPdf(filePath);
viewer.PrinterJobName = Path.GetFileName(filePath);
viewer.Resolution = 110;
viewer.AutoResize = true;
viewer.AutoRotate = false;
viewer.PrintPageDialog = false;
PrinterSettings ps = new PrinterSettings
{
PrinterName = deviceName
};
PageSettings pgs = new();
ps.Duplex = GetPrinterDuplexMode(mode);
pgs.PaperSize = PrinterPrintPaperSizes.A4;
PaperSource? source = null;
foreach (PaperSource p in ps.PaperSources)
{
if (p.SourceName.Trim() == "Tary 1")
{
source = p;
break;
}
}
if (source == null)
throw new NotSupportedException("Tary 1");
pgs.PaperSource = source;
ps.DefaultPageSettings.PaperSource = source;
viewer.PrintDocumentWithSettings(pgs.ToAsposePageSettings(), ps.ToAsposePrinterSettings());
if (viewer.PrintStatus != null)
{
if (viewer.PrintStatus is Exception ex)
{
throw ex;
}
}
It seems you are experiencing issues with selecting the correct paper source when printing PDFs using Aspose.Pdf. This problem may have arisen after upgrading to a newer version of the library, which has changed how tray selection is handled.
Here are some steps and considerations that might help you resolve the issue:
Check Paper Source Availability: Ensure that the paper source you are trying to select (e.g., “Tray 1”) is available on the printer. You can list all available paper sources using the PrinterSettings class to confirm that “Tray 1” is indeed present.
Use Aspose.Pdf.Printing Classes: Since you are using Aspose.Pdf, make sure you are utilizing the Aspose.Pdf.Printing.PrinterSettings and Aspose.Pdf.Printing.PageSettings classes instead of the standard System.Drawing.Printing classes. This is important as the newer versions of Aspose.Pdf may have specific implementations for handling printing.
Setting Paper Source: When setting the paper source, ensure that you are correctly assigning it to both the PageSettings and the PrinterSettings. Here’s a code snippet that demonstrates how to set the paper source correctly:
// Create printer and page settings
Aspose.Pdf.Printing.PrinterSettings ps = new Aspose.Pdf.Printing.PrinterSettings();
Aspose.Pdf.Printing.PageSettings pgs = new Aspose.Pdf.Printing.PageSettings();
// Set printer name
ps.PrinterName = deviceName;
// Set paper size and source
pgs.PaperSize = new Aspose.Pdf.Printing.PaperSize("A4", 827, 1169); // Example for A4 size
pgs.PaperSource = GetPaperSource(ps, "Tray 1"); // Custom method to get the paper source
// Print document
viewer.PrintDocumentWithSettings(pgs, ps);
Custom Method for Paper Source: You may need a method to retrieve the correct paper source based on the printer settings. Here’s an example of how you might implement this:
private static Aspose.Pdf.Printing.PaperSource GetPaperSource(Aspose.Pdf.Printing.PrinterSettings printerSettings, string trayName)
{
foreach (var source in printerSettings.PaperSources)
{
if (source.SourceName.Equals(trayName, StringComparison.OrdinalIgnoreCase))
{
return source;
}
}
throw new NotSupportedException($"Paper source '{trayName}' not found.");
}
Testing with Different Versions: If the issue persists, consider testing with different versions of Aspose.Pdf to see if the problem is specific to the version you are currently using.
If you continue to face issues, it may be helpful to check the Aspose documentation or community forums for any updates or similar issues reported by other users.