Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Dec 04, 2019 10:46 am

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);
}
}

mconstam
 
Posts: 5
Joined: Thu May 03, 2018 1:58 pm

Thu Dec 05, 2019 3:53 am

Hi,

Thanks for your inquiry.
To help us investigate your issue accurately, please offer us the following information.
1. Your input Pdf files.
2. The information of your printer.
3. The OS and Region information, e.g. Win7, 64bit, China/Chinese.

You could upload them here or send us([email protected]) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Dec 17, 2019 10:30 am

Hi,

1. I have attached the PDF File to this post.
2. The printer model is a HP Laserjet pro M404dn. If I use the recommended driver from HP for M404-M405 Model (Driver Version 8.00.1329.6536) then I have problems with printing legal format. The printer insists on the format A4 and cuts the print on the end of the page.

As soon as I switch to the HP Universal Printing PCL 6 Driver (Version 61.186.1.20636) everything works fine.

My OS is Windows 10 1903, 64Bit, english langage.

Thanks.

Martin

mconstam
 
Posts: 5
Joined: Thu May 03, 2018 1:58 pm

Wed Dec 18, 2019 10:37 am

Hi,

Thanks for your information.
We will do further investigate and update you ASAP.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Dec 19, 2019 2:09 am

Hi Martin,

Hope you are doing well.
I did notice the issue with our printer HP LaserJet P1007, and I have logged it into our bug tracking system. Once there is any progress, we will inform you.
Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Thu Dec 19, 2019 7:37 am

HI Amber, hi Betsy,

thank you very much. Glad you can reproduce the error.

Kind regards,
Martin

mconstam
 
Posts: 5
Joined: Thu May 03, 2018 1:58 pm

Thu Dec 19, 2019 7:51 am

Hi Martin,

Thanks for your reply.
Once there is any progress about this issue, we will inform you ASAP. Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Dec 25, 2019 10:07 am

Hi Martin,

Hope you are doing well.
After further investigation, we found the following code could solve your issue. Please have a try.
Code: Select all
            if (doc.Pages.Count > 0 && doc.Pages[0].Size.Width == 612 && doc.Pages[0].Size.Height == 1008)
            {
                //Get the paper size from PrintDocument object first, then set the value to your page when print.
                int rawKind = (int)PaperKind.Legal;
                PrintDocument pd = new PrintDocument();
                foreach (PaperSize ps in pd.PrinterSettings.PaperSizes)
                {
                    if (ps.RawKind == rawKind)
                    {
                        doc.PrintSettings.PaperSize = ps;
                        break;
                    }
                }
            }

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Jan 14, 2020 2:01 pm

This was the solution. Thank you very much!

Cheers, Martin

mconstam
 
Posts: 5
Joined: Thu May 03, 2018 1:58 pm

Wed Jan 15, 2020 1:11 am

Hi,

Thanks for your feedback.
Any question, welcome to contact us. Have a nice day.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.PDF