Ejemplo n.º 1
0
        internal static void Generate_receipt(List <string> SelectedImages, string ImageFileName, string taxinvoicenumber)
        {
            ///Create a pdf document
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();

            //Set the margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();

            PdfMargins margin = new PdfMargins();

            margin.Top    = InPoints(0.5f);//unitCvtr.ConvertUnits(MARGINTOP_BOTTOM, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;

            //Create one page
            PdfPageBase page = doc.Pages.Add(new SizeF(InPoints(float.Parse(ConfigurationManager.AppSettings["ReceiptWidth"])),
                                                       InPoints(float.Parse(ConfigurationManager.AppSettings["ReceiptHeight"]))), margin);
            //PdfFont font12 = new PdfFont(PdfFontFamily.Helvetica, 12f);
            PdfFont font10 = new PdfFont(PdfFontFamily.Helvetica, 10f);
            //PdfFont font8 = new PdfFont(PdfFontFamily.Helvetica, 8f);
            PdfSolidBrush   brush1          = new PdfSolidBrush(Color.Black);
            PdfStringFormat leftAlignment   = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            PdfStringFormat rightAlignment  = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            string total = Math.Round(
                (((Convert.ToDouble(ConfigurationManager.AppSettings["CostValue" + Globals.PrintSelection.ToString()]) *
                   SelectedImages.Count) * Convert.ToDouble(ConfigurationManager.AppSettings["GSTValue"]) /
                  100) +
                 (Convert.ToDouble(ConfigurationManager.AppSettings["CostValue" + Globals.PrintSelection.ToString()]) * SelectedImages.Count)
                ), 2
                ).ToString();

            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line1"], font10, brush1, page.Canvas.ClientSize.Width, 10, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line2"] + taxinvoicenumber, font10, brush1, page.Canvas.ClientSize.Width, 25, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line3"] + SelectedImages.Count + "/-", font10, brush1, page.Canvas.ClientSize.Width, 40, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line4"] + ConfigurationManager.AppSettings["CostValue"] + "/-"
                                   , font10, brush1, page.Canvas.ClientSize.Width, 55, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line5"] +
                                   ConfigurationManager.AppSettings["GSTValue"] + "%", font10, brush1, page.Canvas.ClientSize.Width, 70, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line6"], font10, brush1, page.Canvas.ClientSize.Width, 85, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line7"] + total + "/-", font10, brush1, page.Canvas.ClientSize.Width, 100, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line8"], font10, brush1, page.Canvas.ClientSize.Width, 120, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line9"], font10, brush1, page.Canvas.ClientSize.Width, 130, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line10"], font10, brush1, page.Canvas.ClientSize.Width, 140, rightAlignment);
            page.Canvas.DrawString(ConfigurationManager.AppSettings["Line11"], font10, brush1, page.Canvas.ClientSize.Width, 155, rightAlignment);


            //Save the document
            doc.SaveToFile(Globals.receiptDir + ImageFileName);
            doc.SaveToFile(ConfigurationManager.AppSettings["ReceiptBackupDir"] + "\\" + ImageFileName);
            doc.Close();

            //Launch the Pdf file
            if (ConfigurationManager.AppSettings["Mode"] == "Diagnostic")
            {
                logger.Log(NLog.LogLevel.Info, "Inside Generate_receipt function.");
                PDFDocumentViewer(Globals.receiptDir + ImageFileName);
            }
        }
Ejemplo n.º 2
0
        internal static void SetPageMarginGeneratePDF_ImageRatio4x3_A5(string ImageFileName, PdfImage img1, PdfImage img2,
                                                                       Globals.AspectRatio aspectRatioImage1 = Globals.AspectRatio.S4x3, Globals.AspectRatio aspectRatioImage2 = Globals.AspectRatio.S4x3)
        {
            float MARGINTOP_BOTTOM = 0.75f; float MARGINLEFT_RIGHT = 1.25f;
            float DISTANCE_BTW_IMAGES = 0.5F;

            ///Create a pdf document
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();

            //Set the margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = PrintIO.InPoints(MARGINTOP_BOTTOM);//unitCvtr.ConvertUnits(MARGINTOP_BOTTOM, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            //TODO: Add margins in global settings xml file.
            margin.Left  = PrintIO.InPoints(MARGINLEFT_RIGHT); //unitCvtr.ConvertUnits(MARGINLEFT_RIGHT, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            //Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float A4Height = unitCvtr.ConvertUnits(PdfPageSize.A4.Height, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter);
            float A4Width  = unitCvtr.ConvertUnits(PdfPageSize.A4.Width, PdfGraphicsUnit.Point, PdfGraphicsUnit.Centimeter);

            //After margin
            float A4PostMarginWidth = PdfPageSize.A4.Width - (margin.Left * 2); // left,right margins

            //Adjust width, height with 4:3 ratio in PDF points :
            float A4PostMarginWidthPts4x3  = PdfPageSize.A4.Width - (margin.Left * 2); // left,right margins
            float A4PostMarginHeightPts4x3 = A4PostMarginWidthPts4x3 * 0.75f;          // height = 3/4 * width


            //TransformText(page);
            DrawImagesInPage_A5(img1, img2, page, A4PostMarginWidthPts4x3, A4PostMarginHeightPts4x3,
                                DISTANCE_BTW_IMAGES, aspectRatioImage1, aspectRatioImage2);
            //TransformImage(page);

            //Save the document
            doc.SaveToFile(ImageFileName);
            doc.Close();

            if (ConfigurationManager.AppSettings["Mode"] == "Diagnostic")
            {
                PrintIO.PDFDocumentViewer(ImageFileName);
            }
        }
