Ejemplo n.º 1
0
        //CLICK EVENT OF EXPORT PDF IMAGE
        private void exportImageClick(object sender, EventArgs e)
        {
            List <Image> images = new List <Image>();

            foreach (Tile tile in _imageTileControl.Groups[0].Tiles)
            {
                if (tile.Checked)
                {
                    images.Add(tile.Image);
                }
            }
            //CONVERTING TO PDF
            ConvertToPdf(images);

            //SAVING THE FILE
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.DefaultExt = "pdf";
            saveFile.Filter     = "PDF files (*.pdf)|*.pdf*";

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                c1PdfDocument1.Save(saveFile.FileName);
            }
        }
Ejemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // get stream to save to
            var dlg = new SaveFileDialog();

            dlg.DefaultExt = ".pdf";
            var dr = dlg.ShowDialog();

            if (!dr.HasValue || !dr.Value)
            {
                return;
            }

            // get sender button
            var btn = sender as Button;

            // create document
            var pdf = new C1PdfDocument(PaperKind.Letter);

            pdf.Clear();

            // set document info
            var di = pdf.DocumentInfo;

            di.Author  = "ComponentOne";
            di.Subject = "C1.WPF.Pdf demo.";
            di.Title   = "Experimental VisualTree Exporter for PDF";

            // walk visual tree
            CreateDocumentVisualTree(pdf, content);

            // render footers
            // this reopens each page and adds content to them (now we know the page count).
            var font = new Font("Arial", 8, PdfFontStyle.Bold);
            var fmt  = new StringFormat();

            fmt.Alignment     = HorizontalAlignment.Right;
            fmt.LineAlignment = VerticalAlignment.Bottom;
            for (int page = 0; page < pdf.Pages.Count; page++)
            {
                pdf.CurrentPage = page;
                var text = string.Format("C1.WPF.Pdf: {0}, page {1} of {2}",
                                         di.Title,
                                         page + 1,
                                         pdf.Pages.Count);
                pdf.DrawString(
                    text,
                    font,
                    Colors.DarkGray,
                    PdfUtils.Inflate(pdf.PageRectangle, -72, -36),
                    fmt);
            }

            // save document
            using (var stream = dlg.OpenFile())
            {
                pdf.Save(stream);
            }
            MessageBox.Show("Pdf Document saved to " + dlg.SafeFileName);
        }
Ejemplo n.º 3
0
        private void makeDocument()
        {
            // start a new document
            C1PdfDocument pdf  = new C1PdfDocument();
            string        name = Thread.CurrentThread.Name;

            // with two fonts
            Font font1 = new Font("Tahoma", 10);
            Font font2 = new Font("Tahoma", 10, FontStyle.Italic);

            // create document
            pdf.Clear();
            RectangleF rc = pdf.PageRectangle;

            rc.Inflate(-72, -72);
            while (rc.Y < pdf.PageRectangle.Bottom - 72)
            {
                pdf.DrawString("Hello buddy. This is thread " + name, font1, Brushes.Red, rc);
                rc.Y += 12;
                pdf.DrawString("Hello again. Same thread " + name, font2, Brushes.Blue, rc);
                rc.Y += 12;
                pdf.DrawLine(Pens.ForestGreen, rc.X, rc.Y, rc.Right, rc.Y);

                // let other threads work
                Thread.Sleep(0);
            }

            // save document
            pdf.Save(string.Format(@"c:\temp\test{0}.pdf", name));
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new Microsoft.Win32.SaveFileDialog();

            dlg.Filter = "PDF files (*.pdf)|*.pdf";
            //var t = dlg.ShowDialog();
            if (dlg.ShowDialog().Value)
            {
                // create pdf document
                var pdf = new C1PdfDocument();
                pdf.Landscape   = true;
                pdf.Compression = CompressionLevel.NoCompression;

                // render all grids into pdf document
                var options = new PdfExportOptions();
                options.ScaleMode = ScaleMode.ActualSize;
                GridExport.RenderGrid(pdf, _flex1, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex2, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex3, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex4, options);

                // save document
                using (var stream = dlg.OpenFile())
                {
                    pdf.Save(stream);
                }
            }
        }
 private void _exportimage_Click(object sender, EventArgs e)
 {   //This executes when user clicks on export pdf icon(picture box).
     try
     {
         List <Image> images = new List <Image>();
         foreach (Tile tile in _imageTileControl.Groups[0].Tiles)
         {
             if (tile.Checked)
             {
                 images.Add(tile.Image);
             }
         }
         ConvertToPdf(images);
         SaveFileDialog saveFile = new SaveFileDialog();
         saveFile.DefaultExt = "pdf";
         saveFile.Filter     = "PDF files (*.pdf)|*.pdf*";
         if (saveFile.ShowDialog() == DialogResult.OK)
         {
             imagePdfDocument.Save(saveFile.FileName);
         }
     }
     catch (Exception excp)
     {
         MessageBox.Show("Exception occured: " + excp);
     }
 }
