Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint PDF without print dialog in asp.net
    primarykey
    data
    text
    <p>I have a button in ASP.NET that when its clicked it gets a rdlc file and generates a PDF file with a print dialog screen. What I want is to print it directly without the print dialog, I know it can be done with Javascript but I dont have any idea how to do this in javascript.</p> <pre><code> &lt;iframe id="frmPrint" name="IframeName" width="500" height="200" runat="server" style="display: none"&gt;&lt;/iframe&gt; </code></pre> <p>Code in aspx.cs</p> <pre><code>public void PrintTicket() { string[] streamids; string reportType = "PDF"; string mimeType; string encoding; //string fileNameExtension = "pdf"; string extension; LocalReport report = new LocalReport(); //Displays ticket letter and number in ticket report.ReportPath = "PrintTicket.rdlc"; ReportParameter ticket_parameter = new ReportParameter(); ticket_parameter.Name = "Ticket"; ticket_parameter.Values.Add(TicketNo); report.SetParameters(new ReportParameter[] { ticket_parameter }); //Displays date and time in ticket ReportParameter date = new ReportParameter(); date.Name = "Date_Time"; date.Values.Add(System.DateTime.Now.ToString()); report.SetParameters(new ReportParameter[] { date }); //Displays branch location in ticket ReportParameter location_parameter = new ReportParameter(); location_parameter.Name = "Location"; location_parameter.Values.Add(location); report.SetParameters(new ReportParameter[] { location_parameter }); string deviceInfo = "&lt;DeviceInfo&gt;" + " &lt;OutputFormat&gt;EMF&lt;/OutputFormat&gt;" + " &lt;PageWidth&gt;8.5in&lt;/PageWidth&gt;" + " &lt;PageHeight&gt;11in&lt;/PageHeight&gt;" + " &lt;MarginTop&gt;0.10in&lt;/MarginTop&gt;" + " &lt;MarginLeft&gt;0.02in&lt;/MarginLeft&gt;" + " &lt;MarginRight&gt;0.25in&lt;/MarginRight&gt;" + " &lt;MarginBottom&gt;0.15in&lt;/MarginBottom&gt;" + "&lt;/DeviceInfo&gt;"; Warning[] warnings; byte[] bytes = report.Render("PDF", deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings); FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("output2.pdf"), FileMode.Create); fs.Write(bytes, 0, bytes.Length); fs.Close(); //Open existing PDF Document document = new Document(PageSize.LETTER); PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("output2.pdf")); //Getting a instance of new PDF writer PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Server.MapPath("Print.pdf"), FileMode.Create)); document.Open(); PdfContentByte cb = writer.DirectContent; int i = 0; int p = 0; int n = reader.NumberOfPages; iTextSharp.text.Rectangle psize = reader.GetPageSize(1); float width = psize.Width; float height = psize.Height; //Add Page to new document while (i &lt; n) { document.NewPage(); p++; i++; PdfImportedPage page1 = writer.GetImportedPage(reader, i); cb.AddTemplate(page1, 0, 0); } //Attach javascript to the document PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer); writer.AddJavaScript(jAction); document.Close(); //Attach pdf to the iframe frmPrint.Attributes["src"] = "Print.pdf"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload