Esempio n. 1
0
        public static PdfPage ConvertToDL8(this PdfPage page, UrlGenerator generator, int offset, string functionDirectory)
        {
            var type             = LabelTypes.DL8;
            var width            = 270;
            var height           = 182;
            var logoWidth        = 140;
            var logoOffsetLeft   = 35;
            var logoOffsetTop    = 160;
            var marginTop        = 41;
            var marginLeft       = 18;
            var marginRight      = 18;
            var marginBottom     = 10;
            var qrCodeSize       = 178;
            var qrCodeImageSize  = 500;
            var qrCodeOffsetTop  = 190;
            var qrCodeOffsetLeft = 80;

            gfx = XGraphics.FromPdfPage(page);

            var pen = new XPen(XColors.Black);

            var rectangles = GetRectangles(width, height, (int)type, marginTop, marginBottom, marginLeft, marginRight);

            gfx.DrawRectangles(pen, rectangles.ToArray());

            var totalSquaresAvailable = rectangles.Count;
            var numberOfSquresToPrint = generator.ToUri().Count;

            for (var i = 0; i < numberOfSquresToPrint; i++)
            {
                var squareToPrint = (offset + i) % totalSquaresAvailable;

                DrawQrCode(qrCodeImageSize, qrCodeSize, qrCodeOffsetLeft, qrCodeOffsetTop, rectangles[squareToPrint], generator.ToUri()[i], functionDirectory + iconPath);
                DrawImage(rectangles[squareToPrint], logoWidth, logoOffsetLeft, logoOffsetTop, functionDirectory + LogoImagePath);
            }

            return(page);
        }
Esempio n. 2
0
        private double PrintServicesListHeaderRow(XGraphics printer, double nextStartY)
        {
            nextStartY += 40;
            int headerRowHeight = 35;

            XFont  font  = new XFont("Times", 12, XFontStyle.Bold);
            XBrush brush = XBrushes.Black;

            XPen        strokePen = new XPen(XColor.FromArgb(100, 100, 100));
            XSolidBrush fillColor = new XSolidBrush(XColor.FromArgb(230, 230, 230));

            printer.DrawRectangles(strokePen, fillColor, new XRect[] {
                new XRect(COL1_START_X, nextStartY, COL1_WIDTH, headerRowHeight),
                new XRect(COL2_START_X, nextStartY, COL2_WIDTH, headerRowHeight)
            });

            double textY = nextStartY + (headerRowHeight * 7 / 10); // + printer.MeasureString("Description", font).Height;

            printer.DrawString("Description", font, brush, new XPoint(COL1_START_X + 10, textY));
            printer.DrawString("Amount", font, brush, new XPoint(COL2_START_X + 10, textY));

            return(nextStartY);
        }
Esempio n. 3
0
        private double PrintInvoiceRow(XGraphics printer, double startY, InvoiceLine invoiceRow, bool odd)
        {
            int topMargin = 5;
            int rowHeight = 15;

            XColor strokeColor = XColor.FromArgb(100, 100, 100);
            XPen   strokePen   = new XPen(strokeColor);

            XFont font = new XFont("Times", 10, XFontStyle.Regular);

            List <string> lines = new List <string>();

            string[] returnSplit = invoiceRow.Product.Name.Split("\n");

            List <string> breaks = returnSplit.ToList();

            foreach (string brr in breaks)
            {
                string        br = brr;
                StringBuilder sb = new StringBuilder();
                br = br.Replace("\n", " ");
                br = br.Replace("\r", " ");

                foreach (string s in br.Split(" "))
                {
                    XSize size = printer.MeasureString(sb.ToString() + s + " ", font);
                    if (size.Width > COL1_WIDTH - 10)
                    {
                        lines.Add(sb.ToString());
                        sb = new StringBuilder();
                        sb.Append("  ");
                    }
                    sb.Append(s).Append(" ");
                }

                if (sb.Length >= 1)
                {
                    lines.Add(sb.ToString());
                }
            }

            XRect r1 = new XRect(COL1_START_X, startY - 10, COL1_WIDTH, rowHeight * lines.Count + topMargin);
            XRect r2 = new XRect(COL2_START_X, startY - 10, COL2_WIDTH, rowHeight * lines.Count + topMargin);

            if (odd)
            {
                printer.DrawRectangles(strokePen, new XSolidBrush(XColor.FromArgb(230, 230, 230)), new XRect[] { r1, r2 });
            }
            else
            {
                printer.DrawRectangles(strokePen, new XRect[] { r1, r2 });
            }

            startY += topMargin;
            double yPos = startY; // + rowHeight - rowHeight * 2 / 5;

            foreach (string line in lines)
            {
                printer.DrawString(line, font, brush, new XPoint(COL1_START_X + 10, yPos));
                yPos += rowHeight;
            }

            startY += rowHeight * lines.Count;

            yPos = startY - rowHeight * lines.Count * 2 / 5 - 10;
            printer.DrawString(invoiceRow.getTotalstring(), font, brush, new XPoint(COL2_START_X + 10, yPos));

            return(startY);
        }
