Print PDF client side ASP.Net Web Application 3.5

Hi,


We are using following code to Print PDF. Although this code works perfectly fine on local machine but when deploy this code to server it is not working.
Working with PDF printing - Facades|Aspose.PDF for .NET


Our requirement:
1: Generate new PDF based on existing template (Working with AcroForms|Aspose.PDF for .NET)
2: Print the generated PDF on Client machine. The client should see the Print Dialog box and be able to print the PDF.

P.S: The new PDF is in memory stream

Can you please advise.


Hi there,


Thanks for your inquiry. Please check sample code for printing PDF document from memory stream using print dialogue. Hopefully it will help you to accomplish the task.

FileStream fs = new
FileStream(myDir + “HelloWorld.pdf”,
FileMode.Open, FileAccess.Read);<o:p></o:p>

byte[] tmpBytes = new byte[fs.Length];

fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));

MemoryStream mystream = new MemoryStream(tmpBytes);

MyStream myStream = new MyStream(mystream);

PdfViewer viewer = new PdfViewer();

viewer.BindPdf(mystream);

viewer.PrintAsImage = true;

viewer.AutoResize = false;

// viewer.Resolution = 600;

viewer.AutoRotate = false;

//viewer.PrintPageDialog = true;

System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();

if (printDialog.ShowDialog() == System.Windows.Forms.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);

pgs.Landscape = true;

// ps.PrinterName = "Adobe PDF";

// ps.PrintToFile = true;

// ps.PrintFileName = myDir + "testoutprint.pdf";

viewer.PrintDocumentWithSettings(pgs, ps);

}

viewer.Close();

Please feel free to contact us for any further assistance.


Best Regards,

Hi,


Thanks for the reply.

But the solution you provided do not solve our problem of printing the PDF.

The namespace System.Windows.Forms is not supported on IIS hosted Web Application, therefore it throws error as it tries to find default printer of server, which is not configured.

We need to show Print Dialog to user and use client machine printer not the server network attached printer.

Hope to find a solution soon.

P.S: We are using Aspose in Public facing website, so user can access this site from anywhere, and it should look for local printer of user.

Hi there,


Thanks for your feedback. 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’ll 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 pereferences) 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

Best Regards