Ejemplo n.º 6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.Filter = "PDF files (*.pdf)|*.pdf";
            //var t = dlg.ShowDialog();
            if (dlg.ShowDialog().Value)
            {
                // create pdf document
                var pdf = new C1PdfDocument();
                pdf.Landscape = true;
                pdf.Compression = CompressionLevel.NoCompression;

                // render all grids into pdf document
                var options = new PdfExportOptions();
                options.ScaleMode = ScaleMode.ActualSize;
                GridExport.RenderGrid(pdf, _flex1, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex2, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex3, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex4, options);

                // save document
                using (var stream = dlg.OpenFile())
                {
                    pdf.Save(stream);
                }
            }
        }
Ejemplo n.º 7
0
        public static MemoryStream SaveToStream(this C1PdfDocument pdf)
        {
            MemoryStream ms = new MemoryStream();

            pdf.Save(ms);
            ms.Seek(0, SeekOrigin.Begin);
            return(ms);
        }
        public static void SavePdf(C1FlexGrid flex, Stream s, PdfExportOptions options)
        {
            var pdf = new C1PdfDocument();

            options.KnownPageCount = false;
            RenderGrid(pdf, flex, options);

            // save the PDF document and close the stream
            pdf.Save(s);
            s.Close();
        }
Ejemplo n.º 9
0
        // ** event handlers
        public void Save(string fileName)
        {
            // create new pdf document
            var pdf = new C1PdfDocument();

            // add pages to document
            for (int page = 0; page < _images.Count; page++)
            {
                DrawPageImage(pdf, page);
            }

            // done
            pdf.Save(fileName);
        }
Ejemplo n.º 10
0
        private void OnExportClick(object sender, EventArgs e)
        {
            C1PdfDocument imageToPdf = new C1PdfDocument();
            List <Image>  images     = new List <Image>();

            foreach (Tile tile in imageTileControl.Groups[0].Tiles)
            {
                if (tile.Checked)
                {
                    images.Add(tile.Image);
                }
            }
            if (images.Count <= 0)
            {
                MessageBox.Show(Properties.Resources.no_images_selected, Properties.Resources.dialog_alert);
                return;
            }
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.DefaultExt = "pdf";
            saveFile.Filter     = "PDF files (*.pdf)|*.pdf*";
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    ConvertToPdf(images, imageToPdf);
                    Console.WriteLine(saveFile.FileName);
                    imageToPdf.Save(saveFile.FileName);
                    DialogResult dialogResult = MessageBox.Show(saveFile.FileName + " " + Properties.Resources.saved_successfully, Properties.Resources.dialog_success, MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(saveFile.FileName);
                    }
                }
                catch (Exception e1)
                {
                    Console.WriteLine(e1.StackTrace);
                    MessageBox.Show(e1.Message, Properties.Resources.dialog_error);
                }
            }
            else
            {
                Console.WriteLine("Operation Cancelled");
            }
        }
Ejemplo n.º 11
0
        //Implementation of Export to PDF Method

        private void OnExportClick(object sender, EventArgs e)
        {
            List <Image> images = new List <Image>();

            foreach (Tile tile_ in tile.Groups[0].Tiles)
            {
                if (tile_.Checked)
                {
                    images.Add(tile_.Image);
                }
            }
            ConvertToPdf(images);
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.DefaultExt = "pdf";
            saveFile.Filter     = "PDF files (*.pdf)|*.pdf*";
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                imagePdfDocument.Save(saveFile.FileName);
            }
        }
Ejemplo n.º 12
0
        private void c1Button1_Click(object sender, EventArgs e)
        {
            String        statusOPD = "", vsDate = "", vn = "", an = "", anDate = "", hn = "", preno = "", anyr = "", vn1 = "", pathFolder = "", datetick = "";
            C1PdfDocument pdf = new C1PdfDocument();

            pdf.Clear();

            //get page rectangle, discount margins
            RectangleF rcPage = pdf.PageRectangle;

            rcPage.Inflate(-72, -92);

            //loop through selected categories
            int page = 0;

            //add page break, update page counter
            if (page > 0)
            {
                pdf.NewPage();
            }
            page++;

            pdf.DrawString("ใบงบหน้าสรุป", _fontTitle, Brushes.Blue, rcPage);


            datetick   = DateTime.Now.Ticks.ToString();
            pathFolder = "D:\\" + datetick;
            if (!Directory.Exists(pathFolder))
            {
                Directory.CreateDirectory(pathFolder);
            }
            pdf.Save(pathFolder + "\\_summary.pdf");



            System.Diagnostics.Process.Start("explorer.exe", pathFolder);
        }
