public static void getReport(string path, Entrada oE, string pathImg) { PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(21.59, 27.94)); PdfPage newPdfPage = myPdfDocument.NewPage(); // This will load the image without placing into the document. The good thing // is that the image will be written into the document just once even if we put it // more times and in different sizes and places! PdfImage LogoImage = myPdfDocument.NewImage(pathImg); //// now we start putting the logo into the right place with a high resoluton... newPdfPage.Add(LogoImage, 10, 20, 300); setHeader(myPdfDocument, newPdfPage, oE); setBody(myPdfDocument, newPdfPage, oE); setFooter(myPdfDocument, newPdfPage, oE); try { newPdfPage.SaveToDocument(); myPdfDocument.SaveToFile(path); } catch { throw; } }
/// <summary> /// Saves the PDF from the disk swap file /// </summary> /// <param name="b"></param> /// <param name="output"></param> public void SaveAsPDF(BitmapFile b, string output) { FileInfo fi = new FileInfo(output); // Following are the calls to the Gios PDF library PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(m_PDF_Width, m_PDF_Height)); int horizontalStep = Convert.ToInt32(m_PDF_Width * m_PDF_DPI / 2.54); int verticalStep = Convert.ToInt32(m_PDF_Height * m_PDF_DPI / 2.54); int origin = 0; List <string> tmpFiles = new List <string>(); int tmpFileCount = 0; while (origin < b.Y) { Bitmap tmp = b.GetBitmap(0, origin, horizontalStep, verticalStep); string temp_file = fi.DirectoryName + "\\_tempPDFComponent_" + tmpFileCount.ToString().PadLeft(5, '0') + ".jpg"; tmp.Save(temp_file, ImageFormat.Jpeg); tmpFiles.Add(temp_file); PdfPage newPdfPage = myPdfDocument.NewPage(); PdfImage myImage = myPdfDocument.NewImage(temp_file); newPdfPage.Add(myImage, 0.0, 0.0, m_PDF_DPI); newPdfPage.SaveToDocument(); origin += verticalStep; tmpFileCount++; tmp.Dispose(); } myPdfDocument.SaveToFile(output); foreach (string f in tmpFiles) { try { File.Delete(f); } catch (Exception) { } } }
public Boolean Generate() { pdf_table_no = 1; // Starting instantiate the document. // Remember to set the Docuement Format. In this case, we specify width and height. if (UsingControl == 1) { int total_grid_exported = 0; PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(21, 29.7)); addTable(myPdfDocument, Table, noOfrows); myPdfDocument.SaveToFile(PDFsaveAs); } else { PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(21, 29.7)); if (PDFReportNumber == 9) { myPdfDocument.SetPageFormat(PdfDocumentFormat.A4_Horizontal); } if (addTable(myPdfDocument, Table, noOfrows)) { try { myPdfDocument.SaveToFile("reports/" + PDFsaveAs + ".pdf"); } catch (Exception ex) { MessageBox.Show("Please close the opened pdf."); } } else { MessageBox.Show("Failed to generate report."); return(false); } } MessageBox.Show("PDF Saved.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }
public void GenerateUsingText(string saveAs, RichTextBox inText) { try { PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(21, 29.7)); PdfImage LogoImage = myPdfDocument.NewImage(@"logo.jpg"); PdfPage newPdfPage = null; int lineNo = 1; string text = ""; PdfTextArea ptasubtext = null; for (int i = 0; i < inText.Lines.Length; i++, lineNo++) { if (i % 50 == 0) { newPdfPage = myPdfDocument.NewPage(); lineNo = 1; } text += "\n" + inText.Lines[i]; if (i % 50 == 0 && i != 0) { newPdfPage.Add(LogoImage, 15, 10, 100); ptasubtext = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.Black , new PdfArea(myPdfDocument, 18, 120, 400, 930), ContentAlignment.TopLeft, text); newPdfPage.Add(ptasubtext); newPdfPage.SaveToDocument(); text = ""; } } newPdfPage = myPdfDocument.NewPage(); newPdfPage.Add(LogoImage, 15, 10, 100); ptasubtext = new PdfTextArea(new Font("Verdana", 12, FontStyle.Bold), Color.Black , new PdfArea(myPdfDocument, 18, 120, 400, 930), ContentAlignment.TopLeft, text); newPdfPage.Add(ptasubtext); newPdfPage.SaveToDocument(); myPdfDocument.SaveToFile(saveAs); MessageBox.Show("PDF Saved.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { } }
public Stream SaveAsStream() { table.EndLoadData(); table.AcceptChanges(); var removes = new List <string>(); foreach (DataColumn dc in table.Columns) { if (title.IndexOf(dc.ColumnName) == -1) { removes.Add(dc.ColumnName); } } foreach (var name in removes) { table.Columns.Remove(name); } var pdfTitle = table.TableName; // Starting instantiate the document. // Remember to set the Docuement Format. In this case, we specify width and height. PdfDocument myPdfDocument = new PdfDocument(PdfDocumentFormat.InCentimeters(21, 29.7)); // Now we create a Table of 100 lines, 6 columns and 4 points of Padding. PdfTable myPdfTable = myPdfDocument.NewTable(new Font("Arial", 12), table.Rows.Count, table.Columns.Count, 4); // Importing datas from the datatables... (also column names for the headers!) //myPdfTable.ImportDataTable(Table); myPdfTable.ImportDataTable(table); // Sets the format for correct date-time representation //myPdfTable.Columns[2].SetContentFormat("{0:dd/MM/yyyy}"); // Now we set our Graphic Design: Colors and Borders... myPdfTable.HeadersRow.SetColors(Color.White, Color.Navy); myPdfTable.SetColors(Color.Black, Color.White, Color.Gainsboro); myPdfTable.SetBorders(Color.Black, 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[] { 5, 25, 16, 20, 20, 15 }); //// You can also set colors for a range of cells, in this case, a row: //myPdfTable.Rows[7].SetColors(Color.Black, Color.LightGreen); // Now we set some alignment... for the whole table and then, for a column. myPdfTable.SetContentAlignment(ContentAlignment.MiddleCenter); myPdfTable.Columns[1].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(); PdfTablePage newPdfTablePage = myPdfTable.CreateTablePage(new PdfArea(myPdfDocument, 48, 120, 500, 670)); // we also put a Label PdfTextArea pta = new PdfTextArea(new Font("Arial", 26, FontStyle.Bold), Color.Red , new PdfArea(myPdfDocument, 0, 20, 595, 120), ContentAlignment.MiddleCenter, pdfTitle); // nice thing: we can put all the objects in the following lines, so we can have // a great control of layer sequence... newPdfPage.Add(newPdfTablePage); newPdfPage.Add(pta); // we save each generated page before start rendering the next. newPdfPage.SaveToDocument(); } //myPdfDocument.SaveToFile("Example1.pdf"); var stream = new MemoryStream(); myPdfDocument.SaveToStream(stream); return(stream); }
protected void btn_commonprint_OnClick(object sender, EventArgs e) { try { string coename = ""; string strquery = "select *,district+' - '+pincode as districtpin from collinfo where college_code='" + Session["collegecode"].ToString() + "'"; ds.Dispose(); ds.Reset(); ds = d2.select_method_wo_parameter(strquery, "Text"); string Collegename = ""; string aff = ""; string collacr = ""; string dispin = ""; string category = ""; if (ds.Tables[0].Rows.Count > 0) { Collegename = ds.Tables[0].Rows[0]["Collname"].ToString(); aff = ds.Tables[0].Rows[0]["affliatedby"].ToString(); string[] strpa = aff.Split(','); aff = strpa[0]; coename = ds.Tables[0].Rows[0]["coe"].ToString(); collacr = ds.Tables[0].Rows[0]["acr"].ToString(); dispin = ds.Tables[0].Rows[0]["districtpin"].ToString(); category = ds.Tables[0].Rows[0]["category"].ToString(); } string degreecode = ddlbranch.SelectedValue.ToString(); //string //string eve = d2.GetFunction(" select c.type from Degree d,Course c where d.Course_Id=c.Course_Id and d.Degree_Code='" + degreecode + "'"); string eve = ""; string course = ""; string deptacr = ""; string headingquery = "select c.type,c.Course_Name,de.dept_name from Degree d,Course c,Department de where d.Course_Id=c.Course_Id and de.Dept_Code=d.Dept_Code and d.Degree_Code='" + degreecode + "'"; hds = d2.select_method_wo_parameter(headingquery, "Text"); if (hds.Tables[0].Rows.Count > 0) { eve = hds.Tables[0].Rows[0]["type"].ToString(); course = hds.Tables[0].Rows[0]["Course_Name"].ToString(); deptacr = hds.Tables[0].Rows[0]["dept_name"].ToString(); } string batch = ddlbatch.SelectedItem.Text; string title = "PAPERS SELECTED BY THE STUDENTS OF " + course + " - " + deptacr + " - BATCH " + batch + " (" + eve + ")"; Font Fontbold1 = new Font("Times New Roman", 15, FontStyle.Bold); Font font2bold = new Font("Times New Roman", 12, FontStyle.Bold); Font font2small = new Font("Times New Roman", 12, FontStyle.Regular); Font font3bold = new Font("Times New Roman", 9, FontStyle.Bold); Font font3small = new Font("Times New Roman", 10, FontStyle.Regular); Font font4bold = new Font("Times New Roman", 7, FontStyle.Bold); Font font4small = new Font("Times New Roman", 7, FontStyle.Regular); Gios.Pdf.PdfDocument mydoc; Gios.Pdf.PdfPage mypdfpage; Gios.Pdf.PdfTable table1forpage2; Gios.Pdf.PdfTablePage newpdftabpage2; if (FpSpread2.Sheets[0].RowCount > 0) { int nofocolun = 0; Hashtable hatrowset = new Hashtable(); int haskpage = 0; int checkrow = 0; for (int r = 0; r < FpSpread2.Sheets[0].RowCount; r++) { string nameval = FpSpread2.Sheets[0].Cells[r, 1].Text.ToString(); if (nameval.Trim() != "") { checkrow++; if (checkrow == 11 || checkrow == 1) { haskpage++; checkrow = 1; } } if (hatrowset.Contains(haskpage)) { hatrowset[haskpage] = Convert.ToInt32(hatrowset[haskpage]) + 1; } else { hatrowset.Add(haskpage, 1); } } int pagcount = hatrowset.Count; haskpage = 0; int totcol = FpSpread2.Sheets[0].ColumnCount - 3; int noofcolumn = totcol / 10; if (((FpSpread2.Sheets[0].ColumnCount - 3) % 10) > 0) { noofcolumn++; } mydoc = new Gios.Pdf.PdfDocument(PdfDocumentFormat.InCentimeters(60, 40)); int startcolun = 0; int endcolumn; int stratrow = 0; int endrow = 0; for (int pc = 1; pc <= pagcount; pc++) { int noofrows = Convert.ToInt32(hatrowset[pc]); startcolun = 3; stratrow = endrow; endrow = stratrow + noofrows; startcolun = 3; int colcou = 3; for (int col = 0; col < noofcolumn; col++) { if (col > 0) { startcolun = startcolun + 10; } endcolumn = startcolun + 10; if (endcolumn > FpSpread2.Sheets[0].ColumnCount) { endcolumn = FpSpread2.Sheets[0].ColumnCount; } colcou = colcou + 10; nofocolun = 13; if (colcou > FpSpread2.Sheets[0].ColumnCount) { colcou = (FpSpread2.Sheets[0].ColumnCount + 10) - colcou; nofocolun = colcou + 3; } mypdfpage = mydoc.NewPage(); int coltop = 20; #region Left Logo if (File.Exists(HttpContext.Current.Server.MapPath("~/college/Left_Logo.jpeg"))) { PdfImage LogoImage = mydoc.NewImage(HttpContext.Current.Server.MapPath("~/college/Left_Logo.jpeg")); mypdfpage.Add(LogoImage, 35, 20, 320); } #endregion #region TOP DETAILS coltop = coltop + 10; PdfTextArea ptc = new PdfTextArea(Fontbold1, System.Drawing.Color.Black, new PdfArea(mydoc, 0, coltop, 1700, 30), System.Drawing.ContentAlignment.TopCenter, Collegename + "(" + category + ")"); mypdfpage.Add(ptc); coltop = coltop + 20; ptc = new PdfTextArea(Fontbold1, System.Drawing.Color.Black, new PdfArea(mydoc, 0, coltop, 1700, 30), System.Drawing.ContentAlignment.TopCenter, title); mypdfpage.Add(ptc); coltop = coltop + 20; //ptc = new PdfTextArea(font2bold, System.Drawing.Color.Black, // new PdfArea(mydoc, 560, coltop, 595, 30), System.Drawing.ContentAlignment.TopCenter, aff); //mypdfpage.Add(ptc); //coltop = coltop + 15; //ptc = new PdfTextArea(font2bold, System.Drawing.Color.Black, // new PdfArea(mydoc, 560, coltop, 595, 30), System.Drawing.ContentAlignment.TopCenter, dispin); //mypdfpage.Add(ptc); #endregion # region Table Binding table1forpage2 = mydoc.NewTable(font3small, noofrows + 1, nofocolun, 4); table1forpage2.VisibleHeaders = false; table1forpage2.SetBorders(Color.Black, 1, BorderType.CompleteGrid); table1forpage2.Cell(0, 0).SetContentAlignment(ContentAlignment.MiddleCenter); table1forpage2.Cell(0, 0).SetContent("S.No"); table1forpage2.Columns[0].SetWidth(30); table1forpage2.Cell(0, 1).SetContentAlignment(ContentAlignment.MiddleCenter); table1forpage2.Cell(0, 1).SetContent("Reg.No"); table1forpage2.Columns[1].SetWidth(60); table1forpage2.Cell(0, 2).SetContentAlignment(ContentAlignment.MiddleCenter); table1forpage2.Cell(0, 2).SetContent("Student Name"); table1forpage2.Columns[2].SetWidth(150); //table1forpage2.Cell(0, 3).SetContentAlignment(ContentAlignment.MiddleCenter); //table1forpage2.Cell(0, 3).SetContent("(Total Papers Selected)"); //table1forpage2.Columns[3].SetWidth(80); //table1forpage2.Cell(0, 4).SetContentAlignment(ContentAlignment.MiddleCenter); //table1forpage2.Cell(0, 4).SetContent("Total Papers Appeared"); //table1forpage2.Columns[4].SetWidth(80); table1forpage2.Cell(0, 0).SetFont(font2bold); table1forpage2.Cell(0, 1).SetFont(font2bold); table1forpage2.Cell(0, 2).SetFont(font2bold); //table1forpage2.Cell(0, 3).SetFont(font2bold); //table1forpage2.Cell(0, 4).SetFont(font2bold); int totalrow = endrow - stratrow; int tr = 0; int tc = 3; for (int r = stratrow; r < endrow; r++) { tr++; tc = 2; table1forpage2.Cell(tr, 0).SetContentAlignment(ContentAlignment.MiddleCenter); table1forpage2.Cell(tr, 1).SetContentAlignment(ContentAlignment.MiddleLeft); table1forpage2.Cell(tr, 2).SetContentAlignment(ContentAlignment.MiddleLeft); //table1forpage2.Cell(tr, 3).SetContentAlignment(ContentAlignment.MiddleCenter); //table1forpage2.Cell(tr, 4).SetContentAlignment(ContentAlignment.MiddleCenter); table1forpage2.Cell(tr, 0).SetContent(FpSpread2.Sheets[0].Cells[r, 0].Text.ToString()); table1forpage2.Cell(tr, 1).SetContent(FpSpread2.Sheets[0].Cells[r, 1].Text.ToString()); table1forpage2.Cell(tr, 1).SetFont(font2bold); table1forpage2.Cell(tr, 2).SetContent(FpSpread2.Sheets[0].Cells[r, 2].Text.ToString()); table1forpage2.Cell(tr, 2).SetFont(font2bold); //table1forpage2.Cell(tr, 3).SetContent(FpSpread2.Sheets[0].Cells[r, 3].Text.ToString()); //table1forpage2.Cell(tr, 3).SetFont(font3small); //table1forpage2.Cell(tr, 4).SetContent(FpSpread2.Sheets[0].Cells[r, 4].Text.ToString()); //table1forpage2.Cell(tr, 4).SetFont(font3small); for (int c = startcolun; c < endcolumn; c++) { tc++; if (tc < FpSpread2.Sheets[0].ColumnCount) { if (r == stratrow) { table1forpage2.Cell(0, tc).SetContentAlignment(ContentAlignment.MiddleCenter); table1forpage2.Cell(0, tc).SetContent(FpSpread2.Sheets[0].ColumnHeader.Cells[0, c].Text.ToString()); table1forpage2.Cell(0, tc).SetFont(font2bold); table1forpage2.Columns[tc].SetWidth(100); table1forpage2.Cell(tr, tc).SetCellPadding(20); } table1forpage2.Cell(tr, tc).SetContent(FpSpread2.Sheets[0].Cells[r, c].Text.ToString()); table1forpage2.Cell(tr, tc).SetFont(font2bold); string value = FpSpread2.Sheets[0].Cells[r, c].Text.ToString().ToString(); if (value.Trim() == "") { table1forpage2.Cell(tr, tc).SetContent("."); table1forpage2.Cell(tr, tc).SetForegroundColor(Color.White); } if (totalrow > 40) { table1forpage2.Cell(tr, tc).SetCellPadding(1); } else if (totalrow > 30) { table1forpage2.Cell(tr, tc).SetCellPadding(5); } else if (totalrow > 18) { table1forpage2.Cell(tr, tc).SetCellPadding(10); } else { table1forpage2.Cell(tr, tc).SetCellPadding(20); } } } } newpdftabpage2 = table1forpage2.CreateTablePage(new Gios.Pdf.PdfArea(mydoc, 15, 130, 1670, 5000)); mypdfpage.Add(newpdftabpage2); mypdfpage.SaveToDocument(); #endregion } } string appPath = HttpContext.Current.Server.MapPath("~"); if (appPath != "") { string szPath = appPath + "/Report/"; string szFile = "SubjectAllotment" + 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); } } }
public byte[] Serialize(ReportDocument document) { //long start = DateTime.Now.Ticks; Size documentSize = document.PaperType == Paper.Type.Custom ? document.PixelSize : Paper.GetPaperSize(document.PaperType); if (document.Layout == Com.Delta.Print.Engine.ReportDocument.LayoutType.Portrait) { pdfDocument = new PdfDocument(PdfDocumentFormat.InInches(documentSize.Width * 0.72 / 72, documentSize.Height * 0.72 / 72)); } else { pdfDocument = new PdfDocument(PdfDocumentFormat.InInches(documentSize.Height * 0.72 / 72, documentSize.Width * 0.72 / 72)); } document.StartPrinting(); for (int sectionCounter = 0; sectionCounter < document.Sections.Count; sectionCounter++) { document.NewPage(); Section section = (Section)document.Sections[sectionCounter]; section.Prepare(true); PdfPage page = pdfDocument.NewPage(); bool morePages = false; int sectionPage = 0; do { sectionPage++; morePages = section.UpdateDynamicContent(); for (int i = 0; i < section.Objects.Length; i++) { if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.EveryPage) { ProcessElement(page, section.Objects[i]); } else if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.FirstPage) { if (sectionPage == 1) { ProcessElement(page, section.Objects[i]); } } else if (section.Objects[i].Layout == ICustomPaint.LayoutTypes.LastPage) { if (!morePages) { ProcessElement(page, section.Objects[i]); } } } if (morePages) { page.SaveToDocument(); page = pdfDocument.NewPage(); document.NewPage(); section.Prepare(false); } }while(morePages); page.SaveToDocument(); document.NewSection(); } MemoryStream ms = new MemoryStream(); pdfDocument.SaveToStream(ms); byte[] content = new byte[ms.Length]; //Console.WriteLine((DateTime.Now.Ticks-start)/10000); ms.Position = 0; ms.Read(content, 0, content.Length); ms.Close(); return(content); }
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"); } }
protected void btndummynoprint_Click(object sender, EventArgs e) { try { ArrayList adddummyarray = new ArrayList(); Gios.Pdf.PdfDocument mydoc; Font Fontbold = new Font("Book Antiqua", 18, FontStyle.Regular); Font fbold = new Font("Book Antiqua", 18, FontStyle.Bold); Font Fontsmall = new Font("Book Antiqua", 12, FontStyle.Regular); Font fontname = new Font("Book Antiqua", 11, FontStyle.Bold); Font fontmedium = new Font("Book Antiqua", 10, FontStyle.Regular); Font fontmediumb = new Font("Book Antiqua", 8, FontStyle.Bold); mydoc = new Gios.Pdf.PdfDocument(PdfDocumentFormat.InCentimeters(24, 30)); Gios.Pdf.PdfPage mypdfpage; // Gios.Pdf.PdfTable table1 = myprovdoc.NewTable(Fontsmall, prov_cnt + 8, 6, 1); Gios.Pdf.PdfTable table; Gios.Pdf.PdfTable table1; Gios.Pdf.PdfTablePage myprov_pdfpage1; string deptvalue = ""; Fpspread1.SaveChanges(); int prinsheetno = 0; string getmaxsheetno = d2.GetFunction("select isnull(max(sheet_no),'10000') from dummynumber where exam_year='" + ddlYear.SelectedValue.ToString() + "' and exam_month='" + ddlMonth.SelectedValue.ToString() + "' "); int strshetno = Convert.ToInt32(getmaxsheetno); if (Fpspread1.Sheets[0].RowCount > 0) { for (int row = 0; row < Fpspread1.Sheets[0].RowCount; row++) { string getval = Fpspread1.Sheets[0].Cells[row, 2].Tag.ToString(); if (getval == "1") { adddummyarray.Add(Convert.ToString(Fpspread1.Sheets[0].Cells[row, 2].Text)); } else { adddummyarray.Add(Convert.ToString(Fpspread1.Sheets[0].Cells[row, 3].Text)); } string dummyno = Fpspread1.Sheets[0].Cells[row, 3].Tag.ToString(); if (dummyno == "") { if ((row % 25) == 0) { strshetno++; } dummyno = strshetno.ToString(); string insertval = "update dummynumber set sheet_no='" + dummyno + "' where dummy_no='" + Fpspread1.Sheets[0].Cells[row, 3].Text.ToString() + "'"; int val = d2.update_method_wo_parameter(insertval, "Text"); } if (prinsheetno == 0) { prinsheetno = Convert.ToInt32(dummyno); } Fpspread1.Sheets[0].Cells[row, 3].Tag = dummyno; } } Fpspread1.SaveChanges(); string month = Convert.ToString(ddlMonth.SelectedItem.Text); string year = Convert.ToString(ddlYear.SelectedItem.Text); string dept = ""; if (chklstbranch.Items.Count > 0) { for (int ros = 0; ros < chklstbranch.Items.Count; ros++) { if (chklstbranch.Items[ros].Selected == true) { dept = Convert.ToString(chklstbranch.Items[ros].Text); } } } string course = Convert.ToString(Fpspread1.Sheets[0].Cells[0, 4].Text); deptvalue = Convert.ToString(Fpspread1.Sheets[0].Cells[0, 5].Text); string semval = Convert.ToString(Fpspread1.Sheets[0].Cells[0, 4].Tag); string subjectname = ddlsubject.SelectedItem.Text; string subjectcode = ddlsubject.SelectedItem.Value; PdfTextArea ptc4 = new PdfTextArea(Fontsmall, System.Drawing.Color.Black, new PdfArea(mydoc, 515, 0, 113, 30), System.Drawing.ContentAlignment.MiddleCenter, prinsheetno.ToString()); PdfTextArea ptc5 = new PdfTextArea(Fontsmall, System.Drawing.Color.Black, new PdfArea(mydoc, 515, 30, 113, 20), System.Drawing.ContentAlignment.MiddleCenter, month + " " + year); int y = 48; PdfTextArea ptde = new PdfTextArea(fontmedium, System.Drawing.Color.Black, new PdfArea(mydoc, 120, y, 100, 30), System.Drawing.ContentAlignment.MiddleLeft, "" + course + ""); PdfTextArea ptc = new PdfTextArea(fontmedium, System.Drawing.Color.Black, new PdfArea(mydoc, 303, y, 350, 30), System.Drawing.ContentAlignment.MiddleLeft, "" + deptvalue + ""); PdfTextArea psem = new PdfTextArea(fontmedium, System.Drawing.Color.Black, new PdfArea(mydoc, 544, y, 200, 30), System.Drawing.ContentAlignment.MiddleLeft, "" + semval + ""); y = y + 20; PdfTextArea ptc1 = new PdfTextArea(fontmedium, System.Drawing.Color.Black, new PdfArea(mydoc, 120, y, 350, 30), System.Drawing.ContentAlignment.MiddleLeft, "" + subjectname + ""); PdfTextArea ptc2 = new PdfTextArea(fontmedium, System.Drawing.Color.Black, new PdfArea(mydoc, 544, y, 200, 30), System.Drawing.ContentAlignment.MiddleLeft, "" + subjectcode + ""); if (adddummyarray.Count > 0) { int rowcount = 0; int totalcount = adddummyarray.Count; while (totalcount > 25) { if (rowcount > 24) { prinsheetno++; ptc4 = new PdfTextArea(Fontsmall, System.Drawing.Color.Black, new PdfArea(mydoc, 515, 2, 113, 30), System.Drawing.ContentAlignment.MiddleCenter, prinsheetno.ToString()); } totalcount = totalcount - 25; table = mydoc.NewTable(Fontsmall, 13, 1, 10); for (int row = 0; row < 13; row++) { string getvalue = Convert.ToString(adddummyarray[rowcount]); table.Cell(row, 0).SetContent(getvalue); table.Cell(row, 0).SetContentAlignment(ContentAlignment.MiddleLeft); table.Cell(row, 0).SetCellPadding(11); rowcount++; } table1 = mydoc.NewTable(Fontsmall, 12, 1, 10); for (int row = 0; row < 12; row++) { string getvalue = Convert.ToString(adddummyarray[rowcount]); table1.Cell(row, 0).SetContent(getvalue); table1.Cell(row, 0).SetCellPadding(11); rowcount++; } mypdfpage = mydoc.NewPage(); myprov_pdfpage1 = table.CreateTablePage(new Gios.Pdf.PdfArea(mydoc, 50, 150, 100, 500)); mypdfpage.Add(myprov_pdfpage1); myprov_pdfpage1 = table1.CreateTablePage(new Gios.Pdf.PdfArea(mydoc, 340, 150, 100, 500)); mypdfpage.Add(myprov_pdfpage1); mypdfpage.Add(ptc); mypdfpage.Add(ptc1); mypdfpage.Add(ptc2); mypdfpage.Add(ptc4); mypdfpage.Add(ptc5); mypdfpage.Add(ptde); mypdfpage.Add(psem); mypdfpage.SaveToDocument(); } bool check = false; int subtotalcount = totalcount; int value = 0; mypdfpage = mydoc.NewPage(); if (subtotalcount >= 13) { value = subtotalcount - 13; check = true; } if (check == true) { prinsheetno++; ptc4 = new PdfTextArea(Fontsmall, System.Drawing.Color.Black, new PdfArea(mydoc, 515, 2, 113, 30), System.Drawing.ContentAlignment.MiddleCenter, prinsheetno.ToString()); table = mydoc.NewTable(Fontsmall, 13, 1, 10); for (int row = 0; row < 13; row++) { string getvalue = Convert.ToString(adddummyarray[rowcount]); table.Cell(row, 0).SetContent(getvalue); rowcount++; } myprov_pdfpage1 = table.CreateTablePage(new Gios.Pdf.PdfArea(mydoc, 50, 150, 100, 500)); mypdfpage.Add(myprov_pdfpage1); } else { prinsheetno++; ptc4 = new PdfTextArea(Fontsmall, System.Drawing.Color.Black, new PdfArea(mydoc, 515, 2, 113, 30), System.Drawing.ContentAlignment.MiddleCenter, prinsheetno.ToString()); table = mydoc.NewTable(Fontsmall, subtotalcount, 1, 10); for (int row = 0; row < subtotalcount; row++) { string getvalue = Convert.ToString(adddummyarray[rowcount]); table.Cell(row, 0).SetContent(getvalue); rowcount++; } myprov_pdfpage1 = table.CreateTablePage(new Gios.Pdf.PdfArea(mydoc, 50, 150, 100, 500)); mypdfpage.Add(myprov_pdfpage1); } if (value != 0) { table1 = mydoc.NewTable(Fontsmall, value, 1, 10); for (int row = 0; row < value; row++) { string getvalue = Convert.ToString(adddummyarray[rowcount]); table1.Cell(row, 0).SetContent(getvalue); rowcount++; } myprov_pdfpage1 = table1.CreateTablePage(new Gios.Pdf.PdfArea(mydoc, 340, 170, 100, 500)); mypdfpage.Add(myprov_pdfpage1); } mypdfpage.Add(ptc); mypdfpage.Add(ptc1); mypdfpage.Add(ptc2); mypdfpage.Add(ptc4); mypdfpage.Add(ptc5); mypdfpage.Add(ptde); mypdfpage.Add(psem); mypdfpage.SaveToDocument(); string appPath = HttpContext.Current.Server.MapPath("~"); if (appPath != "") { string szPath = appPath + "/Report/"; string szFile = "Dummy.pdf"; mydoc.SaveToFile(szPath + szFile); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment; filename=" + szFile); Response.ContentType = "application/pdf"; Response.WriteFile(szPath + szFile); } } } catch { } }