public bool Print()
        {
            if (this.pdfFile == null)
            {
                return(false);
            }

            PrintDialog printDialog = new PrintDialog();

            if (printDialog.ShowDialog(this) == DialogResult.OK)
            {
                PDFPrintSettings settings = new PDFPrintSettings()
                {
                    BitmapPrintResolution = 300,
                    AutoRotate            = true,
                    Columns              = 1,
                    Rows                 = 1,
                    PageScaling          = PageScaling.None,
                    DownscaleLargeImages = true,
                    PaperSize            = printDialog.PrinterSettings.DefaultPageSettings.PaperSize
                };
                this.pdfFile.Print(settings);
            }

            return(true);
        }
        public string SilentPrint(string Url, string PostData, string cookieStr, string printerParams, string charset)
        {
            string fileName = null;

            try {
                Stream stream = HttpUtils.SendRequest(Url, PostData, charset, cookieStr);

                //创建临时目录
                string temp = System.Environment.GetEnvironmentVariable("TEMP");
                fileName = Guid.NewGuid().ToString();
                fileName = temp + "\\" + fileName + ".pdf";
                saveFile(stream, fileName);

                //读取PDF文件
                if (PrintEngine.Equals("exe"))
                {
                    string exePath = Assembly.GetExecutingAssembly().Location;
                    string exeFile = new FileInfo(exePath).DirectoryName + "\\FR.exe";
                    // MessageBox.Show(exeFile);
                    Process          p         = new Process();
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.CreateNoWindow  = true;
                    startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                    startInfo.UseShellExecute = true;
                    startInfo.FileName        = exeFile;
                    //startInfo.Verb = "FR.exe";
                    string cmd = "/p  \"" + fileName + "\" \"" + GetPrinter() + "\"";

                    startInfo.Arguments = cmd;
                    p.StartInfo         = startInfo;
                    p.Start();
                    p.WaitForExit();
                }
                else
                {
                    PDFFile pdf = PDFFile.Open(fileName);
                    // Create a default printer settings to print on the default printer.
                    PrinterSettings  settings         = new PrinterSettings();
                    PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);
                    pdfPrintSettings.PageScaling = PageScaling.FitToPrinterMargins;
                    pdf.Print(pdfPrintSettings);
                    pdf.Dispose();
                }
            } catch (Exception ex) {
                return("{status:'error',msg:'" + ex.Message + "'}");
            } finally {
                try {
                    if (fileName != null)
                    {
                        new FileInfo(fileName).Delete();
                    }
                } catch (Exception ee) {
                }
            }
            return("{status:'success'}");
        }
Exemple #3
0
        private PDFPrintSettings PrinterSettings()
        {
            PrinterSettings settings = new PrinterSettings();

            //PrintDocument pd = new PrintDocument();
            settings.PrinterName = this.printName;
            settings.PrintToFile = false;

            //设置纸张大小(可以不设置,取默认设置)3.90 in,  8.65 in
            PaperSize ps = new PaperSize();

            //如果是自定义纸张,就要大于118,(A4值为9,详细纸张类型与值的对照请看http://msdn.microsoft.com/zh-tw/library/system.drawing.printing.papersize.rawkind(v=vs.85).aspx)
            ps.RawKind = this.rawKind;

            PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);

            pdfPrintSettings.PaperSize              = ps;
            pdfPrintSettings.PageScaling            = PageScaling.FitToPrinterMarginsProportional;
            pdfPrintSettings.PrinterSettings.Copies = 1;

            return(pdfPrintSettings);
        }
Exemple #4
0
        void PrintPDF(string pdfPath, int copies)
        {
            PDFFile         file    = PDFFile.Open(pdfPath);
            PrinterSettings setting = new PrinterSettings();
            PrintDocument   pd      = new PrintDocument();

            setting.PrinterName = "FUJI XEROX DocuCentre S2110";
            setting.Duplex      = Duplex.Vertical;
            setting.PrintToFile = false;
            setting.Copies      = (short)copies;
            setting.Collate     = true;
            PDFPrintSettings pdfps = new PDFPrintSettings(setting);

            try
            {
                file.Print(pdfps);
            }
            finally
            {
                file.Dispose();
            }
        }
Exemple #5
0
        ///// <summary>
        ///// 将字符串发送到打印机方法
        ///// </summary>
        ///// <param name="szPrinterName">打印机名称</param>
        ///// <param name="szString">打印的字符串</param>
        ///// <returns></returns>
        //public static bool SendStringToPrinter(string szPrinterName, string szString)
        //{
        //    bool flag = false;
        //    try
        //    {
        //        IntPtr pBytes;
        //        Int32 dwCount;

        //        // 获取字符串长度
        //        dwCount = szString.Length;

        //        // 将字符串复制到非托管 COM 任务分配的内存非托管内存块,并转换为 ANSI 文本
        //        pBytes = Marshal.StringToCoTaskMemAnsi(szString);

        //        // 将已转换的 ANSI 字符串发送到打印机
        //        flag = SendBytesToPrinter(szPrinterName, pBytes, dwCount);

        //        // 释放先前分配的非托管内存
        //        Marshal.FreeCoTaskMem(pBytes);
        //    }
        //    catch (Win32Exception ex)
        //    {
        //        Helper.WriteLog(ex.Message);
        //        flag = false;
        //    }
        //    return flag;
        //}


        /// <summary>
        /// PDFRender4Net打印pdf
        /// </summary>
        /// <param name="filePath">pdf文件路径</param>
        /// <param name="printerName">打印机名称</param>
        /// <param name="paper">纸张大小</param>
        /// <param name="isVertical">是否竖打</param>
        /// <param name="copies">份数</param>
        public static string UsePDFRender4NetToPrintPdf(string filePath, string printerName, PaperSize paper, bool isVertical, int copies)
        {
            string errorStr = "";

            if (!File.Exists(filePath))
            {
                errorStr += "打印的文件不存在\r\n";
                return(errorStr);
            }

            PDFFile         file     = PDFFile.Open(filePath);
            PrinterSettings settings = new PrinterSettings();

            settings.PrinterName = printerName;
            settings.PrintToFile = false;
            settings.DefaultPageSettings.Landscape = !isVertical;

            PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);

            pdfPrintSettings.PaperSize              = paper;
            pdfPrintSettings.PageScaling            = PageScaling.FitToPrinterMarginsProportional;
            pdfPrintSettings.PrinterSettings.Copies = (short)copies;

            try
            {
                file.Print(pdfPrintSettings);
            }
            catch (Exception ex)
            {
                errorStr = ex.Message;
                Helper.WriteLog(ex.Message);
            }
            finally
            {
                file.Dispose();
            }
            return(errorStr);
        }
        private void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            // Load the PDF file.
            PDFFile file = PDFFile.Open(this.pdfViewer.Source);

            file.SerialNumber = "PDFVW-6ATTA-DK6XD-A2XTO-AIQUM-3ECYE";
            // Create a default printer settings to print on the default printer.
            PrinterSettings  settings         = new PrinterSettings();
            PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);

            pdfPrintSettings.PageScaling = PageScaling.FitToPrinterMargins;

            // Create the print dialog object and set options
            PrintDialog pDialog = new PrintDialog();

            pDialog.PageRangeSelection   = PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled = true;

            // Display the dialog. This returns true if the user presses the Print button.
            Nullable <Boolean> print = pDialog.ShowDialog();

            if (print == true)
            {
                // Get the settings from the PrintDialog and manually set each one.
                // If there are more option that need to be set the we need to identify them and set them manually.

                pdfPrintSettings.PrinterSettings.PrinterName = pDialog.PrintQueue.FullName;

                pdfPrintSettings.PrinterSettings.Copies   = (short)pDialog.PrintTicket.CopyCount;
                pdfPrintSettings.PrinterSettings.FromPage = pDialog.PageRange.PageFrom;
                pdfPrintSettings.PrinterSettings.ToPage   = pDialog.PageRange.PageTo;

                // Print the PDF file.
                file.Print(pdfPrintSettings);
            }

            file.Dispose();
        }
Exemple #7
0
        private void CreatePDF(string hphm, string vin, string business, string carType, string chekItem, string weight, string makeDate, byte[] qrcode)
        {
            PdfHelper    pdfHelper    = new PdfHelper();
            Document     doc          = pdfHelper.CreateDocument(500, 500);
            MemoryStream memoryStream = new MemoryStream();
            PdfWriter    writer       = PdfWriter.GetInstance(doc, memoryStream);

            doc.Open();
            doc.NewPage();

            BaseFont ArialFont = BaseFont.CreateFont("STZHONGS.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            iTextSharp.text.Font BoldFont = new iTextSharp.text.Font(ArialFont, 11, iTextSharp.text.Font.NORMAL, new BaseColor(System.Drawing.Color.Black));
            iTextSharp.text.Font HeadFont = new iTextSharp.text.Font(ArialFont, 11, iTextSharp.text.Font.BOLD, new BaseColor(System.Drawing.Color.Red));
            PdfPTable            tableVIN = pdfHelper.CreateTable(new float[] { 1, 1, 1, 1, 1 }, doc);

            tableVIN.AddCell(pdfHelper.CreateCell("号牌号码", BoldFont, Element.ALIGN_RIGHT));
            tableVIN.AddCell(pdfHelper.CreateCell(hphm, HeadFont, Element.ALIGN_CENTER));
            tableVIN.AddCell(pdfHelper.CreateCell("VIN", BoldFont, Element.ALIGN_RIGHT));
            tableVIN.AddCell(pdfHelper.CreateCell(vin, HeadFont, Element.ALIGN_CENTER, 2));
            doc.Add(tableVIN);

            PdfPTable tableMsg = pdfHelper.CreateTable(new float[] { 1, 1, 1, 1 }, doc);

            tableMsg.AddCell(pdfHelper.CreateCell("业务类型", BoldFont, Element.ALIGN_RIGHT));
            tableMsg.AddCell(pdfHelper.CreateCell(business, BoldFont, Element.ALIGN_CENTER));
            tableMsg.AddCell(pdfHelper.CreateCell("车辆类型", BoldFont, Element.ALIGN_RIGHT));
            tableMsg.AddCell(pdfHelper.CreateCell(carType, BoldFont, Element.ALIGN_CENTER));
            tableMsg.AddCell(pdfHelper.CreateCell("检测项目", BoldFont, Element.ALIGN_RIGHT));
            tableMsg.AddCell(pdfHelper.CreateCell(chekItem, BoldFont, Element.ALIGN_CENTER));
            tableMsg.AddCell(pdfHelper.CreateCell("总质量", BoldFont, Element.ALIGN_RIGHT));
            tableMsg.AddCell(pdfHelper.CreateCell(weight, BoldFont, Element.ALIGN_CENTER));
            tableMsg.AddCell(pdfHelper.CreateCell("环保登记", BoldFont, Element.ALIGN_RIGHT));
            tableMsg.AddCell(pdfHelper.CreateCell("", BoldFont, Element.ALIGN_CENTER));
            tableMsg.AddCell(pdfHelper.CreateCell("出厂日期", BoldFont, Element.ALIGN_RIGHT));
            tableMsg.AddCell(pdfHelper.CreateCell(makeDate, BoldFont, Element.ALIGN_CENTER));

            PdfPCell qrCell = null;

            if (qrcode != null)
            {
                qrCell = new PdfPCell(pdfHelper.CreateImage(qrcode, 100f, 100f));
            }
            else
            {
                qrCell = pdfHelper.CreateCell("", BoldFont, Element.ALIGN_CENTER);
            }
            //qrCell.Rowspan = 3;
            qrCell.Padding = 2;
            tableMsg.AddCell(qrCell);
            //tableMsg.AddCell(pdfHelper.CreateCell(" ", BoldFont, Element.ALIGN_LEFT, false, 3, false));
            //tableMsg.AddCell(pdfHelper.CreateCell("Admin", BoldFont, Element.ALIGN_LEFT,false,3,false));
            tableMsg.AddCell(pdfHelper.CreateCell("Admin\r\n\r\n" + DateTime.Now.ToString("yyyy年MM月dd日  HH:mm:ss"), BoldFont, Element.ALIGN_LEFT, false, 3, false));

            doc.Add(tableMsg);
            doc.Close();
            MemoryStream pdf     = new MemoryStream(memoryStream.ToArray());
            PDFFile      pdfFile = PDFFile.Open(pdf);
            //Bitmap pageImage  = pdfFile.GetPageImage(0,56 * (int)PdfHelper.Definition.Six);

            PrinterSettings settings = new PrinterSettings();
            PrintDocument   pd       = new PrintDocument();

            settings.PrinterName = "Adobe PDF";
            settings.PrintToFile = false;

            //设置纸张大小(可以不设置,取默认设置)3.90 in,  8.65 in
            //PaperSize ps = new PaperSize("test", 4, 9);
            // ps.RawKind = 9; //如果是自定义纸张,就要大于118,(A4值为9,详细纸张类型与值的对照请看http://msdn.microsoft.com/zh-tw/library/system.drawing.printing.papersize.rawkind(v=vs.85).aspx)

            PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);

            //pdfPrintSettings.PaperSize = ps;
            pdfPrintSettings.PageScaling            = O2S.Components.PDFRender4NET.Printing.PageScaling.MultiplePagesPerSheetProportional;
            pdfPrintSettings.PrinterSettings.Copies = 1;
            pdfFile.Print(pdfPrintSettings);

            // MemoryStream pic = new MemoryStream();
            //pageImage.Save(pic, ImageFormat.Png);
            //pageImage.Save("测试.png", ImageFormat.Png);
            pdf.Close();
            pdf.Dispose();
            //pageImage.Dispose();
            pdfFile.Dispose();
            // picQRCode.BackgroundImage = System.Drawing.Image.FromStream(pic);
        }
Exemple #8
0
        private void CreatePDF(X18J52 x18J52, string hpzl, byte[] qrcode)
        {
            PdfHelper    pdfHelper    = new PdfHelper();
            Document     doc          = pdfHelper.CreateDocumentA4();
            MemoryStream memoryStream = new MemoryStream();
            PdfWriter    writer       = PdfWriter.GetInstance(doc, memoryStream);

            try
            {
                doc.Open();
                doc.NewPage();

                BaseFont             ArialFont = BaseFont.CreateFont("STZHONGS.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                iTextSharp.text.Font BoldFont  = new iTextSharp.text.Font(ArialFont, 11, iTextSharp.text.Font.NORMAL, new BaseColor(System.Drawing.Color.Black));

                //二维码
                iTextSharp.text.Image img = pdfHelper.CreateImage(qrcode, 100, 100f);
                img.SetAbsolutePosition(AppHelper.PointSetting.X_QRCode, AppHelper.PointSetting.Y_QRCode);
                doc.Add(img);

                PrintPoint     print = AppHelper.PointSetting;
                PdfContentByte pb    = writer.DirectContent;
                pb.BeginText();
                pb.SetFontAndSize(ArialFont, 9);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, DateTime.Now.ToString("yyyy"), print.X_Year, print.Y_Year, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, DateTime.Now.ToString("MM"), print.X_Month, print.Y_Month, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, DateTime.Now.ToString("dd"), print.X_Day, print.Y_Day, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.hphm, print.X_PlateNo, print.Y_PlateNo, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.syr, print.X_Owner, print.Y_Owner, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, hpzl, print.X_PlateType, print.Y_PlateType, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "", print.X_PlateColor, print.Y_PlateColor, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.cllx, print.X_CarType, print.Y_CarType, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.clpp1, print.X_CarBrand, print.Y_CarBrand, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.clxh, print.X_CarMold, print.Y_CarMold, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.ccdjrq, print.X_RegisterDate, print.Y_RegisterDate, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.ccrq, print.X_MakeDate, print.Y_MakeDate, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.zzl, print.X_Weight, print.Y_Weight, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, x18J52.zbzl, print.X_KerbWeight, print.Y_KerbWeight, 0);

                pb.EndText();

                doc.Close();
                MemoryStream pdf     = new MemoryStream(memoryStream.ToArray());
                PDFFile      pdfFile = PDFFile.Open(pdf);

                PrinterSettings settings = new PrinterSettings();
                PrintDocument   pd       = new PrintDocument();
                settings.PrinterName = AppHelper.AppSetting.PrinterName;
                settings.PrintToFile = false;

                PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);
                pdfPrintSettings.PageScaling            = PageScaling.MultiplePagesPerSheetProportional;
                pdfPrintSettings.PrinterSettings.Copies = 1;
                pdfFile.Print(pdfPrintSettings);
                pdf.Close();
                pdf.Dispose();
                pdfFile.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("打印异常" + ex.Message);
            }
            finally
            {
                memoryStream.Dispose();
                memoryStream.Close();
                writer.Dispose();
                doc.Dispose();
                doc.Close();
            }
        }
Exemple #9
0
        public void Print()
        {
            int width  = 200;
            int height = 297;

            if (details.Count > 3)
            {
                height += (details.Count - 3) * 30;
            }

            PdfHelper pdfHelper = new PdfHelper();
            Document  doc       = pdfHelper.CreateDocument(width, height);

            doc.SetMargins(10, 10, 10, 10);
            MemoryStream memoryStream = new MemoryStream();
            PdfWriter    writer       = PdfWriter.GetInstance(doc, memoryStream);

            doc.Open();
            doc.NewPage();
            doc.Add(_pdfHelper.CreateTitleParagraph("收费明细", NormalFont));

            PdfPTable table = _pdfHelper.CreateTable(new float[] { 4, 3, 3 }, doc);

            table.AddCell(_pdfHelper.CreateNoWidthCell($"车牌: {chargeRecord.PlateNo}", NormalFont, Element.ALIGN_LEFT, 3));
            table.AddCell(_pdfHelper.CreateNoWidthCell($"检测时间: {chargeRecord.DateOfTest}", NormalFont, Element.ALIGN_LEFT, 3));
            table.AddCell(_pdfHelper.CreateNoWidthCell($"收费时间: {chargeRecord.DateOfCharge}", NormalFont, Element.ALIGN_LEFT, 3));
            table.AddCell(_pdfHelper.CreateNoWidthCell($"收费人: {AppHelper.UserName}", NormalFont, Element.ALIGN_LEFT, 3));
            table.AddCell(_pdfHelper.CreateNoWidthCell("检验项目", NormalFont, Element.ALIGN_LEFT));
            table.AddCell(_pdfHelper.CreateNoWidthCell("次数", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateNoWidthCell("金额", NormalFont, Element.ALIGN_CENTER));

            foreach (var item in details)
            {
                table.AddCell(_pdfHelper.CreateNoWidthCell(item.TestItem, NormalFont, Element.ALIGN_LEFT));
                table.AddCell(_pdfHelper.CreateNoWidthCell(item.TestTimes.ToString(), NormalFont, Element.ALIGN_CENTER));
                table.AddCell(_pdfHelper.CreateNoWidthCell(item.Price.ToString(), NormalFont, Element.ALIGN_CENTER));
            }
            table.AddCell(_pdfHelper.CreateNoWidthCell($"合计: {chargeRecord.Price}", NormalFont, Element.ALIGN_RIGHT, 3));
            doc.Add(table);
            doc.Close();

            MemoryStream memoryStream1 = new MemoryStream(memoryStream.ToArray());

            O2S.Components.PDFRender4NET.PDFFile pdfFile = O2S.Components.PDFRender4NET.PDFFile.Open(memoryStream1);

            PrinterSettings settings = new PrinterSettings();
            PrintDocument   pd       = new PrintDocument();

            settings.PrinterName = AppHelper.AppSetting.PrinterName;
            settings.PrintToFile = false;
            PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);

            pdfPrintSettings.PageScaling            = PageScaling.MultiplePagesPerSheetProportional;
            pdfPrintSettings.PrinterSettings.Copies = 1;
            LogHelper.Trace("开始打印" + AppHelper.AppSetting.PrinterName);
            pdfFile.Print(pdfPrintSettings);
            LogHelper.Trace("打印完成" + AppHelper.AppSetting.PrinterName);

            memoryStream.Close();
            memoryStream.Dispose();
            memoryStream1.Close();
            memoryStream1.Dispose();
        }
Exemple #10
0
        public Bitmap CreatePDF()
        {
            Document     doc          = _pdfHelper.CreateDocumentA4(10, 10, 30, 10);
            MemoryStream memoryStream = new MemoryStream();
            PdfWriter    writer       = PdfWriter.GetInstance(doc, memoryStream);

            doc.Open();
            doc.NewPage();
            doc.Add(_pdfHelper.CreateTitleParagraph($"机动车牌证申请表", BoldFont));
            doc.Add(_pdfHelper.CreateTitleParagraph($" 排队票号:{_ticketNo}", NormalFont));

            PdfPCell  pdfPCell = null;
            PdfPTable table    = _pdfHelper.CreateTable(new float[] { 2, 3, 3, 3, 3, 3 }, doc);

            table.AddCell(_pdfHelper.CreateCell("申请人信息栏", NormalFont, Element.ALIGN_CENTER, 6));

            pdfPCell         = _pdfHelper.CreateCell("机动车所有人", NormalFont, Element.ALIGN_CENTER);
            pdfPCell.Rowspan = 3;
            table.AddCell(pdfPCell);

            table.AddCell(_pdfHelper.CreateCell("姓名/名称", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell(_carInfo?.Owner, NormalFont, Element.ALIGN_CENTER, 2));
            table.AddCell(_pdfHelper.CreateCell("邮政编码", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("100010", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("邮寄地址", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("", NormalFont, Element.ALIGN_CENTER, 4));
            table.AddCell(_pdfHelper.CreateCell("手机号码", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("", NormalFont, Element.ALIGN_CENTER, 2));
            table.AddCell(_pdfHelper.CreateCell("固定电话", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("", NormalFont, Element.ALIGN_CENTER));

            table.AddCell(_pdfHelper.CreateCell("代理人", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("姓名/名称", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("手机号码", NormalFont, Element.ALIGN_CENTER, 1));
            table.AddCell(_pdfHelper.CreateCell("", NormalFont, Element.ALIGN_CENTER, 2));
            table.AddCell(_pdfHelper.CreateCell("申请业务事项", NormalFont, Element.ALIGN_CENTER, 6));
            doc.Add(table);

            table = _pdfHelper.CreateTable(new float[] { 0.3F, 0.7F, 1, 1, 1, 1 }, doc);
            table.AddCell(_pdfHelper.CreateCell("号牌种类", NormalFont, Element.ALIGN_CENTER, 2));
            table.AddCell(_pdfHelper.CreateCell(AppHelper.GetNameByCode(_carInfo?.PlateType, "HPZL"), NormalFont, Element.ALIGN_CENTER, 2));
            table.AddCell(_pdfHelper.CreateCell("号牌号码", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell(_carInfo?.PlateNo, NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("申请事项", NormalFont, Element.ALIGN_CENTER, 2));
            table.AddCell(_pdfHelper.CreateCell("申请原因及声明", NormalFont, Element.ALIGN_CENTER, 4));

            PdfPTable table1;

            pdfPCell         = _pdfHelper.CreateCell("号牌", NormalFont, Element.ALIGN_CENTER);
            pdfPCell.Rowspan = 2;
            table.AddCell(pdfPCell);
            table.AddCell(_pdfHelper.CreateCell("□补领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("□丢失        □灭失         □前号牌          □后号牌 ", NormalFont, Element.ALIGN_LEFT, 4));

            table.AddCell(_pdfHelper.CreateCell("□换领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("□前号牌        □后号牌 ", NormalFont, Element.ALIGN_LEFT, 4));



            pdfPCell         = _pdfHelper.CreateCell("行驶证", NormalFont, Element.ALIGN_CENTER);
            pdfPCell.Rowspan = 2;
            table.AddCell(pdfPCell);

            table.AddCell(_pdfHelper.CreateCell("□补领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("□丢失        □灭失   ", NormalFont, Element.ALIGN_LEFT, 4));

            table.AddCell(_pdfHelper.CreateCell("□换领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell(" ", NormalFont, Element.ALIGN_CENTER, 4));

            pdfPCell         = _pdfHelper.CreateCell("登记证书", NormalFont, Element.ALIGN_CENTER);
            pdfPCell.Rowspan = 3;
            table.AddCell(pdfPCell);

            table.AddCell(_pdfHelper.CreateCell("□申领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("  ", NormalFont, Element.ALIGN_CENTER, 4));

            table.AddCell(_pdfHelper.CreateCell("□补领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("□丢失        □灭失        □未获得", NormalFont, Element.ALIGN_LEFT, 4));

            table.AddCell(_pdfHelper.CreateCell("□换领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("", NormalFont, Element.ALIGN_CENTER, 4));

            pdfPCell         = _pdfHelper.CreateCell("检验合格标志", NormalFont, Element.ALIGN_CENTER);
            pdfPCell.Rowspan = 3;
            table.AddCell(pdfPCell);

            table.AddCell(_pdfHelper.CreateCell("□申请", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("□在登记地车辆管理所申请        □在登记地以外车辆管理所申请 ", NormalFont, Element.ALIGN_LEFT, 4));

            table.AddCell(_pdfHelper.CreateCell("□补领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("□丢失        □灭失        ", NormalFont, Element.ALIGN_LEFT, 4));

            table.AddCell(_pdfHelper.CreateCell("□换领", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell(" ", NormalFont, Element.ALIGN_CENTER, 4));
            doc.Add(table);

            table = _pdfHelper.CreateTable(new float[] { 3, 3 }, doc);
            table.AddCell(_pdfHelper.CreateCell("  机动车所有人及代理人对申请材料的真实有效性负责", NormalFont, Element.ALIGN_LEFT));
            table.AddCell(_pdfHelper.CreateCell("机动车所有人(代理人签字):" + Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine + "                     " + DateTime.Now.ToString("yyyy年MM月dd日").PadLeft("机动车所有人(代理人签字):".Length * 3, ' '), NormalFont, Element.ALIGN_LEFT));

            //table1 = _pdfHelper.CreateTable(new float[] { 1 }, doc);
            //table1.AddCell(_pdfHelper.CreateNoWidthCell("机动车所有人(代理人签字):", NormalFont, Element.ALIGN_LEFT));
            //table1.AddCell(_pdfHelper.CreateNoWidthCell("", NormalFont, Element.ALIGN_LEFT));
            //table1.AddCell(_pdfHelper.CreateNoWidthCell(DateTime.Now.ToString("yyyy年MM月dd日"), NormalFont, Element.ALIGN_LEFT));
            //PdfPCell cell1 = new PdfPCell(table1);
            //table.AddCell(cell1);
            doc.Add(table);

            table = _pdfHelper.CreateTable(new float[] { 1, 4 }, doc);
            table.AddCell(_pdfHelper.CreateCell("公安交警" + Environment.NewLine + "部门提示", NormalFont, Element.ALIGN_CENTER));
            table.AddCell(_pdfHelper.CreateCell("       《中华人民共和国道路交通安全法》第十六条规定,任何单位或者个人不得" +
                                                "拼装机动车或者擅自改变机动车已登记的结构、构造或者特征。构造或者特征。《机动车登记规公安交管定》" +
                                                " (公安部令第124号)第五十七条规定,擅自改变机动车外形和已登记的有部门提示关技术数据的, 由公安机关交通管理部门责令恢复原状," +
                                                "并处警告或者五百元以下罚款。擅自改装机动车属于违法行为,应承担法律责任,因非法改装造成交通事故的," +
                                                "还应承担相应交通事故责任。", NormalFont, Element.ALIGN_LEFT));

            doc.Add(table);
            doc.Close();

            MemoryStream memoryStream1 = new MemoryStream(memoryStream.ToArray());

            O2S.Components.PDFRender4NET.PDFFile pdfFile = O2S.Components.PDFRender4NET.PDFFile.Open(memoryStream1);
            System.Drawing.Bitmap pageImage = pdfFile.GetPageImage(0, 56 * (int)PdfHelper.Definition.Six);

            PrinterSettings settings = new PrinterSettings();
            PrintDocument   pd       = new PrintDocument();

            settings.PrinterName = AppHelper.AppSetting.PrinterName;
            settings.PrintToFile = false;
            PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);

            pdfPrintSettings.PageScaling            = PageScaling.MultiplePagesPerSheetProportional;
            pdfPrintSettings.PrinterSettings.Copies = 1;
            LogHelper.Trace("开始打印" + AppHelper.AppSetting.PrinterName);
            pdfFile.Print(pdfPrintSettings);
            LogHelper.Trace("打印完成" + AppHelper.AppSetting.PrinterName);

            memoryStream.Close();
            memoryStream.Dispose();
            memoryStream1.Close();
            memoryStream1.Dispose();

            return(pageImage);
        }
Exemple #11
0
        public void PrintMsg()
        {
            PdfHelper    pdfHelper    = new PdfHelper();
            Document     doc          = pdfHelper.CreateDocumentA4();
            MemoryStream memoryStream = new MemoryStream();
            PdfWriter    writer       = PdfWriter.GetInstance(doc, memoryStream);

            try
            {
                doc.Open();
                doc.NewPage();

                BaseFont             ArialFont = BaseFont.CreateFont("STZHONGS.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                iTextSharp.text.Font BoldFont  = new iTextSharp.text.Font(ArialFont, 17, iTextSharp.text.Font.BOLD, new BaseColor(System.Drawing.Color.Black));

                ApplyTableSetting print = AppHelper.ApplyPointSetting;
                PdfContentByte    pb    = writer.DirectContent;
                pb.BeginText();
                pb.SetFontAndSize(ArialFont, 15);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, DateTime.Now.ToString("yyyy"), print.X_Year, print.Y_Year, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, DateTime.Now.ToString("MM"), print.X_Month, print.Y_Month, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, DateTime.Now.ToString("dd"), print.X_Day, print.Y_Day, 0);

                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _carInfo.Owner, print.X_Owner, print.Y_Owner, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "100021", print.X_Post, print.Y_Post, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _carInfo?.Addr ?? "", print.X_Addr, print.X_Addr, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _carInfo?.MobilePhone ?? "", print.X_MobilePhone, print.Y_MobilePhone, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _carInfo.PlateNo, print.X_PlateNo, print.Y_PlateNo, 0);
                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _carInfo.PlateType, print.X_PlateType, print.Y_PlateType, 0);

                pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _ticketNo, print.X_Ticket, print.Y_Ticket, 0);
                if (_carInfo.PlateNo.Contains("京"))
                {
                    pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "√", print.X_Apply, print.Y_Apply, 0);
                }
                else
                {
                    pb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "√", print.X_Apply1, print.Y_Apply1, 0);
                }

                pb.EndText();

                doc.Close();
                MemoryStream pdf     = new MemoryStream(memoryStream.ToArray());
                PDFFile      pdfFile = PDFFile.Open(pdf);

                PrinterSettings settings = new PrinterSettings();
                PrintDocument   pd       = new PrintDocument();
                settings.PrinterName = AppHelper.AppSetting.PrinterName;
                settings.PrintToFile = false;

                PDFPrintSettings pdfPrintSettings = new PDFPrintSettings(settings);
                pdfPrintSettings.PageScaling            = PageScaling.MultiplePagesPerSheetProportional;
                pdfPrintSettings.PrinterSettings.Copies = 1;
                pdfFile.Print(pdfPrintSettings);
                pdf.Close();
                pdf.Dispose();
                pdfFile.Dispose();
            }
            catch (Exception ex)
            {
                LogHelper.Error("打印异常:" + ex.Message);
            }
            finally
            {
                memoryStream.Dispose();
                memoryStream.Close();
                writer.Dispose();
                doc.Dispose();
                doc.Close();
            }
        }