We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose PDF Print Not Working

Hello,


We have the following code for opening a Print dialog and allowing the user to Print the PDF file. But, on button click, nothing is happening. Kindly advice what could be wrong.

Thanks.

Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
viewer.BindPdf(“C:\Test\Test.pdf”);
viewer.AutoResize = true;
viewer.Resolution = 600;
viewer.AutoRotate = true;
viewer.PrintPageDialog = true;
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == DialogResult.OK)
{
System.Drawing.Printing.PrinterSettings ps = printDialog.PrinterSettings;
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
pgs.PaperSize = new System.Drawing.Printing.PaperSize(“A4”, 827, 1169);
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
viewer.PrintDocumentWithSettings(pgs, ps);
}
viewer.Close();

Hi Raman,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for Java 17.4.0 and have managed to print the PDF file correctly. I will appreciate if you please share your sample PDF file along with your environment details. It will help to reproduce the problem and address it accordingly.

We are sorry for the inconvenience.

Best Regards,

Hi,


This is ASPOSE PDF.NET. Version 17.1.00. Windows 7 Ultimate, 64 Bit, Chrome Browser 57.0.

I have attached a sample solution. On Print, it automatically chooses default Printer. Is it possible to show a Print dialog and then allow the user to select Printer and then Print? I have commented out those lines in the code now.

(I have not included the Aspose.dll in the solution)


Hi Raman,


Thanks for sharing further details.

Yes, you can show a Print dialog and then allow the user to select the Printer by uncommenting the following lines of code.

C#

if (printDialog.ShowDialog() == DialogResult.OK)

I have tested the code using Aspose.Pdf for .NET 17.4.0 Windows 10 and it is working perfect. Please give me some time to test the same in Windows 7 and then I will get back to you with my findings.

We are sorry for this inconvenience.

Best Regards,

Hi Fahad,


If I uncomment those lines. nothing is happening. Currently ‘Print’ is not working in any browser (IE, Chrome, FF) on Windows 7 machine.

Is the ‘SamplePrint’ application I attached earlier working for you?

Hello Raman,


We are checking details in the environment, specified above and will get back to you shortly.


Best Regards,

Hello Raman,


Thanks for your patience.

I have tested the sample application which was shared above on Windows 7 Ultimate 64-bit operating system using Aspose.Pdf 17.4.0 and did not notice any issue. The print dialog was appeared and list of all installed printer was also there in the dialog to select. I have attached a screenshot for your reference.

I would also like to share with you that print dialog was showed up behind the chrome window and I had to use Alt + Tab keys to view it. May be same thing is happening at your side, that is why you were not able to notice the print dialog. Please try with latest version of the API as it is highly recommended and in a case you still face any issue please feel free to contact us.


Best Regards,

Do you have Aspose.Fonts.DLL on the computer that where you can make it work. When I try to print or render a PDF with Aspose.PDF.DLL version greater than 12.0 it fails with a message that it can’t load Aspose.Fonts.DLL. What is this Aspose.Fonts.DLL.

Hi Asad,


Thanks for the prompt reply.

Looks like the ‘Print’ dialog is opening behind the browser. Unless the user minimizes the browser window to desktop view, Print dialog is not visible.

Is there anyway to show the ‘Print’ dialog on top of the current browser window? Behavior right now is not user friendly.

mcrose:
Do you have Aspose.Fonts.DLL on the computer that where you can make it work. When I try to print or render a PDF with Aspose.PDF.DLL version greater than 12.0 it fails with a message that it can’t load Aspose.Fonts.DLL. What is this Aspose.Fonts.DLL.
Hi Matthew,

Thanks for contacting support.

The above stated problem is a known issue and we are working on fixing it. However currently there are two workarounds for this problem.

1.Do not use assembly.GetTypes(), use assembly.GetExportedTypes() instead.

System.Reflection.Assembly
assembly = System.Reflection.Assembly.LoadFrom(@“d:\MyApp\References\Aspose.Pdf.dll”);

var types =
assembly.GetExportedTypes(); // <-- it works fine
now and returns all public exported non-obfuscated classes.


2. Call assembly.CreateInstance(“Aspose.Pdf.Document”); after LoadFrom(), before GetTypes(). Something like this:

System.Reflection.Assembly
assembly = System.Reflection.Assembly.LoadFrom(@“d:\MyApp\References\Aspose.Pdf.dll”);

assembly.CreateInstance(“Aspose.Pdf.Document”);

var types =
assembly.GetTypes(); // <-- it works fine now.


The problem is logged in our issue tracking system as PDFNET-42609 and the product team is working on fixing this problem and we hope to get it resolved in next release versions of Aspose.Pdf for .NET. Please be patient and spare us little time.

Hi Raman,


Thanks for writing back.

rnidamar:
Looks like the ‘Print’ dialog is opening behind the browser. Unless the user minimizes the browser window to desktop view, Print dialog is not visible.

