Esempio n. 1
0
        private void newPagePDFBorder(C1PdfDocument pdf, Boolean loopfor)
        {
            int  gapLine = 20, gapX = 40, gapY = 135, xCol2 = 130, xCol1 = 20, xCol3 = 300, xCol4 = 390, xCol5 = 1030;
            Size size = new Size();

            //if(pdf.Pages.Count>1) pdf.NewPage();
            //if ((loopfor) && (pdf.CurrentPage != 0)) pdf.NewPage();
            if ((loopfor))
            {
                pdf.NewPage();
            }
            RectangleF rcHdr = new RectangleF();

            rcHdr.Width  = 542;
            rcHdr.Height = 500;
            rcHdr.X      = gapX;
            rcHdr.Y      = gapY;
            //rcHdr.Location
            pdf.DrawRectangle(Pens.Black, rcHdr);       // ตารางใหญ่

            pdf.DrawLine(Pens.Black, rcHdr.X, rcHdr.Y + 50, rcHdr.X + rcHdr.Width, rcHdr.Y + 50);
            pdf.DrawLine(Pens.Black, rcHdr.X, rcHdr.Y + 80, rcHdr.X + rcHdr.Width, rcHdr.Y + 80);
            pdf.DrawLine(Pens.Black, rcHdr.X + rcHdr.Width - 90, rcHdr.Y + 50, rcHdr.X + rcHdr.Width - 90, rcHdr.Y + rcHdr.Height); //เส้นตั้ง จำนวนเงิน
            pdf.DrawLine(Pens.Black, rcHdr.X + 260, rcHdr.Y, rcHdr.X + 260, rcHdr.Y + 50);                                          //  เส้นตั้ง ชื่อ - นามสกุล
            float xxx = rcHdr.X + rcHdr.Width - 90;
            float yyy = rcHdr.Y + rcHdr.Height;

            gapY        += 510;
            rcHdr.Width  = rcHdr.X + rcHdr.Width - 230;
            rcHdr.Height = 30;
            rcHdr.X      = gapX;
            rcHdr.Y      = gapY;
            pdf.DrawRectangle(Pens.Black, rcHdr);                                               // ตารางจำนวนเงิน ตัวอักษร

            pdf.DrawLine(Pens.Black, rcHdr.X + 452, rcHdr.Y + 15, rcHdr.X + 542, rcHdr.Y + 15); //เส้นแบ่ง รวมเงิน
            pdf.DrawLine(Pens.Black, rcHdr.X + 452, rcHdr.Y + 40, rcHdr.X + 542, rcHdr.Y + 40); //เส้นแบ่ง รวมเงิน

            rcHdr.Width  = 500 - xxx + gapX + 42;
            rcHdr.Height = 75;
            rcHdr.X      = xxx;
            rcHdr.Y      = yyy;
            pdf.DrawRectangle(Pens.Black, rcHdr);       // ตารางรวมเงิน ด้านล่าง
        }
Esempio n. 2
0
        void CreateDocumentVisualTree(C1PdfDocument pdf, FrameworkElement targetElement)
        {
            // set up to render
            var font = new Font("Courier", 14);
            var img  = new WriteableBitmap(CreateBitmap(targetElement));

            // go render
            bool firstPage = true;

            foreach (Stretch stretch in new Stretch[] { Stretch.Fill, Stretch.None, Stretch.Uniform, Stretch.UniformToFill })
            {
                // add page break
                if (!firstPage)
                {
                    pdf.NewPage();
                }
                firstPage = false;

                // set up to render
                var alignment = ContentAlignment.TopLeft;
                var rc        = PdfUtils.Inflate(pdf.PageRectangle, -72, -72);
                rc.Height /= 2;

                // render element as image
                pdf.DrawString("Element as Image, Stretch: " + stretch.ToString(), font, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, -20, -20);
                pdf.DrawImage(img, rc, alignment, stretch);
                pdf.DrawRectangle(Colors.Green, rc);
                rc = PdfUtils.Inflate(rc, +20, +20);
                pdf.DrawRectangle(Colors.Green, rc);

                // move to bottom of the page
                rc = PdfUtils.Offset(rc, 0, rc.Height + 20);

                // render element
                pdf.DrawString("Element as VisualTree, Stretch: " + stretch.ToString(), font, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, -20, -20);
                pdf.DrawElement(targetElement, rc, alignment, stretch);
                pdf.DrawRectangle(Colors.Green, rc);
                rc = PdfUtils.Inflate(rc, +20, +20);
                pdf.DrawRectangle(Colors.Green, rc);
            }
        }
