Hello!
I am using the code below to print PDF documents with different sizes. This code works fine with many printers, but I also have printers that don't work. If i am trying to print a legal PDF in one of these printers, then the printer thinks the papersize is A4 instead of legal format. That means it stops printing where the smaller A4 paper ends. So the printout is missing at the bottom of the legal paper.
Opening and printing the PDF with Adobe Reader works fine without tweaking the settings of the printer.
Can you help me?
Thanks, Martin
---------------------------------------------
private void PrintDocument()
{
//Set Printer
//Falls der Printer den Wert String.Empty hat, wird der Standarddrucker genommen
if (_printerName != String.Empty) _pdfDocument.PrintSettings.PrinterName = _printerName;
//Set Paper source
//Dieser Delegate wird bei jeder Seite aufgerufen, um die Papierquelle für jedes Dokument einzeln zu bestimmen
_pdfDocument.PrintSettings.PaperSettings += delegate(object sender, PdfPaperSettingsEventArgs e)
{
e.CurrentPaperSource = CreatePaperSourceFromName(GetPhysicalTray(_printerName,_pageMetaData[e.CurrentPaper - 1].Tray), e.PaperSources);
};
//Print the document
//Manually set the paper size to legal if needed
if (_pdfDocument.Pages.Count > 0 && _pdfDocument.Pages[0].Size.Width == 612 &&
_pdfDocument.Pages[0].Size.Height == 1008)
{
_pdfDocument.PrintSettings.PaperSize = PdfPaperSizes.Legal;
}
else if (_pdfDocument.Pages.Count > 0 && _pdfDocument.Pages[0].Size.Width == 842 &&
_pdfDocument.Pages[0].Size.Height == 1190)
{
_pdfDocument.PrintSettings.PaperSize = PdfPaperSizes.A3;
}
else
{
_pdfDocument.PrintSettings.PaperSize = PdfPaperSizes.A4;
}
_pdfDocument.PrintSettings.SelectSinglePageLayout(PdfSinglePageScalingMode.ActualSize);
_pdfDocument.PrintSettings.SelectPageRange(_fromPage, _toPage);
_pdfDocument.PrintSettings.Duplex = _duplex;
_pdfDocument.PrintSettings.PrintController = new StandardPrintController();
try
{
for (int i = 0; i < _copies; i++)
{
_pdfDocument.Print();
}
}
catch (Exception e)
{
log.Error("Fehler beim Drucken", e);
}
}