Saturday, 19 October 2019

How to get Client PC Printer name in network

 How to get Client PC Printer name in network


Following is a code sample for Microsoft report. You have to find the way to export CR to pdf. this will not be hard. i have metioned which line be replaced. Also you need to download ItextSharp.dll. you can find from google.
Add following frame to html markup
<iframe id="frmPrint" name="IframeName" width="500" height="200" runat="server" style="display: none" runat="server"></iframe>
</form>
refer following libraries

using System.Collections.Generic;
using System.Text;
using System.Web;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
Add below code in a button click or page load,
                Warning[] warnings;
                string[] streamids;
                string mimeType;
                string encoding;
                string extension;
//// remove the below line and replace crystal report export pdf funciton, coz following line intended to microsoft report, what is happening here report is render as pdf to byte array
                byte[] bytes = View.ReportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
////
                FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("output.pdf"), FileMode.Create);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();

                //Open exsisting pdf
                Document document = new Document(PageSize.LETTER);
                PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("output.pdf"));

                //Getting a instance of new pdf wrtiter
                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;
                Rectangle psize = reader.GetPageSize(1);
                float width = psize.Width;
                float height = psize.Height;

                //Add Page to new document

                while (i < 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";
Hope this will help.

No comments:

Post a Comment