This is a migrated thread and some comments may be shown as answers.

Print PDF via code not using printer driver defaults

9 Answers 729 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 22 Jun 2020, 05:55 PM

Hi

I am trying to print a PDF containing logos and barcodes.

I am using a Zebra PAX label printing using thermal transfer ribbon, so within its printer driver settings I have set the label size and the Graphics Dithering setting to NONE to ensure pure B&W printing.

Printing the PDF through Adobe takes note of the driver settings and prints perfectly.

Using the code below, the logo are "greyscaled" and the label doesn't fill the label, i.e. doesn't take note of the printer driver settings.

Any ideas?

private void btnPrint_Click(object sender, RoutedEventArgs e)
 {
     PrintSettings printSettings = new PrintSettings()
     {
           DocumentName = "pdfLabel",
           UseDefaultPrinter = false
     };
 
     PrintDialog p = new PrintDialog();
     PrintQueue q = FindPrintQueueByName("ZebraPAX");
     if (q == null)
     {
            q = p.PrintQueue;
     }
 
      p.PrintQueue = q;
      p.MinPage = 1;
      p.MaxPage = 1;
 
      this.pdfViewer.Print(p, printSettings);
}
 
private PrintQueue FindPrintQueueByName(string name)
{
      PrintServer server = new PrintServer();
        
       foreach (PrintQueue queue in server.GetPrintQueues(new EnumeratedPrintQueueTypes[] {
            EnumeratedPrintQueueTypes.Connections, EnumeratedPrintQueueTypes.Local }))
       {
                if (queue.Name == name)
                {
                    return queue;
                }
       }
 
       return null;

}

9 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 23 Jun 2020, 11:02 AM

** UPDATE **

Re-installed driver - still the same.

Printed to a laserjet, still ignores the printer driver options.

Is this a bug?

0
Nikolay Demirev
Telerik team
answered on 25 Jun 2020, 10:41 AM

Hello Andrew,

The PdfViewer printing implementation doesn't take care of the colors while printing. It uses the WPF API for printing which takes Visual and page size, which we get from the print dialog. We are passing a Visual with all the UI elements we have in the UI of the RadPdfViewer with the same colors as in the UI. We only make sure the page size and margins are correct. The WPF has its own way of respecting the printer settings for the color and we don't have control over it.

If the page you print does not fit your label, please check the size of the label in the Print dialog, because our code gets if from there, arranges the page and passes it to the WPF API.

Please let me know what is the size of your print paper, so I can test it on our end. 

If your 

Regards,
Nikolay Demirev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Andrew
Top achievements
Rank 1
answered on 25 Jun 2020, 11:00 AM

Hi Nikolay

The print size is not a big problem.

The main problem is the logo and the barcodes as you can see in the photo attached (telerik.png).

As a work around i'm kicking of a Process (AcroRd32.exe) and printing it silently through that, much better result (adobe.png)

Ideally i would like to keep everything in Telerik, can I load the PDF into a report viewer???

Many Thanks 

Andy

0
Andrew
Top achievements
Rank 1
answered on 25 Jun 2020, 11:07 AM

Hi Nikolay

Just had a thought, you say it's the WPF way of handling the printing.Would the PDF viewer in Winforms use the printer driver settings or Blazor / Asp.NET etc???

Kind Regards

Andy

 

0
Dimitar
Telerik team
answered on 26 Jun 2020, 09:10 AM

Hello Andrew,

Although the API used in WinForms is a bit different the .Net Framework is still responsible for the printing. In addition, I do not think that in both cases the printer settings can be avoided. I believe that Adobe Acrobat may scale the document a bit and this is what can cause the difference. Can you try this by printing with a 100% in Adobe and see if there is still a difference (see attached)? 

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Andrew
Top achievements
Rank 1
answered on 26 Jun 2020, 09:32 AM

Hi Dimitar
The most important issue to us and our customer is the quality of the barcodes and logos.
As you can see in my 2 attached photos from my previous post,  the barcodes are unreadable when printing via the PDF viewer, where printing via and Adobe process results in a perfect barcode which is readable.

We'll still use the viewer to display the PDF, but I think we'll go along the Adobe process route to print them.

Thanks for quick responses and help.

Kind Regards

Andy

0
Dimitar
Telerik team
answered on 26 Jun 2020, 10:05 AM

Hi Andrew,

I have prepared a small Winforms application that you can use to print your PDF file. Can you test this with it and see if there is a difference? You can change the paper type in the code depending on the exact size. 

Thank you in advance for your patience and cooperation. I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Andrew
Top achievements
Rank 1
answered on 01 Jul 2020, 01:43 PM

Hi Dimitar

Apologies for the delay in getting back but I had other work commitments.

Yes, your WinForms app worked, it printed the barcode successfully ( the height was reduced for same reason though?) and the graphics printed fine, through the printer driver?

 

How does the WinForms differ from the WPF then for printing?

Many Thanks

Andy

0
Dimitar
Telerik team
answered on 02 Jul 2020, 08:29 AM

Hi Andrew,

Although both are .NET Desktop platforms they are indeed different. In this case, the printing API provided for WinForms and WPF is completely different. I am not sure why Microsoft decided this but there is not much we can do about that.

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
PDFViewer
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Nikolay Demirev
Telerik team
Dimitar
Telerik team
Share this question
or