Esempio n. 4
0
        private void GenerateSummaryPage(XGraphics gfx, int firstIndex)
        {
            //======================================================================================================================================//
            //Add summary header
            var font       = new XFont("Calibri", 30.0, XFontStyle.Bold);
            var stringSize = gfx.MeasureString("SUMMARY", font);
            var rect       = new XRect(Margin, Margin, UsableWidth, font.GetHeight());

            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("SUMMARY", font, TextBrush, rect, XStringFormats.TopLeft);

            //======================================================================================================================================//
            //Add: Summary header boxes
            int bigBoxW    = (int)UsableWidth / 2,
                smallBoxW  = (int)UsableWidth / 5,
                startX     = (int)PageWidth / 2 - (bigBoxW + smallBoxW + smallBoxW) / 2,
                startY     = (int)rect.Location.Y + (int)rect.Height + 10,
                rectHeight = 25;

            XPen pen = XPens.Black;

            Rectangle[] rects =
            {
                //msgTextRect
                new Rectangle(new System.Drawing.Point(startX,                       startY), new System.Drawing.Size(bigBoxW,   rectHeight)),
                //amountTextRect
                new Rectangle(new System.Drawing.Point(startX + bigBoxW,             startY), new System.Drawing.Size(smallBoxW, rectHeight)),
                //durationTextRect
                new Rectangle(new System.Drawing.Point(startX + bigBoxW + smallBoxW, startY), new System.Drawing.Size(smallBoxW, rectHeight))
            };

            gfx.DrawRectangles(pen, rects);

            //======================================================================================================================================//
            //Add summary table
            font = new XFont("Calibri", 15.0, XFontStyle.Bold);
            var msgTextRect      = new XRect(rects[0].Location.X + 1, rects[0].Location.Y + 3, rects[0].Width - 2, rects[0].Height - 2);
            var amountTextRect   = new XRect(rects[1].Location.X + 1, rects[1].Location.Y + 3, rects[1].Width - 2, rects[1].Height - 2);
            var durationTextRect = new XRect(rects[2].Location.X + 1, rects[2].Location.Y + 3, rects[2].Width - 2, rects[2].Height - 2);

            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("Alarm text", font, TextBrush, msgTextRect, XStringFormats.TopLeft);
            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("Amount", font, TextBrush, amountTextRect, XStringFormats.TopLeft);
            CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString("Total duration", font, TextBrush, durationTextRect, XStringFormats.TopLeft);

            font = new XFont("Calibri", 11.0, XFontStyle.Bold);
            XRect loopRect;
            int   y = 1; //Maximum 26 then new page is needed

            for (int i = firstIndex; i < parent.mySummary.Count - 1; i++)
            {
                loopRect = new XRect(startX, startY + (rectHeight * y), bigBoxW, rectHeight);
                gfx.DrawRectangle(pen, loopRect);

                loopRect = new XRect(startX + 2, startY + (rectHeight * y) + 5, rects[0].Width - 2, rects[0].Height - 2);
                CreateTextFormatter(gfx, XParagraphAlignment.Left).DrawString(parent.mySummary[i].MsgText, font, TextBrush, loopRect, XStringFormats.TopLeft);

                loopRect = new XRect(startX + bigBoxW, startY + (rectHeight * y), smallBoxW, rectHeight);
                gfx.DrawRectangle(pen, loopRect);

                loopRect = new XRect(startX + bigBoxW + 1, startY + (rectHeight * y) + 5, rects[1].Width - 2, rects[1].Height - 2);
                CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString(parent.mySummary[i].Amount.ToString(), font, TextBrush, loopRect, XStringFormats.TopLeft);

                loopRect = new XRect(startX + bigBoxW + smallBoxW, startY + (rectHeight * y), smallBoxW, rectHeight);
                gfx.DrawRectangle(pen, loopRect);

                loopRect = new XRect(startX + bigBoxW + smallBoxW + 1, startY + (rectHeight * y) + 5, rects[2].Width - 2, rects[2].Height - 2);
                CreateTextFormatter(gfx, XParagraphAlignment.Center).DrawString(parent.mySummary[i].StopDuration.ToString(@"hh\:mm\:ss"), font, TextBrush, loopRect, XStringFormats.TopLeft);
                y++;
            }
        }