Ejemplo n.º 13
0
        private void printReserveVaccinePDF()
        {
            String pathFolder = "", filename = "", datetick = "";
            int    gapLine = 20, gapLine1 = 15, gapX = 40, gapY = 20, xCol2 = 200, xCol1 = 160, xCol3 = 300, xCol4 = 390, xCol5 = 500;
            Size   size = new Size();

            C1PdfDocument       pdf = new C1PdfDocument();
            C1PdfDocumentSource pds = new C1PdfDocumentSource();
            StringFormat        _sfRight, _sfRightCenter;

            //Font _fontTitle = new Font("Tahoma", 15, FontStyle.Bold);
            _sfRight                     = new StringFormat();
            _sfRight.Alignment           = StringAlignment.Far;
            _sfRightCenter               = new StringFormat();
            _sfRightCenter.Alignment     = StringAlignment.Far;
            _sfRightCenter.LineAlignment = StringAlignment.Center;

            Font titleFont = new Font(bc.iniC.pdfFontName, bc.pdfFontSizetitleFont, FontStyle.Bold);
            Font hdrFont   = new Font(bc.iniC.pdfFontName, bc.pdfFontSizehdrFont, FontStyle.Regular);
            Font hdrFontB  = new Font(bc.iniC.pdfFontName, 16, FontStyle.Bold);
            Font ftrFont   = new Font(bc.iniC.pdfFontName, 8);
            Font txtFont   = new Font(bc.iniC.pdfFontName, bc.pdfFontSizetxtFont, FontStyle.Regular);

            pdf.FontType = FontTypeEnum.Embedded;

            RectangleF rcPage = pdf.PageRectangle;

            rcPage = RectangleF.Empty;
            rcPage.Inflate(-72, -92);
            rcPage.Location = new PointF(rcPage.X, rcPage.Y + titleFont.SizeInPoints + 10);
            rcPage.Size     = new SizeF(0, titleFont.SizeInPoints + 3);
            rcPage.Width    = 110;

            Image loadedImage;

            loadedImage = Resources.LOGO_BW_tran;
            float newWidth  = loadedImage.Width * 100 / loadedImage.HorizontalResolution;
            float newHeight = loadedImage.Height * 100 / loadedImage.VerticalResolution;

            float widthFactor  = 4.8F;
            float heightFactor = 4.8F;

            if (widthFactor > 1 | heightFactor > 1)
            {
                if (widthFactor > heightFactor)
                {
                    widthFactor = 1;
                    newWidth    = newWidth / widthFactor;
                    newHeight   = newHeight / widthFactor;
                    //newWidth = newWidth / 1.2;
                    //newHeight = newHeight / 1.2;
                }
                else
                {
                    newWidth  = newWidth / heightFactor;
                    newHeight = newHeight / heightFactor;
                }
            }

            RectangleF recf = new RectangleF(15, 15, (int)newWidth, (int)newHeight);

            pdf.DrawImage(loadedImage, recf);
            rcPage.X = gapX + recf.Width - 10;
            rcPage.Y = gapY;
            RectangleF rc = rcPage;

            string[] filePaths = Directory.GetFiles(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\slip\\", txtID.Text.Trim() + "*.jpg");
            if (filePaths.Length > 0)
            {
                int i = 1, xx = 40;
                foreach (String filename1 in filePaths)
                {
                    Image loadedImage1, resizedImage1 = null;
                    loadedImage1 = Image.FromFile(filename1);
                    int originalWidth = 0;
                    originalWidth = loadedImage1.Width;
                    int newWidth1 = 200;

                    resizedImage1 = loadedImage1.GetThumbnailImage(newWidth1, (newWidth1 * loadedImage1.Height) / originalWidth, null, IntPtr.Zero);
                    RectangleF recf1 = new RectangleF(i == 1?xx: newWidth1 + 10, 380, (int)newWidth1, (int)resizedImage1.Height);
                    pdf.DrawImage(loadedImage1, recf1);
                    i++;
                }
            }
            Image      qrcode = c1BarCode1.Image;
            RectangleF recf2  = new RectangleF(350, 500, qrcode.Width, qrcode.Height);

            pdf.DrawImage(qrcode, recf2);

            size         = bc.MeasureString(bc.iniC.hostname, titleFont);
            rcPage.Width = size.Width;
            pdf.DrawString(bc.iniC.hostname, titleFont, Brushes.Black, rcPage);
            gapY        += gapLine;
            rcPage.Y     = gapY;
            size         = bc.MeasureString(bc.iniC.hostaddresst, hdrFont);
            rcPage.Width = size.Width;
            pdf.DrawString(bc.iniC.hostaddresst, hdrFont, Brushes.Black, rcPage);

            String dose = "", amt11 = "";
            int    amt111 = 0;

            dose = txtDose.Text.Replace("จอง", "").Replace("เข็ม", "").Replace("3,300", "").Replace("1,650", "").Replace("4,950", "").Trim().Replace("6,600", "").Trim().Replace("8,250", "")
                   .Replace("8,250", "").Replace("9,900", "").Replace("11,500", "").Replace("13,200", "").Replace("14,850", "").Replace("16,500", "").Replace("18,150", "").Replace("19,800", "").Trim();
            int.TryParse(dose, out amt111);
            amt111 *= 1650;

            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapX  = xCol1;
            rc.X  = (pdf.PageSize.Width / 2) - 15;
            rc.Y  = gapY;
            pdf.DrawString("ใบจองวัคซีน", titleFont, Brushes.Black, rc);

            gapY += gapLine;
            gapY += gapLine;
            gapX  = 30;
            rc.X  = gapX;
            rc.Y  = gapY;
            pdf.DrawString("ข้าพเจ้า ชื่อ-นามสกุล", txtFont, Brushes.Black, rc);
            rc.X = 110;
            rc.Y = rc.Y - 4;
            pdf.DrawString(txtName.Text, hdrFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 100, gapY + 15, 380, gapY + 15);
            rc.X = 400;
            rc.Y = gapY;
            pdf.DrawString("เลขที่ประชาชน", txtFont, Brushes.Black, rc);
            rc.X = 470;
            rc.Y = rc.Y - 4;
            pdf.DrawString(txtPID.Text, hdrFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 455, gapY + 15, 590, gapY + 15);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = gapX;
            rc.Y  = gapY;
            pdf.DrawString("ที่อยู่ปัจจุบัน", txtFont, Brushes.Black, rc);
            rc.X = 75;
            rc.Y = rc.Y - 4;
            pdf.DrawString(txtAddress.Text, hdrFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 70, gapY + 15, 400, gapY + 15);
            rc.X = 420;
            rc.Y = gapY;
            pdf.DrawString("เบอร์ที่ติดต่อได้", txtFont, Brushes.Black, rc);
            rc.X = 480;
            rc.Y = rc.Y - 4;
            pdf.DrawString(txtMobile.Text, hdrFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 470, gapY + 15, 590, gapY + 15);

            gapY    += gapLine;
            gapX     = 30;
            rc.X     = gapX;
            rc.Y     = gapY;
            rc.Width = 610;
            pdf.DrawString("ขอจองวัคซีนทางเลือก MODERNA และชำระเงิน  จำนวน             โดส   ราคา 1,650 บาทต่อโดส", txtFont, Brushes.Black, rc);
            rc.X = 19;
            rc.Y = rc.Y - 4;
            pdf.DrawString(dose, hdrFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 215, gapY + 15, 220, gapY + 15);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = gapX;
            rc.Y  = gapY;
            pdf.DrawString("ราคาดังกล่าวเป็นราคาที่ รวมค่าวัคซีน  ค่าประกัน  ค่าบริการสำหรับการฉีด ไม่รวมค่าแพทย์ ถ้าต้องการพบแพทย์  โดยชำระเงินเต็มจำนวน", txtFont, Brushes.Black, rc);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = gapX;
            rc.Y  = gapY;
            pdf.DrawString("โดสละ 1,650  รวม            โดส  เป็นเงิน                               บาท  ตามใบเจองเลขที่                            ", txtFont, Brushes.Black, rc);
            rc.X = 100;
            rc.Y = rc.Y - 4;
            pdf.DrawString(dose, hdrFont, Brushes.Black, rc);
            rc.X = 175;
            rc.Y = rc.Y;
            pdf.DrawString(amt111.ToString("#,###.00"), hdrFont, Brushes.Black, rc);
            rc.X = 310;
            rc.Y = rc.Y;
            pdf.DrawString(txtID.Text.Trim(), hdrFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 95, gapY + 15, 100, gapY + 15);
            pdf.DrawLine(Pens.Gray, 165, gapY + 15, 220, gapY + 15);
            pdf.DrawLine(Pens.Gray, 340, gapY + 15, 470, gapY + 15);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = gapX;
            rc.Y  = gapY;
            pdf.DrawString("หมายเหตุ  1.ทางโรงพยาบาลจะนัดรับวัคซีนหลังจาก โรงพยาบาลได้รับการจัดสรรจากหน่วยงานภาครัฐ  ตามที่อยู่และเบอร์โทรที่ได้ให้ไว้", txtFont, Brushes.Black, rc);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = 67;
            rc.Y  = gapY;
            pdf.DrawString("2.กรณีได้รับจัดสรรวัคซีนมาไม่เพียงพอต่อการจองที่โรงพยาบาลได้รับจองตามที่ได้รับจัดสรร  ทางโรงพยาบาลจะเรียงลำดับการเข้ารับวัคซีนตามลำดดับการจองก่อน-หลัง", txtFont, Brushes.Black, rc);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = 67;
            rc.Y  = gapY;
            pdf.DrawString("และจะคืนเงินมัดจำให้เต็มจำนวน  กรณีจองแล้วไม่ได้", txtFont, Brushes.Black, rc);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = 67;
            rc.Y  = gapY;
            pdf.DrawString("3.ทางโรงพยาบาลสงวนสิทธิ์ยกเลิกการของโดยไม่คืนเงินกรณีผู้จองไม่มารับวัคซีนตามช่วงเวลาที่กำหนด", txtFont, Brushes.Black, rc);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = 67;
            rc.Y  = gapY;
            pdf.DrawString("4.ห้ามนำวัคซีนไปขายต่อเพราะเป็นสินค้าควบคุมราคา", txtFont, Brushes.Black, rc);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = 67;
            rc.Y  = gapY;
            pdf.DrawString("5.ต้องมารับบริการฉีดวัคซีน ที่โรงพยาบาล บางนา5 เท่านั้น", txtFont, Brushes.Black, rc);

            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapX  = 30;
            rc.X  = 370;
            rc.Y  = gapY;
            pdf.DrawString("ผู้จอง", txtFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 400, gapY + 15, 500, gapY + 15);

            gapY += gapLine;
            gapX  = 30;
            rc.X  = 370;
            rc.Y  = gapY;
            pdf.DrawString("ผู้รับจอง  on line", txtFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 400, gapY + 15, 500, gapY + 15);

            String txt = "";

            if (txtDate.Text.Trim().Length > 9)
            {
                txt = bc.datetoShow(txtDate.Text.Trim()) + " " + txtDate.Text.Substring(10).Trim();
            }
            else
            {
                txt = txtDate.Text.Trim();
            }
            gapY += gapLine;
            gapX  = 30;
            rc.X  = 370;
            rc.Y  = gapY;
            pdf.DrawString("วันที่จอง   " + txt, txtFont, Brushes.Black, rc);
            pdf.DrawLine(Pens.Gray, 400, gapY + 15, 500, gapY + 15);

            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapY += gapLine;
            gapX  = 30;
            rc.X  = gapX;
            rc.Y  = gapY;
            pdf.DrawString("สอบถามเพิ่มเติมโทร 02 138 1155-60 ต่อ 143   ", txtFont, Brushes.Black, rc);
            gapY += gapLine;
            gapX  = 30;
            rc.X  = gapX;
            rc.Y  = gapY;
            pdf.DrawString("วันจันทร์ ถึง วันศุกร์ เวลา 8.00 - 16.00 น. (ปิดพักเที่ยง)   ", txtFont, Brushes.Black, rc);
            gapY += gapLine;
            gapX  = 30;
            rc.X  = gapX;
            rc.Y  = gapY;
            pdf.DrawString("line @657bkkyq", txtFont, Brushes.Black, rc);


            RectangleF rcHdr = new RectangleF();

            rcHdr.Width  = pdf.PageSize.Width - 20;
            rcHdr.Height = pdf.PageSize.Height - 20;
            rcHdr.X      = 10;
            rcHdr.Y      = 10;
            String PathName = "medical", fileName = "";

            datetick = DateTime.Now.Ticks.ToString();
            if (!Directory.Exists("report"))
            {
                Directory.CreateDirectory("report");
            }
            fileName = "report\\" + txtID.Text.Trim() + "_" + datetick + ".pdf";
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
                System.Threading.Thread.Sleep(100);
            }
            pdf.DrawRectangle(Pens.Black, rcHdr);       // ตาราง

            String path = Path.GetDirectoryName(Application.ExecutablePath);

            pdf.Save(path + "\\" + fileName);
            Process.Start(fileName);
        }