Ejemplo n.º 3
0
        internal static void SetPageMarginGeneratePDF_ImageRatio4x3_Passport(string ImageFileName, PdfImage img1)
        {
            float MARGINTOP_BOTTOM = 1.25f; float MARGINLEFT_RIGHT = 1.5f;
            float DISTANCE_BTW_IMAGES = 0.5F;

            ///Create a pdf document
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();

            //Set the margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = PrintIO.InPoints(MARGINTOP_BOTTOM);//unitCvtr.ConvertUnits(MARGINTOP_BOTTOM, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            //TODO: Add margins in global settings xml file.
            margin.Left  = PrintIO.InPoints(MARGINLEFT_RIGHT); //unitCvtr.ConvertUnits(MARGINLEFT_RIGHT, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            //Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);


            //divde A4 210mm page to 6 parts to get 35mm image width
            float passport_35x45_width  = PdfPageSize.A4.Width / 6;     // left,right margins
            float passport_35x45_height = passport_35x45_width * 1.28f; // calc height image size = 4.5 x 3.5 cm, width is known

            //Passport size image
            float postcard_101_1x152_4_width  = PdfPageSize.A4.Width / 2.08f;      //101.1
            float postcard_101_1x152_4_height = postcard_101_1x152_4_width * 1.5f; //151.6


            //Firt row
            float DistanceBtwSecondImg = passport_35x45_width + PrintIO.InPoints(1f);

            DrawImageInFrame_wxh_Passport(img1, page, 0, 0, passport_35x45_width, passport_35x45_height);
            DrawImageInFrame_wxh_Passport(img1, page, DistanceBtwSecondImg, 0, passport_35x45_width, passport_35x45_height);
            DrawImageInFrame_wxh_Passport(img1, page, 2 * DistanceBtwSecondImg, 0, passport_35x45_width, passport_35x45_height);
            DrawImageInFrame_wxh_Passport(img1, page, 3 * DistanceBtwSecondImg, 0, passport_35x45_width, passport_35x45_height);

            //second row
            float DistanceBtwSecondRowofImg = passport_35x45_height + PrintIO.InPoints(1f);

            DrawImageInFrame_wxh_Passport(img1, page, 0, DistanceBtwSecondRowofImg, passport_35x45_width, passport_35x45_height);
            DrawImageInFrame_wxh_Passport(img1, page, DistanceBtwSecondImg, DistanceBtwSecondRowofImg, passport_35x45_width, passport_35x45_height);
            DrawImageInFrame_wxh_Passport(img1, page, 2 * DistanceBtwSecondImg, DistanceBtwSecondRowofImg, passport_35x45_width, passport_35x45_height);
            DrawImageInFrame_wxh_Passport(img1, page, 3 * DistanceBtwSecondImg, DistanceBtwSecondRowofImg, passport_35x45_width, passport_35x45_height);

            //third row
            //float DistanceBtwThirdRowofImg = 2 * (passport_35x45_height + PrintIO.InPoints(1f));
            //DrawImageInFrame_wxh_Passport(img1, page, 0, DistanceBtwThirdRowofImg, postcard_101_1x152_4_width, postcard_101_1x152_4_height);

            //Save the document
            doc.SaveToFile(ImageFileName);
            doc.Close();

            if (ConfigurationManager.AppSettings["Mode"] == "Diagnostic")
            {
                PrintIO.PDFDocumentViewer(ImageFileName);
            }

            ////Launch the Pdf file
            //if (System.Diagnostics.Debugger.IsAttached)
            //    PDFDocumentViewer( ImageFileName);
        }