Ejemplo n.º 1
0
        public static void PrintRecipts(ReceiptHeader header, ReceiptFooter footer, ReceiptItemTotal itemTotals, ReceiptDetails details, List <ReceiptItemDetails> itemDetail)
        {
            //Exporting to PDF
            //string folderPath = "c:\\pdf\\";
            //if ( !Directory.Exists (folderPath) )
            //{
            //    Directory.CreateDirectory (folderPath);
            //}
            using (FileStream stream = new FileStream(/*Application.CommonAppDataPath +*/ "\\reciptsPrint.pdf", FileMode.Create))
            {
                //   System.Console.WriteLine(Application.CommonAppDataPath);

                Document pdfDoc = new Document(new Rectangle(225, 5000), 10f, 10f, 10f, 0f);
                PdfWriter.GetInstance(pdfDoc, stream);
                pdfDoc.Open();
                //Header
                Paragraph p = new Paragraph(header.StoreName + "\n")
                {
                    Alignment = PdfAppearance.ALIGN_CENTER
                };
                p.Add(header.StoreAddress + "\n");
                p.Add(header.StoreCity + "\n");
                p.Add(header.StorePhoneNo + "\n");
                p.Add(header.StoreGST + "\n");
                p.Add(PrintLine.DotedLine);
                p.Add(header.InvoiceTitle + "\n");
                p.Add(PrintLine.DotedLine);
                pdfDoc.Add(p);
                //Details
                Paragraph dP = new Paragraph
                {
                    //dP.Alignment = PdfAppearance.ALIGN_CENTER;
                    details.Employee + "\n",
                    details.BillNo + "\n",
                    details.BillDate + "\n",
                    details.BillTime + "\n",
                    details.CustomerName + "\n",
                    PrintLine.DotedLine,
                    details.ItemLine1 + "\n",
                    details.ItemLine2 + "\n",
                    details.ItemLine3 + "\n",
                    PrintLine.DotedLine,
                    "\n"
                };
                pdfDoc.Add(dP);
                //ItemDetails

                Paragraph ip = new Paragraph();
                // ip.Alignment = PdfAppearance.ALIGN_CENTER;
                double gstPrice   = 0.00;
                double basicPrice = 0.00;
                string tab        = "    ";
                foreach (ReceiptItemDetails itemDetails in itemDetail)
                {
                    if (itemDetails != null)
                    {
                        ip.Add(itemDetails.SKU_Description + "\n");
                        ip.Add(itemDetails.HSN + tab + tab + itemDetails.MRP + tab + tab);
                        ip.Add(itemDetails.QTY + tab + tab + itemDetails.Discount + "\n");
                        ip.Add(itemDetails.GSTPercentage + "%" + tab + tab + itemDetails.GSTAmount + tab + tab);
                        ip.Add(itemDetails.GSTPercentage + "%" + tab + tab + itemDetails.GSTAmount + "\n");
                        gstPrice   += Double.Parse(itemDetails.GSTAmount);
                        basicPrice += Double.Parse(itemDetails.BasicPrice);
                    }
                }
                ip.Add("\n" + PrintLine.DotedLine);
                ip.Add("Total: " + itemTotals.TotalItem + tab + tab + tab + itemTotals.NetAmount + "\n");
                ip.Add("item(s): " + itemTotals.ItemCount + tab + "Net Amount:" + tab + itemTotals.NetAmount + "\n");
                ip.Add(PrintLine.DotedLine);
                ip.Add("Tender\n Paid Amount:\t\t Rs. " + itemTotals.CashAmount);
                ip.Add("\n" + PrintLine.DotedLine);
                ip.Add("Basic Price:\t\t" + basicPrice);
                ip.Add("\nCGST:\t\t" + gstPrice);
                ip.Add("\nSGST:\t\t" + gstPrice + "\n");
                //ip.Add (PrintLine.DotedLine);
                pdfDoc.Add(ip);
                //Footer
                Paragraph foot = new Paragraph(PrintLine.DotedLine)
                {
                    Alignment = PdfAppearance.ALIGN_CENTER
                };
                foot.Add(footer.FirstMessage + "\n");
                foot.Add(PrintLine.DotedLine);
                foot.Add(footer.ThanksMessage + "\n");
                foot.Add(footer.LastMessage + "\n");
                foot.Add(PrintLine.DotedLine);
                foot.Add("\n");// Just to Check;
                pdfDoc.Add(foot);
                pdfDoc.NewPage();

                pdfDoc.Close();

                stream.Close();
                // Create an instance of the Printer
                IPrinter printer = new Printer();
                // Print the file
                //TODO: enebale it printer.PrintRawFile(ViewModel.UtilOps.PrinterName, Application.CommonAppDataPath + "\\reciptsPrint.pdf");
            }
        }