Esempio n. 3
0
        static Rect RenderTableRow(C1PdfDocument pdf, Font font, Font hdrFont, Rect rcPage, Rect rc, string[] fields, DataRow dr)
        {
            // calculate cell width (same for all columns)
            Rect rcCell = rc;

            rcCell.Width  = rc.Width / fields.Length;
            rcCell.Height = 0;

            // calculate cell height (max of all columns)
            rcCell = PdfUtils.Inflate(rcCell, -4, 0);
            foreach (string field in fields)
            {
                string text   = dr[field].ToString();
                var    height = pdf.MeasureString(text, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }
            rcCell         = PdfUtils.Inflate(rcCell, 4, 0); // add 4 point margin
            rcCell.Height += 2;

            // break page if we have to
            if (rcCell.Bottom > rcPage.Bottom)
            {
                pdf.NewPage();
                rc       = RenderTableHeader(pdf, hdrFont, rcPage, fields);
                rcCell.Y = rc.Y;
            }

            // center vertically just to show how
            StringFormat fmt = new StringFormat();

            fmt.LineAlignment = VerticalAlignment.Center;

            // render data cells
            foreach (string field in fields)
            {
                // get content
                string text = dr[field].ToString();

                // set horizontal alignment
                double d;
                fmt.Alignment = (double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out d))
                    ? HorizontalAlignment.Right
                    : HorizontalAlignment.Left;

                // render cell
                pdf.DrawRectangle(Colors.LightGray, rcCell);
                rcCell = PdfUtils.Inflate(rcCell, -4, 0);
                pdf.DrawString(text, font, Colors.Black, rcCell, fmt);
                rcCell = PdfUtils.Inflate(rcCell, 4, 0);
                rcCell = PdfUtils.Offset(rcCell, rcCell.Width, 0);
            }

            // update rectangle and return it
            return(PdfUtils.Offset(rc, 0, rcCell.Height));
        }
        static void CreateDocumentPaperSizes(C1PdfDocument pdf)
        {
            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);
            Rect rc        = PdfUtils.PageRectangle(pdf);

            PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rc, rc, false);

            // create constant font and StringFormat objects
            Font         font = new Font("Tahoma", 18);
            StringFormat sf   = new StringFormat();

            sf.Alignment     = HorizontalAlignment.Center;
            sf.LineAlignment = VerticalAlignment.Center;

            // create one page with each paper size
            bool firstPage = true;

            foreach (PaperKind pk in Enum.GetValues(typeof(PaperKind)))
            {
                // Silverlight doesn't have Enum.GetValues
                //PaperKind pk = fi;

                // skip custom size
                if (pk == PaperKind.Custom)
                {
                    continue;
                }

                // add new page for every page after the first one
                if (!firstPage)
                {
                    pdf.NewPage();
                }
                firstPage = false;

                // set paper kind and orientation
                pdf.PaperKind = pk;
                pdf.Landscape = !pdf.Landscape;

                // draw some content on the page
                rc = PdfUtils.PageRectangle(pdf);
                rc = PdfUtils.Inflate(rc, -6, -6);
                string text = string.Format(Strings.StringFormatTwoArg,
                                            pdf.PaperKind, pdf.Landscape);
                pdf.DrawString(text, font, Colors.Black, rc, sf);
                pdf.DrawRectangle(Colors.Black, rc);
            }
            //foreach (var fi in typeof(PaperKind).GetTypeInfo().GetFields(BindingFlags.Static | BindingFlags.Public))
            //{

            //}
        }