Ejemplo n.º 14
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // get stream to save to
            var dlg = new SaveFileDialog();
            dlg.DefaultExt = ".pdf";
            var dr = dlg.ShowDialog();
            if (!dr.HasValue || !dr.Value)
            {
                return;
            }

            // get sender button
            var btn = sender as Button;

            // create document
            var pdf = new C1PdfDocument(PaperKind.Letter);
            pdf.Clear();

            // set document info
            var di = pdf.DocumentInfo;
            di.Author = "ComponentOne";
            di.Subject = "C1.WPF.Pdf demo.";
            di.Title = "Experimental VisualTree Exporter for PDF";

            // walk visual tree
            CreateDocumentVisualTree(pdf, content);

            // render footers
            // this reopens each page and adds content to them (now we know the page count).
            var font = new Font("Arial", 8, PdfFontStyle.Bold);
            var fmt = new StringFormat();
            fmt.Alignment = HorizontalAlignment.Right;
            fmt.LineAlignment = VerticalAlignment.Bottom;
            for (int page = 0; page < pdf.Pages.Count; page++)
            {
                pdf.CurrentPage = page;
                var text = string.Format("C1.WPF.Pdf: {0}, page {1} of {2}",
                    di.Title,
                    page + 1,
                    pdf.Pages.Count);
                pdf.DrawString(
                    text,
                    font,
                    Colors.DarkGray,
                    PdfUtils.Inflate(pdf.PageRectangle, -72, -36),
                    fmt);
            }

            // save document
            using (var stream = dlg.OpenFile())
            {
                pdf.Save(stream);
            }
            MessageBox.Show("Pdf Document saved to " + dlg.SafeFileName);
        }
