Ejemplo n.º 1
0
		/// <summary>
		/// Creates a New Page for the Pdf Document
		/// </summary>
		/// <returns>
		/// 
		/// </returns>
		public PdfPage NewPage()
		{
			PdfPage p=new PdfPage();
			p.PdfDocument=this;
			return p;
		}
Ejemplo n.º 2
0
        public Stream GenerateSelectedTasksPDF(IEnumerable <SelectedTask> selectedTasks, ReportInfo reportInfo)
        {
            int            countSelectedTasks = selectedTasks.Count();
            int            totalNoiseDosage   = selectedTasks.Sum(x => x.Percentage);
            NoiseLevelEnum noiseLevelEnum     = _noiseLevelService.CalculateNoiseLevelEnum(totalNoiseDosage);
            Color          noiseLevelColor    = GetColorForNoiseLevel(noiseLevelEnum);
            DataTable      dataTable          = GenerateDataTable(selectedTasks);


            // Starting instantiate the document.
            // Remember to set the Docuement Format. In this case, we specify width and height.
            PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.A4_Horizontal);

            // Now we create a Table with lines likt the number of selected tasks, 6 columns and 4 points of Padding.
            PdfTable myPdfTable = myPdfDocument.NewTable(new Font("Verdana", 12), countSelectedTasks, 6, 4);

            // Importing datas from the datatables... (also column names for the headers!)
            myPdfTable.ImportDataTable(dataTable);

            // Now we set our Graphic Design: Colors and Borders...
            myPdfTable.HeadersRow.SetColors(Color.FromRgb(255, 255, 255), Color.FromRgb(0, 0, 255));
            myPdfTable.SetColors(Color.FromRgb(0, 0, 0), Color.FromRgb(255, 255, 255), Color.FromRgb(0, 255, 255));
            myPdfTable.SetBorders(Color.FromRgb(0, 0, 0), 1, BorderType.CompleteGrid);

            // With just one method we can set the proportional width of the columns.
            // It's a "percentage like" assignment, but the sum can be different from 100.
            myPdfTable.SetColumnsWidth(new int[] { 90, 25, 45, 20, 20, 10 });

            // Now we set some alignment... for the whole table and then, for a column.
            myPdfTable.SetContentAlignment(ContentAlignment.MiddleCenter);
            foreach (PdfColumn pdfColumn in myPdfTable.Columns)
            {
                pdfColumn.SetContentAlignment(ContentAlignment.MiddleLeft);
            }

            // Here we start the loop to generate the table...
            while (!myPdfTable.AllTablePagesCreated)
            {
                // we create a new page to put the generation of the new TablePage:
                PdfPage newPdfPage = myPdfDocument.NewPage();

                // LAKHA
                PdfArea      pdfArea   = new PdfArea(myPdfDocument, 48, 95, 750, 670);
                PdfTablePage taskTable = myPdfTable.CreateTablePage(pdfArea);

                // we also put a Label
                PdfTextArea reportTitle = new PdfTextArea(new Font("Verdana", 26, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                          , new PdfArea(myPdfDocument, 48, 20, 595, 60), ContentAlignment.TopLeft, ReportResource.ReportTitle);

                // LAKHA - Status
                PdfTextArea statusText = new PdfTextArea(new Font("Verdana", 14, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                         , new PdfArea(myPdfDocument, 48, taskTable.CellArea(taskTable.LastRow, 6 - 1).BottomRightCornerY + 10, 595, 60), ContentAlignment.TopLeft,
                                                         _noiseLevelService.GetNoiseLevelStatusText(noiseLevelEnum));

                // LAKHA - Total prosent
                PdfRectangle summaryBackground = new PdfArea(myPdfDocument, 635, taskTable.CellArea(taskTable.LastRow, 6 - 1).BottomRightCornerY + 10, 165, 45).ToRectangle(noiseLevelColor, noiseLevelColor);
                PdfTextArea  summary           = new PdfTextArea(new Font("Verdana", 26, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                                 , new PdfArea(myPdfDocument, 640, taskTable.CellArea(taskTable.LastRow, 6 - 1).BottomRightCornerY + 20, 595, 60), ContentAlignment.TopLeft,
                                                                 string.Format(ReportResource.TotalPercentageFormatString, totalNoiseDosage));

                // nice thing: we can put all the objects in the following lines, so we can have
                // a great control of layer sequence...
                newPdfPage.Add(taskTable);
                newPdfPage.Add(reportTitle);
                newPdfPage.Add(statusText);
                newPdfPage.Add(summaryBackground);
                newPdfPage.Add(summary);

                // Info from report input window
                PdfTextArea reportPlant = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                          , new PdfArea(myPdfDocument, 48, 50, 595, 60), ContentAlignment.TopLeft, string.Format(ReportResource.PlantFormatString, reportInfo.Plant));
                PdfTextArea reportCreatedBy = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                              , new PdfArea(myPdfDocument, 650, 50, 595, 60), ContentAlignment.TopLeft, string.Format(ReportResource.UserFormatString, reportInfo.CreatedBy));

                PdfTextArea reportProfession = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                               , new PdfArea(myPdfDocument, 48, 65, 595, 60), ContentAlignment.TopLeft, string.Format(ReportResource.ProfessionFormatString, reportInfo.Group));
                PdfTextArea reportDate = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                         , new PdfArea(myPdfDocument, 650, 65, 595, 60), ContentAlignment.TopLeft, string.Format(ReportResource.DateFormatString, (reportInfo.Date.HasValue) ? reportInfo.Date.Value.ToString("dd.MM.yyyy") : string.Empty));

                PdfTextArea reportComment = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.FromRgb(0, 0, 0)
                                                            , new PdfArea(myPdfDocument, 48, 80, 700, 60), ContentAlignment.TopLeft, string.Format(ReportResource.CommentFormatString, reportInfo.Comment));

                newPdfPage.Add(reportPlant);
                newPdfPage.Add(reportCreatedBy);
                newPdfPage.Add(reportProfession);
                newPdfPage.Add(reportDate);
                newPdfPage.Add(reportComment);


                // LAKHA - Add footnotes...
                const int widthOfFootnote = 750;
                Font      footnoteFont    = new Font("Verdana", 9, FontStyle.Regular);
                double    posY            = statusText.PdfArea.BottomRightCornerY + 3;

                foreach (string footNoteText in reportInfo.Footnotes)
                {
                    int heightOfFootnote = 10;

                    if (footNoteText.Length > 380)
                    {
                        heightOfFootnote = heightOfFootnote * 3;
                    }
                    else if (footNoteText.Length > 160)
                    {
                        heightOfFootnote = heightOfFootnote * 2;
                    }

                    PdfArea     pdfAreaForText = new PdfArea(myPdfDocument, 48, posY, widthOfFootnote, heightOfFootnote);
                    PdfTextArea footNote       = new PdfTextArea(footnoteFont, Color.FromRgb(0, 0, 0), pdfAreaForText, ContentAlignment.TopLeft, string.Format("* {0}", footNoteText));
                    newPdfPage.Add(footNote);

                    posY = footNote.PdfArea.BottomRightCornerY + 2;
                }

                // we save each generated page before start rendering the next.
                newPdfPage.SaveToDocument();
            }


            // Finally we save the docuement...
            Stream memoryStream = new MemoryStream();

            myPdfDocument.SaveToStream(memoryStream);
            memoryStream.Seek(0, SeekOrigin.Begin);

            return(memoryStream);
        }
    protected void btnprint_click(object sender, EventArgs e)
    {
        try
        {
            int RowCheckedCnt = 0;
            if (grdBarcode.Rows.Count > 0)
            {
                foreach (GridViewRow row in grdBarcode.Rows)
                {
                    CheckBox cbsel = (CheckBox)row.FindControl("chkenbl");
                    if (cbsel.Checked == true)
                    {
                        RowCheckedCnt++;
                    }
                }
            }
            PdfDocument          mydoc = new PdfDocument(PdfDocumentFormat.InCentimeters(24, 30));
            Gios.Pdf.PdfDocument mypdf = new Gios.Pdf.PdfDocument(PdfDocumentFormat.A4);

            Gios.Pdf.PdfPage mypdfpage   = mydoc.NewPage();
            Font             Fontsmall   = new Font("Times New Roman", 10, FontStyle.Regular);
            Font             Fontbold    = new Font("Book Antique", 10, FontStyle.Bold);
            Font             Fontnormal  = new Font("Book Antique", 10, FontStyle.Regular);
            Font             fontCoverNo = new Font("IDAutomationHC39M", 10, FontStyle.Bold);

            List <string> Acc_No = new List <string>();
            mypdfpage = mydoc.NewPage();
            string  collegename = "";
            string  address1    = "";
            string  address2    = "";
            string  address3    = "";
            string  PhNo        = "";
            string  faxno       = "";
            string  colquery    = "select collname,address1,address2,address3,phoneno,faxno from collinfo where college_code='" + ddl_collegename.SelectedItem.Value + "'";
            DataSet ds1         = d2.select_method_wo_parameter(colquery, "Text");
            if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
            {
                collegename = Convert.ToString(ds1.Tables[0].Rows[0]["collname"]);
                address1    = Convert.ToString(ds1.Tables[0].Rows[0]["address1"]);
                address2    = Convert.ToString(ds1.Tables[0].Rows[0]["address2"]);
                address3    = Convert.ToString(ds1.Tables[0].Rows[0]["address3"]);
                PhNo        = Convert.ToString(ds1.Tables[0].Rows[0]["phoneno"]);
                faxno       = Convert.ToString(ds1.Tables[0].Rows[0]["faxno"]);
            }
            PdfTextArea ptc = new PdfTextArea(Fontbold, System.Drawing.Color.Black,
                                              new PdfArea(mydoc, 140, 50, 400, 30), System.Drawing.ContentAlignment.MiddleCenter, collegename);
            mypdfpage.Add(ptc);

            PdfTextArea ptc1 = new PdfTextArea(Fontbold, System.Drawing.Color.Black,
                                               new PdfArea(mydoc, 125, 65, 400, 30), System.Drawing.ContentAlignment.MiddleCenter, address1 + "," + address2 + "," + address3);
            mypdfpage.Add(ptc1);
            PdfTextArea ptc2 = new PdfTextArea(Fontbold, System.Drawing.Color.Black,
                                               new PdfArea(mydoc, 130, 80, 400, 30), System.Drawing.ContentAlignment.MiddleCenter, PhNo + "," + faxno);
            mypdfpage.Add(ptc2);

            int SpreadCheckCount = 0;
            if (RowCheckedCnt > 30)
            {
                SpreadCheckCount = RowCheckedCnt / 2;
            }
            if (RowCheckedCnt < 30)
            {
                SpreadCheckCount = RowCheckedCnt;
            }

            Gios.Pdf.PdfTable table = mydoc.NewTable(Fontsmall, SpreadCheckCount + 1, 5, 1);

            table.SetBorders(Color.Black, 1, BorderType.CompleteGrid);
            table.VisibleHeaders = false;
            table.Cell(0, 0).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 0).SetContent("Acc No");
            table.Cell(0, 0).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 0).SetFont(Fontbold);
            table.Cell(0, 1).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 1).SetContent("Title");
            table.Cell(0, 1).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 1).SetFont(Fontbold);
            table.Cell(0, 2).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 2).SetContent("Author");
            table.Cell(0, 2).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 2).SetFont(Fontbold);
            table.Cell(0, 3).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 3).SetContent("Class No");
            table.Cell(0, 3).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 3).SetFont(Fontbold);
            table.Cell(0, 4).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 4).SetContent("Bar code");
            table.Cell(0, 4).SetContentAlignment(ContentAlignment.MiddleCenter);
            table.Cell(0, 4).SetFont(Fontbold);
            table.Columns[0].SetWidth(50);
            table.Columns[0].SetCellPadding(9);
            table.Columns[1].SetWidth(200);
            table.Columns[1].SetCellPadding(9);
            table.Columns[2].SetWidth(150);
            table.Columns[2].SetCellPadding(9);
            table.Columns[3].SetWidth(80);
            table.Columns[3].SetCellPadding(9);
            table.Columns[4].SetWidth(100);
            table.Columns[4].SetCellPadding(9);
            int img_pos = 212;
            int TR      = 1;
            //for (int dsrow = 0; dsrow < SpreadCheckCount; dsrow++)
            if (SpreadCheckCount > 0)
            {
                foreach (GridViewRow row in grdBarcode.Rows)
                {
                    CheckBox cbsel  = (CheckBox)row.FindControl("chkenbl");
                    int      RowCnt = Convert.ToInt32(row.RowIndex);
                    if (cbsel.Checked == true)
                    {
                        string accNo      = Convert.ToString(grdBarcode.Rows[RowCnt].Cells[2].Text);
                        string title      = Convert.ToString(grdBarcode.Rows[RowCnt].Cells[3].Text);
                        string author     = Convert.ToString(grdBarcode.Rows[RowCnt].Cells[4].Text);
                        string classNo    = Convert.ToString(grdBarcode.Rows[RowCnt].Cells[7].Text);
                        string LibBarCode = Convert.ToString(grdBarcode.Rows[RowCnt].Cells[17].Text);

                        string barCode = LibBarCode;
                        System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();

                        table.Cell(TR, 0).SetContentAlignment(ContentAlignment.MiddleCenter);
                        table.Cell(TR, 0).SetCellPadding(13);
                        table.Cell(TR, 0).SetContent(Convert.ToString(accNo));
                        table.Cell(TR, 1).SetContentAlignment(ContentAlignment.MiddleCenter);
                        table.Cell(TR, 1).SetCellPadding(13);
                        table.Cell(TR, 1).SetContent(Convert.ToString(title));
                        table.Cell(TR, 2).SetContentAlignment(ContentAlignment.MiddleCenter);
                        table.Cell(TR, 2).SetCellPadding(13);
                        table.Cell(TR, 2).SetContent(Convert.ToString(author));
                        table.Cell(TR, 3).SetContentAlignment(ContentAlignment.MiddleCenter);
                        table.Cell(TR, 3).SetCellPadding(13);
                        table.Cell(TR, 3).SetContent(Convert.ToString(classNo));

                        using (Bitmap bitMap = new Bitmap(accNo.Length * 40, 80))
                        {
                            using (Graphics graphics = Graphics.FromImage(bitMap))
                            {
                                Font       oFont      = new Font("IDAutomationHC39M", 16);
                                PointF     point      = new PointF(2f, 2f);
                                SolidBrush blackBrush = new SolidBrush(Color.Black);
                                SolidBrush whiteBrush = new SolidBrush(Color.White);
                                graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
                                graphics.DrawString("*" + accNo + "*", oFont, blackBrush, point);
                            }
                            using (MemoryStream ms = new MemoryStream())
                            {
                                bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                                byte[] byteImage = ms.ToArray();

                                if (File.Exists(HttpContext.Current.Server.MapPath("~/BarCode/" + accNo + ".jpeg")))
                                {
                                    PdfImage LogoImage1 = mydoc.NewImage(HttpContext.Current.Server.MapPath("~/BarCode/" + accNo + ".jpeg"));
                                    mypdfpage.Add(LogoImage1, 580, img_pos, 200);
                                }
                                else
                                {
                                    File.WriteAllBytes(Server.MapPath("~/BarCode/" + accNo + ".jpeg"), byteImage);

                                    DirectoryInfo dir = new DirectoryInfo("~/BarCode/" + accNo + ".jpeg");
                                    dir.Refresh();
                                    ms.Dispose();
                                    ms.Close();
                                    PdfImage LogoImage1 = mydoc.NewImage(HttpContext.Current.Server.MapPath("~/BarCode/" + accNo + ".jpeg"));
                                    mypdfpage.Add(LogoImage1, 580, img_pos, 200);
                                }
                            }
                            img_pos += 36;
                        }
                        TR++;
                    }
                }
                //}
                Gios.Pdf.PdfTablePage newpdftabpage1 = table.CreateTablePage(new Gios.Pdf.PdfArea(mydoc, 15, 180, 650, 1200));
                mypdfpage.Add(newpdftabpage1);
                mypdfpage.SaveToDocument();

                string appPath = HttpContext.Current.Server.MapPath("~");
                if (appPath != "")
                {
                    string szPath = appPath + "/Report/";
                    string szFile = "LibraryBarcode" + DateTime.Now.ToString("ddMMyyyy") + DateTime.Now.ToString("HHmmss") + ".pdf";
                    mydoc.SaveToFile(szPath + szFile);
                    Response.ClearHeaders();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + szFile);
                    Response.ContentType = "application/pdf";
                    Response.WriteFile(szPath + szFile);
                }
            }
            else
            {
                imgdiv2.Visible = true;
                lbl_alert.Text  = "Please select the record";
            }
        }
        catch (Exception ex)
        {
            d2.sendErrorMail(ex, collegecode, "BarcodeGeneration");
        }
    }
Ejemplo n.º 4
0
		/// <summary>
		/// creates a copy of this page in order to use it as a template
		/// </summary>
		/// <returns></returns>
		public PdfPage CreateCopy()
		{
			PdfPage clone=new PdfPage();
			clone.PdfDocument=this.PdfDocument;
			foreach (PdfObject o in this.PagePdfObjects) clone.PagePdfObjects.Add(o);
			return clone;
		}