Esempio n. 5
0
        //---------------------------------------------------------------------------------
        #region ** text

        static void CreateDocumentText(C1PdfDocument pdf)
        {
            // use landscape for more impact
            pdf.Landscape = true;

            // measure and show some text
            var text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
            var font = new Font("Times New Roman", 9, PdfFontStyle.Italic);

            // create StringFormat used to set text alignment and line spacing
            var fmt = new StringFormat();

            fmt.LineSpacing = -1.5; // 1.5 char height
            fmt.Alignment   = HorizontalAlignment.Center;

            // measure it
            var sz = pdf.MeasureString(text, font, 72 * 3, fmt);
            var rc = new Rect(pdf.PageRectangle.Width / 2, 72, sz.Width, sz.Height);

            rc = PdfUtils.Offset(rc, 72, 0);

            // draw a rounded frame
            rc = PdfUtils.Inflate(rc, 10, 10);
            pdf.FillRectangle(Colors.Black, rc, new Size(30, 30));
            pdf.DrawRectangle(new Pen(Colors.Red, 4), rc, new Size(30, 30));
            rc = PdfUtils.Inflate(rc, -10, -10);

            // draw the text
            pdf.DrawString(text, font, Colors.White, rc, fmt);

            // point in center for rotate the text
            rc = pdf.PageRectangle;
            var pt = new Point(rc.Location.X + rc.Width / 2, rc.Location.Y + rc.Height / 2);

            // rotate the string in small increments
            var step = 6;

            text = "PDF works in WPF!";
            for (int i = 0; i <= 360; i += step)
            {
                pdf.RotateAngle = i;
                font            = new Font("Courier New", 8 + i / 30.0, PdfFontStyle.Bold);
                byte b = (byte)(255 * (1 - i / 360.0));
                pdf.DrawString(text, font, Color.FromArgb(0xff, b, b, b), pt);
            }
        }
Esempio n. 6
0
        //---------------------------------------------------------------------------------
        #region ** graphics

        static void CreateDocumentGraphics(C1PdfDocument pdf)
        {
            // set up to draw
            Rect   rc   = new Rect(0, 0, 300, 200);
            string text = "Hello world of .NET Graphics and PDF.\r\nNice to meet you.";
            Font   font = new Font("Times New Roman", 12, PdfFontStyle.Italic | PdfFontStyle.Underline);

            // draw to pdf document
            int  penWidth = 0;
            byte penRGB   = 0;

            pdf.FillPie(Colors.Red, rc, 0, 20f);
            pdf.FillPie(Colors.Green, rc, 20f, 30f);
            pdf.FillPie(Colors.Blue, rc, 60f, 12f);
            pdf.FillPie(Colors.Orange, rc, -80f, -20f);
            for (float startAngle = 0; startAngle < 360; startAngle += 40)
            {
                Color penColor = Color.FromArgb(0xff, penRGB, penRGB, penRGB);
                Pen   pen      = new Pen(penColor, penWidth++);
                penRGB = (byte)(penRGB + 20);
                pdf.DrawArc(pen, rc, startAngle, 40f);
            }
            pdf.DrawRectangle(Colors.Red, rc);
            pdf.DrawString(text, font, Colors.Black, rc);

            // show a Bezier curve
            var pts = new Point[]
            {
                new Point(400, 100), new Point(420, 30),
                new Point(500, 140), new Point(530, 20),
            };

            // draw Bezier
            pdf.DrawBezier(new Pen(Colors.Blue, 4), pts[0], pts[1], pts[2], pts[3]);

            // show Bezier control points
            pdf.DrawLines(Colors.Gray, pts);
            foreach (Point pt in pts)
            {
                pdf.FillRectangle(Colors.Red, pt.X - 2, pt.Y - 2, 4, 4);
            }

            // title
            pdf.DrawString("Simple Bezier", font, Colors.Black, new Rect(500, 150, 100, 100));
        }