Is there anyway to show the ‘Print’ dialog on top of the current browser window? Behavior right now is not user friendly.

The reason of this behavior is, you are using Windows Form based print dialog in a Web Application and when it shows up, it cannot find its parent window due to web application and goes behind the browser. To make it on top most please check following work around where I create a Windows Form instance in web application and assign it to PrintDialog, so that dialog can be appeared above the browser.

Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();<o:p></o:p>

string filePath = System.Web.HttpContext.Current.Server.MapPath("Test.pdf");

viewer.BindPdf(filePath);

viewer.AutoResize = true;

viewer.Resolution = 600;

viewer.AutoRotate = true;

viewer.PrintPageDialog = true;

PrintDialog printDialog = new PrintDialog();

System.Windows.Forms.Form current = new System.Windows.Forms.Form();

current.Show();

current.Activate();

current.TopMost = true;

current.Focus();

current.Visible = false;

if (printDialog.ShowDialog(current) == DialogResult.OK)

{

current.Close();

System.Drawing.Printing.PrinterSettings ps = printDialog.PrinterSettings;

System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();

pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

viewer.PrintDocumentWithSettings(pgs, ps);

}

viewer.Close();


In case of any further assistance, please feel free to let us know.


Best Regards,

Thanks a lot Asad.

Hi Raman,


Thanks for the acknowledgement.

We are glad to hear that your problem is resolved. Please continue using our API and in the event of any further query, please feel free to contact.

Hi,


The Print dialog works fine on my local machine. When I deploy code to our Staging server, it does not work there. Nothing happens on ‘Print’ button.

Any configuration/permission/tweaks need to be done on the remote server after deployment?

Hi Raman,


Thanks for sharing the details.

As per my understanding, you need to print the document using printer installed on staging server or the machine on which you access the application/page.
Please note printers are usually installed on user’s profile (especially if it’s a network printer, not a physically connected one such as on USB or parallel cable). When Administrator sees a printer it doesn’t necessarily mean they will be available when other user is logging on the same machine. ASP.NET applications runs as ApplicationPoolIdentity or NerworkService credential by default so the web application is unlikely to see the printers there.

There are two solutions:

1) Create an account for .NET application pool to run on, and then login as that user on the server and add the printers there

2) Run on web site under Custom account (Identity property in site’s preferences) that is already able to work with printers.


More information about application pool usage - http://www.iis.net/learn/manage/configuring-security/application-pool-identities

Hi,


I want to make sure I am understanding this. We have deployed the following code to remote server.

----------------------------------------------------------------------------------------------
Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
viewer.BindPdf(“Test.pdf”);
viewer.AutoResize = true;
viewer.Resolution = 600;
viewer.AutoRotate = true;
viewer.PrintPageDialog = true;

PrintDialog printDialog = new PrintDialog();
System.Windows.Forms.Form current = new System.Windows.Forms.Form();
current.Show();
current.Activate();
current.TopMost = true;
current.Focus();
current.Visible = false;

if (printDialog.ShowDialog(current) == DialogResult.OK)
{
System.Drawing.Printing.PrinterSettings ps = printDialog.PrinterSettings;
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
pgs.PaperSize = new System.Drawing.Printing.PaperSize(“A4”, 827, 1169);
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
viewer.PrintDocumentWithSettings(pgs, ps);
}

viewer.Close();

--------------------------------------------------------------------------------------------------------

When I run this code from local machine, I see the ‘Print’ dialog in browser and I can select my local printer.

I would like the same behavior when after we have deployed code to remote server (Staging site). When I browse to the page hosted on remote server. And I click ‘Print’, will the Print dialog not show-up my local printer?


Hi Raman,


Thanks for adding more details to the scenario.

rnidamar:
When I run this code from local machine, I see the ‘Print’ dialog in browser and I can select my local printer.

I would like the same behavior when after we have deployed code to remote server (Staging site). When I browse to the page hosted on remote server. And I click ‘Print’, will the Print dialog not show-up my local printer?

You see “Print Dialog” on the local machine because you are using Windows Form PrintDialog and in the case of local machine, the client and server are same machine due to which you are able to prompt dialog box. Whereas, when website go live on real web server, it does not support the desktop features and you would not see this behavior.

However, to show the print dialog box on the web server, you can convert PDF into images, render images in browser window and use classic JavaScript window.print() method. OR you can use a PDF Viewer, provided by our sister company, in your website to view PDF files and print them.

In case of any further assistance, please feel free to contact us. We are sorry for the inconvenience.


Best Regards,

Hi Raman,


Thanks for your patience.

We are pleased to share that the issue reported earlier as PDFNET-42609 is resolved in latest release of Aspose.Pdf for .NET 17.6. Please try using the latest release and in the event of any further query, please feel free to contact.