Ejemplo n.º 15
0
        // export the grid to a PDF file
        void SavePdf(Stream s, string documentName)
        {
            #if false
            // get root element to lay out the PDF pages
            Panel root = null;
            for (var parent = _flex.Parent as FrameworkElement; parent != null; parent = parent.Parent as FrameworkElement)
            {
                if (parent is Panel)
                {
                    root = parent as Panel;
                }
            }

            // create pdf document
            var pdf = new C1PdfDocument(PaperKind.Letter, false);

            // get page size
            var rc = pdf.PageRectangle;
            var m = new Thickness(96, 96, 96 / 2, 96 / 2);
            var scaleMode = ScaleMode.ActualSize;

            // create panel to hold elements while they render
            var pageTemplate = new PageTemplate();
            pageTemplate.Width = rc.Width;
            pageTemplate.Height = rc.Height;
            pageTemplate.SetPageMargin(m);
            root.Children.Add(pageTemplate);

            // render grid into PDF document
            var sz = new Size(rc.Width - m.Left - m.Right, rc.Height - m.Top - m.Bottom);
            var pages = _flex.GetPageImages(scaleMode, sz, 100);
            for (int i = 0; i < pages.Count; i++)
            {
                // skip a page when necessary
                if (i > 0)
                {
                    pdf.NewPage();
                }

                // set content
                pageTemplate.PageContent.Child = pages[i];
                pageTemplate.PageContent.Stretch = System.Windows.Media.Stretch.Uniform;

                // set header/footer text
                pageTemplate.HeaderLeft.Text = documentName;
                pageTemplate.FooterRight.Text = string.Format("Page {0} of {1}",
                    i + 1, pages.Count);

                // measure page element
                pageTemplate.Measure(new Size(rc.Width, rc.Height));
                pageTemplate.UpdateLayout();

                // add page element to PDF
                pdf.DrawElement(pageTemplate, rc);
            }

            // done with template
            root.Children.Remove(pageTemplate);

            // save the PDF document
            pdf.Save(s);
            s.Close();
            #endif
        }