Esempio n. 7
0
        void CreateDocumentVisualTree(C1PdfDocument pdf, FrameworkElement targetElement)
        {
            // set up to render
            var font = new Font("Courier", 14);
            var img = new WriteableBitmap(CreateBitmap(targetElement));

            // go render
            bool firstPage = true;
            foreach (Stretch stretch in new Stretch[] { Stretch.Fill, Stretch.None, Stretch.Uniform, Stretch.UniformToFill })
            {
                // add page break
                if (!firstPage)
                {
                    pdf.NewPage();
                }
                firstPage = false;

                // set up to render
                var alignment = ContentAlignment.TopLeft;
                var rc = PdfUtils.Inflate(pdf.PageRectangle, -72, -72);
                rc.Height /= 2;

                // render element as image
                pdf.DrawString("Element as Image, Stretch: " + stretch.ToString(), font, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, -20, -20);
                pdf.DrawImage(img, rc, alignment, stretch);
                pdf.DrawRectangle(Colors.Green, rc);
                rc = PdfUtils.Inflate(rc, +20, +20);
                pdf.DrawRectangle(Colors.Green, rc);

                // move to bottom of the page
                rc = PdfUtils.Offset(rc, 0, rc.Height + 20);

                // render element
                pdf.DrawString("Element as VisualTree, Stretch: " + stretch.ToString(), font, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, -20, -20);
                pdf.DrawElement(targetElement, rc, alignment, stretch);
                pdf.DrawRectangle(Colors.Green, rc);
                rc = PdfUtils.Inflate(rc, +20, +20);
                pdf.DrawRectangle(Colors.Green, rc);
            }
        }
Esempio n. 8
0
        static void CreateDocumentTextFlow(C1PdfDocument pdf)
        {
            // load long string from resource file
            string text = Strings.ResourceNotFound;

            using (var sr = new StreamReader(typeof(BasicTextPage).GetTypeInfo().Assembly.GetManifestResourceStream("PdfSamples.Resources.flow.txt")))
            {
                text = sr.ReadToEnd();
            }
            text = text.Replace("\t", "   ");
            text = string.Format("{0}\r\n\r\n---oOoOoOo---\r\n\r\n{0}", text);

            // create pdf document
            pdf.DocumentInfo.Title = Strings.TextFlowDocumentTitle;

            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);
            Font bodyFont  = new Font("Tahoma", 9);
            Rect rcPage    = PdfUtils.PageRectangle(pdf);
            Rect rc        = PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rcPage, rcPage, false);

            rc.Y     += titleFont.Size + 6;
            rc.Height = rcPage.Height - rc.Y;

            // create two columns for the text
            Rect rcLeft = rc;

            rcLeft.Width  = rcPage.Width / 2 - 12;
            rcLeft.Height = 300;
            rcLeft.Y      = (rcPage.Y + rcPage.Height - rcLeft.Height) / 2;
            Rect rcRight = rcLeft;

            rcRight.X = rcPage.Right - rcRight.Width;

            // start with left column
            rc = rcLeft;

            // render string spanning columns and pages
            for (; ;)
            {
                // render as much as will fit into the rectangle
                rc = PdfUtils.Inflate(rc, -3, -3);
                int nextChar = pdf.DrawString(text, bodyFont, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, +3, +3);
                pdf.DrawRectangle(Colors.LightGray, rc);

                // break when done
                if (nextChar >= text.Length)
                {
                    break;
                }

                // get rid of the part that was rendered
                text = text.Substring(nextChar);

                // switch to right-side rectangle
                if (rc.Left == rcLeft.Left)
                {
                    rc = rcRight;
                }
                else // switch to left-side rectangle on the next page
                {
                    pdf.NewPage();
                    rc = rcLeft;
                }
            }
        }
        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);
        }
Esempio n. 10
0
        static Rect RenderTableRow(C1PdfDocument pdf, Font font, Font hdrFont, Rect rcPage, Rect rc, string[] fields, DataRow dr)
        {
            // calculate cell width (same for all columns)
            Rect rcCell = rc;
            rcCell.Width = rc.Width / fields.Length;
            rcCell.Height = 0;

            // calculate cell height (max of all columns)
            rcCell = PdfUtils.Inflate(rcCell, -4, 0);
            foreach (string field in fields)
            {
                string text = dr[field].ToString();
                var height = pdf.MeasureString(text, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }
            rcCell = PdfUtils.Inflate(rcCell, 4, 0); // add 4 point margin
            rcCell.Height += 2;

            // break page if we have to
            if (rcCell.Bottom > rcPage.Bottom)
            {
                pdf.NewPage();
                rc = RenderTableHeader(pdf, hdrFont, rcPage, fields);
                rcCell.Y = rc.Y;
            }

            // center vertically just to show how
            StringFormat fmt = new StringFormat();
            fmt.LineAlignment = VerticalAlignment.Center;

            // render data cells
            foreach (string field in fields)
            {
                // get content
                string text = dr[field].ToString();

                // set horizontal alignment
                double d;
                fmt.Alignment = (double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out d))
                    ? HorizontalAlignment.Right
                    : HorizontalAlignment.Left;

                // render cell
                pdf.DrawRectangle(Colors.LightGray, rcCell);
                rcCell = PdfUtils.Inflate(rcCell, -4, 0);
                pdf.DrawString(text, font, Colors.Black, rcCell, fmt);
                rcCell = PdfUtils.Inflate(rcCell, 4, 0);
                rcCell = PdfUtils.Offset(rcCell, rcCell.Width, 0);
            }

            // update rectangle and return it
            return PdfUtils.Offset(rc, 0, rcCell.Height);
        }