Ejemplo n.º 2
0
        public static void PrintRecipts(ReceiptHeader header, ReceiptFooter footer, ReceiptItemTotal itemTotals, ReceiptDetails details, ReceiptItemDetails itemDetails)
        {
            //Exporting to PDF
            string folderPath = "D:\\pdf\\";

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }
            using (FileStream stream = new FileStream(/*Application.CommonAppDataPath + */ "\\reciptsPrint.pdf", FileMode.Create))
            {
                Document pdfDoc = new Document(PageSize.A6, 10f, 10f, 10f, 0f);
                PdfWriter.GetInstance(pdfDoc, stream);
                pdfDoc.Open();
                //Header
                Paragraph p = new Paragraph(header.StoreName)
                {
                    Alignment = PdfAppearance.ALIGN_CENTER
                };
                p.Add(header.StoreAddress + "\n");
                p.Add(header.StoreCity + "\n");
                p.Add(header.StorePhoneNo + "\n");
                p.Add(header.StoreGST + "\n");
                p.Add(PrintLine.DotedLine);
                p.Add(header.InvoiceTitle + "\n");
                p.Add(PrintLine.DotedLine);
                pdfDoc.Add(p);
                //Details
                Paragraph dP = new Paragraph
                {
                    details.Employee + "\n",
                    details.BillNo + "\n",
                    details.BillDate + "\n",
                    details.BillTime + "\n",
                    details.CustomerName + "\n",
                    PrintLine.DotedLine,
                    details.ItemLine1 + "\n",
                    details.ItemLine2 + "\n",
                    details.ItemLine3 + "\n",
                    PrintLine.DotedLine,
                    "\n"
                };
                pdfDoc.Add(dP);
                //ItemDetails
                //TODO: Need to iterate for Each Item
                Paragraph ip = new Paragraph
                {
                    itemDetails.SKU_Description + "\n",
                    itemDetails.HSN + "\t" + itemDetails.MRP + "\t",
                    itemDetails.QTY + "\t" + itemDetails.Discount + "\n",
                    itemDetails.GSTPercentage + "\t" + itemDetails.GSTAmount + "\t",
                    itemDetails.GSTPercentage + "\t" + itemDetails.GSTAmount + "\n",
                    PrintLine.DotedLine,
                    "Total: " + itemTotals.TotalItem + "\t\t\t" + itemTotals.NetAmount + "\n",

                    "item(s): " + itemTotals.ItemCount + "\tNet Amount:\t" + itemTotals.NetAmount + "\n",
                    PrintLine.DotedLine,
                    "Tender\n Cash Amount:\t\t Rs. " + itemTotals.CashAmount,
                    PrintLine.DotedLine
                };
                double gstPrice = 0.00;    //TODO: Add Item Price
                ip.Add("Basic Price:\t\t" + itemDetails.BasicPrice);
                ip.Add("CGST:\t\t" + gstPrice);
                ip.Add("SGST:\t\t" + gstPrice);
                ip.Add(PrintLine.DotedLine);

                pdfDoc.Add(ip);
                //Footer
                Paragraph foot = new Paragraph(PrintLine.DotedLine)
                {
                    footer.FirstMessage,
                    PrintLine.DotedLine,
                    footer.ThanksMessage,
                    footer.LastMessage,
                    PrintLine.DotedLine,
                    "\n"// Just to Check;
                };
                pdfDoc.Add(foot);
                pdfDoc.Close();
                stream.Close();

                string PrinterName = "Microsoft Print to PDF";
                // Create an instance of the Printer
                IPrinter printer = new Printer();
                // Print the file
                printer.PrintRawFile(PrinterName, /*Application.CommonAppDataPath +*/ "\\reciptsPrint.pdf");
                // printer.PrintRawFile()
            }
        }