Ejemplo n.º 16
0
        private bool CreatePDF(Fax fax, string fileName)
        {
            bool result = false;

            try
            {
                C1PdfDocument c1pdf = new C1PdfDocument();
                // create pdf document
                c1pdf.Clear();
                c1pdf.DocumentInfo.Title = "Fax: " + fax.FaxFilename;

                // calculate document name
                if (true == File.Exists(fileName))
                {
                    // pdf file already exists - so don't recreate it.
                    Trace.WriteLine("PDF File already exists: " + fileName);
                    result = true;
                }
                else
                {
                    bool       newPage     = false;
                    RectangleF rcPage      = RectangleF.Empty;
                    RectangleF rc1         = RectangleF.Empty;
                    bool       addMetaText = true;
                    foreach (Attachment attachment in fax.Attachments)
                    {
                        if (newPage)
                        {
                            c1pdf.NewPage();
                            rc1.Y = rcPage.Y;
                        }

                        rcPage = c1pdf.PageRectangle;
                        //rcPage.Inflate(-72, -72);

                        rc1 = rcPage;
                        rc1.Inflate(-10, 0);
                        rc1         = RenderMultiPageImage(ref c1pdf, rcPage, rc1, attachment.FileName, fax, addMetaText);
                        addMetaText = false;
                        Trace.WriteLine("Rendered page: " + attachment.FileName + " to pdf: " + fileName);
                        newPage = true;
                    }


                    c1pdf.Save(fileName);
                    Trace.WriteLine("Saved (" + fileName + ") successfully.");

                    result = true;
                }
            }
            catch (IOException fileEx)
            {
                Trace.WriteLine("IOException occurred in method CreatePDF with: " + fileEx.Message, "exceptions");
                result = false;
            }
            catch (Exception ex)
            {
                Trace.WriteLine("General Exception occurred in method CreatePDF with: " + ex.Message, "exceptions");
                result = false;
            }
            return(result);
        }