Esempio n. 11
0
        static void CreateDocumentTextFlow(C1PdfDocument pdf)
        {
            // load long string from resource file
            string text = "Resource not found...";
            using (var sr = new StreamReader(DataAccess.GetStream("flow.txt")))
            {
                text = sr.ReadToEnd();
            }
            text = text.Replace("\t", "   ");
            text = string.Format("{0}\r\n\r\n---oOoOoOo---\r\n\r\n{0}", text);

            // create pdf document
            pdf.DocumentInfo.Title = "Text Flow";

            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);
            Font bodyFont = new Font("Tahoma", 9);
            Rect rcPage = PdfUtils.PageRectangle(pdf);
            Rect rc = PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rcPage, rcPage, false);
            rc.Y += titleFont.Size + 6;
            rc.Height = rcPage.Height - rc.Y;

            // create two columns for the text
            Rect rcLeft = rc;
            rcLeft.Width = rcPage.Width / 2 - 12;
            rcLeft.Height = 300;
            rcLeft.Y = (rcPage.Y + rcPage.Height - rcLeft.Height) / 2;
            Rect rcRight = rcLeft;
            rcRight.X = rcPage.Right - rcRight.Width;

            // start with left column
            rc = rcLeft;

            // render string spanning columns and pages
            for (; ; )
            {
                // render as much as will fit into the rectangle
                rc = PdfUtils.Inflate(rc, -3, -3);
                int nextChar = pdf.DrawString(text, bodyFont, Colors.Black, rc);
                rc = PdfUtils.Inflate(rc, +3, +3);
                pdf.DrawRectangle(Colors.LightGray, rc);

                // break when done
                if (nextChar >= text.Length)
                {
                    break;
                }

                // get rid of the part that was rendered
                text = text.Substring(nextChar);

                // switch to right-side rectangle
                if (rc.Left == rcLeft.Left)
                {
                    rc = rcRight;
                }
                else // switch to left-side rectangle on the next page
                {
                    pdf.NewPage();
                    rc = rcLeft;
                }
            }
        }
Esempio n. 12
0
        static void CreateDocumentText(C1PdfDocument pdf)
        {
            // use landscape for more impact
            pdf.Landscape = true;

            // measure and show some text
            var text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
            var font = new Font("Times New Roman", 9, PdfFontStyle.Italic);

            // create StringFormat used to set text alignment and line spacing
            var fmt = new StringFormat();
            fmt.LineSpacing = -1.5; // 1.5 char height
            fmt.Alignment = HorizontalAlignment.Center;

            // measure it
            var sz = pdf.MeasureString(text, font, 72 * 3, fmt);
            var rc = new Rect(pdf.PageRectangle.Width / 2, 72, sz.Width, sz.Height);
            rc = PdfUtils.Offset(rc, 72, 0);

            // draw a rounded frame
            rc = PdfUtils.Inflate(rc, 10, 10);
            pdf.FillRectangle(Colors.Black, rc, new Size(30, 30));
            pdf.DrawRectangle(new Pen(Colors.Red, 4), rc, new Size(30, 30));
            rc = PdfUtils.Inflate(rc, -10, -10);

            // draw the text
            pdf.DrawString(text, font, Colors.White, rc, fmt);

            // now draw some text rotating about the center of the page
            rc = pdf.PageRectangle;
            rc = PdfUtils.Offset(rc, rc.Width / 2, rc.Height / 2);

            // build StringFormat used to rotate the text
            fmt = new StringFormat();

            // rotate the string in small increments
            var step = 6;
            text = "PDF works in WPF!";
            for (int i = 0; i <= 360; i += step)
            {
                fmt.Angle = i;
                font = new Font("Courier New", 8 + i / 30.0, PdfFontStyle.Bold);
                byte b = (byte)(255 * (1 - i / 360.0));
                pdf.DrawString(text, font, Color.FromArgb(0xff, b, b, b), rc, fmt);
            }
        }