Ejemplo n.º 17
0
        private void BtnPrint_Click(object sender, EventArgs e)
        {
            int  gapLine = 40, gapX = 40, gapY = 20, xCol2 = 130, xCol1 = 20, xCol3 = 300, xCol4 = 390, xCol5 = 1030;
            Size size = new Size();

            String statusOPD = "", vsDate = "", vn = "", an = "", anDate = "", doccd = "", docno = "", anyr = "", vn1 = "", pathFolder = "", datetick = "", filename = "", docyr = "", amt2 = "";
            String doc = "", datestart = "";
            //DataTable dt = new DataTable();
            DataTable dt = new DataTable();

            dt = bc.bcDB.pttscDB.SelectByDoc(txtPaidType.Text.Trim());

            DateTime dtstart = new DateTime();

            DateTime.TryParse(txtDateStart.Text, out dtstart);
            if (bc.iniC.windows.Equals("windosxp"))
            {
                if (dtstart.Year > 2500)
                {
                    dtstart = dtstart.AddYears(-543);
                }
                else if (dtstart.Year < 2000)
                {
                    dtstart = dtstart.AddYears(543);
                }
            }
            datestart = dtstart.ToString("dd-MM-yyyy", new CultureInfo("en-US"));

            //throw new NotImplementedException();
            C1PdfDocument       pdf = new C1PdfDocument();
            C1PdfDocumentSource pds = new C1PdfDocumentSource();
            StringFormat        _sfRight, _sfRightCenter;

            //Font _fontTitle = new Font("Tahoma", 15, FontStyle.Bold);
            _sfRight                     = new StringFormat();
            _sfRight.Alignment           = StringAlignment.Far;
            _sfRightCenter               = new StringFormat();
            _sfRightCenter.Alignment     = StringAlignment.Far;
            _sfRightCenter.LineAlignment = StringAlignment.Center;

            //RectangleF rc = GetPageRect(pdf);
            Font titleFont = new Font(bc.iniC.pdfFontName, 18, FontStyle.Bold);
            Font hdrFont   = new Font(bc.iniC.pdfFontName, 14, FontStyle.Regular);
            Font hdrFontB  = new Font(bc.iniC.pdfFontName, 16, FontStyle.Bold);
            Font ftrFont   = new Font(bc.iniC.pdfFontName, 8);
            Font txtFont   = new Font(bc.iniC.pdfFontName, 10, FontStyle.Regular);

            //pdf.Clear();
            pdf.FontType = FontTypeEnum.Embedded;

            //newPagePDFSummaryBorder(pdf, dt, titleFont, hdrFont, ftrFont, txtFont, false);

            //get page rectangle, discount margins
            RectangleF rcPage = pdf.PageRectangle;

            rcPage = RectangleF.Empty;
            rcPage.Inflate(-72, -92);
            rcPage.Location = new PointF(rcPage.X, rcPage.Y + titleFont.SizeInPoints + 10);
            rcPage.Size     = new SizeF(0, titleFont.SizeInPoints + 3);
            rcPage.Width    = 610;
            rcPage.Height   = gapLine;

            gapY += gapLine;
            gapY += gapLine;

            String space2 = "    ", space3 = "      ", space4 = "        ", space5 = "          ", space = "";
            int    rowline = 0, i = 0;

            rowline = 205;

            String txt = "ใบนำส่งรายชื่อ ผู้มาตรวจ COVID " + (bc.iniC.branchId.Equals("001") ? "บางนา 1" : bc.iniC.branchId.Equals("002") ? "บางนา 2" : "ไม่ระบุ");

            pdf.DrawString(txt, titleFont, Brushes.Black, rcPage);

            gapY           += gapLine;
            rcPage.Location = new PointF(rcPage.X, rcPage.Y + titleFont.SizeInPoints + 10);
            rcPage.Size     = new SizeF(0, titleFont.SizeInPoints + 3);
            rcPage.Width    = 610;
            txt             = " ประจำวันที่ " + datestart + " จำนวนผู้มาตรวจ " + dt.Rows.Count;
            pdf.DrawString(txt, titleFont, Brushes.Black, rcPage);

            gapY           += gapLine;
            rcPage.Location = new PointF(rcPage.X, rcPage.Y + titleFont.SizeInPoints + 10);
            rcPage.Size     = new SizeF(0, titleFont.SizeInPoints + 3);
            rcPage.Width    = 610;
            txt             = " เลขที่ " + txtPaidType.Text.Trim();
            pdf.DrawString(txt, titleFont, Brushes.Black, rcPage);

            datetick = DateTime.Now.Ticks.ToString();
            if (!Directory.Exists("report"))
            {
                Directory.CreateDirectory("report");
            }
            filename = "report\\" + datetick + ".pdf";
            pdf.Save(filename);
            pdf.Clear();
            pdf.Dispose();

            if (File.Exists(filename))
            {
                //bool isExists = System.IO.File.Exists(filename);
                //if (isExists)
                System.Diagnostics.Process.Start(filename);
            }
        }
Ejemplo n.º 18
0
        // export the grid to a PDF file
        void SavePdf(Stream s)
        {
            // get root element to lay out the PDF pages
            Panel root = null;

            for (var parent = _flex.Parent as FrameworkElement; parent != null; parent = parent.Parent as FrameworkElement)
            {
                if (parent is Panel)
                {
                    root = parent as Panel;
                }
            }

            // create pdf document
            var pdf = new C1PdfDocument(PaperKind.Letter, false);

            // get page size
            var rc        = pdf.PageRectangle;
            var m         = new Thickness(96, 96, 96 / 2, 96 / 2);
            var scaleMode = ScaleMode.ActualSize;

            // create panel to hold elements while they render
            var pageTemplate = new PageTemplate();

            pageTemplate.Width  = rc.Width;
            pageTemplate.Height = rc.Height;
            pageTemplate.SetPageMargin(m);
            root.Children.Add(pageTemplate);

            // render grid into PDF document
            var sz    = new Size(rc.Width - m.Left - m.Right, rc.Height - m.Top - m.Bottom);
            var pages = _flex.GetPageImages(scaleMode, sz, 100);

            for (int i = 0; i < pages.Count; i++)
            {
                // skip a page when necessary
                if (i > 0)
                {
                    pdf.NewPage();
                }

                // set content
                pageTemplate.PageContent.Child   = pages[i];
                pageTemplate.PageContent.Stretch = System.Windows.Media.Stretch.Uniform;

                // set footer text
                pageTemplate.FooterRight.Text = string.Format("Page {0} of {1}",
                                                              i + 1, pages.Count);

                // measure page element
                pageTemplate.Measure(new Size(rc.Width, rc.Height));
                pageTemplate.UpdateLayout();

                // add page element to PDF
                pdf.DrawElement(pageTemplate, rc);
            }

            // done with template
            root.Children.Remove(pageTemplate);

            // save the PDF document
            pdf.Save(s);
            s.Close();
        }
Ejemplo n.º 19
-1
        public static void HandleButtonClick(object sender, RoutedEventArgs e)
        {
            // get stream to save to
            var dlg = new SaveFileDialog();
            dlg.DefaultExt = ".pdf";
            var dr = dlg.ShowDialog();
            if (!dr.HasValue || !dr.Value)
            {
                return;
            }

            // get sender button
            var btn = sender as Button;

            // create document
            var pdf = new C1PdfDocument(PaperKind.Letter);
            pdf.Clear();

            // set document info
            var di = pdf.DocumentInfo;
            di.Author = "ComponentOne";
            di.Subject = "C1.WPF.Pdf demo.";
            di.Title = (string)btn.Content;

            //// add some security
            //if (false)
            //{
            //    var si = pdf.Security;
            //    si.AllowPrint = false;
            //    si.AllowEditAnnotations = false;
            //    si.AllowEditContent = false;
            //    si.AllowCopyContent = false;
            //    //si.UserPassword = "******";
            //    //si.OwnerPassword = "******";
            //}

            //// set viewer preferences
            //if (false)
            //{
            //    var vp = pdf.ViewerPreferences;
            //    vp.CenterWindow = true;
            //    vp.FitWindow = true;
            //    vp.PageLayout = PageLayout.TwoColumnLeft;
            //    vp.PageMode = PageMode.FullScreen;
            //}

            // create document
            switch (di.Title)
            {
                case "Quotes":
                    CreateDocumentQuotes(pdf);
                    break;
                case "Tables":
                    CreateDocumentTables(pdf);
                    break;
                case "Images":
                    CreateDocumentImages(pdf);
                    break;
                case "Paper Sizes":
                    CreateDocumentPaperSizes(pdf);
                    break;
                case "Table of Contents":
                    CreateDocumentTOC(pdf);
                    break;
                case "Text Flow":
                    CreateDocumentTextFlow(pdf);
                    break;
                case "Text":
                    CreateDocumentText(pdf);
                    break;
                case "Graphics":
                    CreateDocumentGraphics(pdf);
                    break;
            }

            // render footers
            // this reopens each page and adds content to them (now we know the page count).
            var font = new Font("Arial", 8, PdfFontStyle.Bold);
            var fmt = new StringFormat();
            fmt.Alignment = HorizontalAlignment.Right;
            fmt.LineAlignment = VerticalAlignment.Bottom;
            for (int page = 0; page < pdf.Pages.Count; page++)
            {
                pdf.CurrentPage = page;
                var text = string.Format("C1.WPF.Pdf: {0}, page {1} of {2}",
                    di.Title,
                    page + 1,
                    pdf.Pages.Count);
                pdf.DrawString(
                    text,
                    font,
                    Colors.DarkGray,
                    PdfUtils.Inflate(pdf.PageRectangle, -72, -36),
                    fmt);
            }

            // save document
            using (var stream = dlg.OpenFile())
            {
                pdf.Save(stream);
            }
            MessageBox.Show("Pdf Document saved to " + dlg.SafeFileName);
        }
Ejemplo n.º 20
-1
        public static void SavePdf(C1FlexGrid flex, Stream s, PdfExportOptions options)
        {
            var pdf = new C1PdfDocument();
            options.KnownPageCount = false;
            RenderGrid(pdf, flex, options);

            // save the PDF document and close the stream
            pdf.Save(s);
            s.Close();
        }