Esempio n. 13
0
        static void CreateDocumentPaperSizes(C1PdfDocument pdf)
        {
            // add title
            Font titleFont = new Font("Tahoma", 24, PdfFontStyle.Bold);
            Rect rc = PdfUtils.PageRectangle(pdf);
            PdfUtils.RenderParagraph(pdf, pdf.DocumentInfo.Title, titleFont, rc, rc, false);

            // create constant font and StringFormat objects
            Font font = new Font("Tahoma", 18);
            StringFormat sf = new StringFormat();
            sf.Alignment = HorizontalAlignment.Center;
            sf.LineAlignment = VerticalAlignment.Center;

            // create one page with each paper size
            bool firstPage = true;
            foreach (var fi in typeof(PaperKind).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                // Silverlight/Phone doesn't have Enum.GetValues
                PaperKind pk = (PaperKind)fi.GetValue(null);

                // skip custom size
                if (pk == PaperKind.Custom) continue;

                // add new page for every page after the first one
                if (!firstPage) pdf.NewPage();
                firstPage = false;

                // set paper kind and orientation
                pdf.PaperKind = pk;
                pdf.Landscape = !pdf.Landscape;

                // draw some content on the page
                rc = PdfUtils.PageRectangle(pdf);
                rc = PdfUtils.Inflate(rc, -6, -6);
                string text = string.Format("PaperKind: [{0}];\r\nLandscape: [{1}];\r\nFont: [Tahoma 18pt]",
                    pdf.PaperKind, pdf.Landscape);
                pdf.DrawString(text, font, Colors.Black, rc, sf);
                pdf.DrawRectangle(Colors.Black, rc);
            }
        }
Esempio n. 14
0
        static void CreateDocumentGraphics(C1PdfDocument pdf)
        {
            // set up to draw
            Rect rc = new Rect(0, 0, 300, 200);
            string text = "Hello world of .NET Graphics and PDF.\r\nNice to meet you.";
            Font font = new Font("Times New Roman", 12, PdfFontStyle.Italic | PdfFontStyle.Underline);

            // draw to pdf document
            int penWidth = 0;
            byte penRGB = 0;
            pdf.FillPie(Colors.Red, rc, 0, 20f);
            pdf.FillPie(Colors.Green, rc, 20f, 30f);
            pdf.FillPie(Colors.Blue, rc, 60f, 12f);
            pdf.FillPie(Colors.Orange, rc, -80f, -20f);
            for (float startAngle = 0; startAngle < 360; startAngle += 40)
            {
                Color penColor = Color.FromArgb(0xff, penRGB, penRGB, penRGB);
                Pen pen = new Pen(penColor, penWidth++);
                penRGB = (byte)(penRGB + 20);
                pdf.DrawArc(pen, rc, startAngle, 40f);
            }
            pdf.DrawRectangle(Colors.Red, rc);
            pdf.DrawString(text, font, Colors.Black, rc);

            // show a Bezier curve
            var pts = new Point[]
            {
                new Point(400, 100), new Point(420,  30),
                new Point(500, 140), new Point(530,  20),
            };

            // draw Bezier
            pdf.DrawBezier(new Pen(Colors.Blue, 4), pts[0], pts[1], pts[2], pts[3]);

            // show Bezier control points
            pdf.DrawLines(Colors.Gray, pts);
            foreach (Point pt in pts)
            {
                pdf.FillRectangle(Colors.Red, pt.X - 2, pt.Y - 2, 4, 4);
            }

            // title
            pdf.DrawString("Simple Bezier", font, Colors.Black, new Rect(500, 150, 100, 100));
        }