Exemple #1
0
        protected void btnPrintAll_Click(object sender, EventArgs e)
        {
            int    fileID    = Convert.ToInt32(Session["FileID"]);
            string filePath  = Server.MapPath("Files/" + Session["FileID"] + ".pdf");
            string tempPath  = filePath.Replace(".pdf", "_" + Session["UserName"] + ".pdf");
            string yKienPath = filePath.Replace(".pdf", "_" + Session["UserName"] + "_YKien.pdf");

            //Ý kién
            System.IO.FileStream output = new System.IO.FileStream(yKienPath, FileMode.Create);
            using (PDFEntities entities = new PDFEntities())
            {
                var file = entities.tblPDF_FileData.Where(x => x.ID == fileID).ToList();
                //branchName = entities.tblDM_Branch.SingleOrDefault(x => x.BranchID == file.BranchID).BranchName;
                //typeName = entities.tblDM_Type.SingleOrDefault(x => x.TypeID == file.TypeID).TypeName;
                VerticalGrid.DataSource = file;
                VerticalGrid.DataBind();
                VerticalGrid.ExportToPdf(output);
                output.Close();

                PdfDocument pdfyKien = new PdfDocument(new PdfReader(yKienPath));
                File.Copy(filePath, tempPath, true);
                PdfDocument pdf = new PdfDocument(new PdfReader(filePath), new PdfWriter(tempPath));
                pdfyKien.CopyPagesTo(1, 1, pdf);
                pdf.Close();

                Response.ContentType = "Application/pdf";
                Response.AppendHeader("content-disposition",
                                      "attachment; filename=" + file[0].FileName.Replace(" ", "_"));
                Response.WriteFile(tempPath);
                Response.End();
            }

            //PdfDocument pdfyKien = new PdfDocument(new PdfReader(yKienPath));
            //File.Copy(filePath, tempPath, true);
            //PdfDocument pdf = new PdfDocument(new PdfReader(filePath), new PdfWriter(tempPath));
            ////int index = pdf.GetNumberOfPages();
            ////PageSize ps = new PageSize(pdf.GetFirstPage().GetPageSize());

            ////PdfPage page = pdf.AddNewPage(index + 1, ps);

            //pdfyKien.CopyPagesTo(1,1, pdf);
            //pdf.Close();
            //if (txtIdeas.Text.Length > 0)
            //{
            //    PdfDocument pdf = new PdfDocument(new PdfReader(filePath), new PdfWriter(tempPath));
            //    int index = pdf.GetNumberOfPages();
            //    PageSize ps = new PageSize(pdf.GetFirstPage().GetPageSize());
            //    PdfPage page = pdf.AddNewPage(index + 1, ps);
            //    PdfCanvas canvas = new PdfCanvas(page);

            //    string text = txtIdeas.Text;

            //    //PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            //    //PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD);
            //    //Paragraph p = new Paragraph().Add(text);
            //    PdfFont font = PdfFontFactory.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIAL.TTF", PdfEncodings.IDENTITY_H, true);

            //    int size = Convert.ToInt32(Math.Round(ps.GetWidth() / 600)) * 12;
            //    float leading = size * 1.2f;

            //    canvas.ConcatMatrix(1, 0, 0, 1, 0, ps.GetHeight());
            //    canvas.BeginText().SetFontAndSize(font, size).SetLeading(leading).MoveText(70, -40);

            //    canvas.NewlineShowText("Danh sách các ý kiến: ");
            //    foreach (var item in text.Split(new string[1] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
            //    {
            //        if (item.Length > 90)
            //        {
            //            string items = item.Replace(",", ", ");
            //            foreach (var texts in WordWrap(items, 90))
            //            {
            //                canvas.NewlineShowText(texts);
            //            }

            //        }
            //        else
            //        {
            //            canvas.NewlineShowText(item);
            //        }

            //    }

            //    canvas.EndText();
            //    pdf.Close();

            //using (PDFEntities entities = new PDFEntities())
            //{
            //    tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID);
            //    Response.ContentType = "Application/pdf";
            //    Response.AppendHeader("content-disposition",
            //            "attachment; filename=" + file.FileName.Replace(" ","_"));
            //    Response.WriteFile(tempPath);
            //    Response.End();
            //}

            //}
        }
Exemple #2
0
        protected void btnPrintIdea_Click(object sender, EventArgs e)
        {
            int    fileID   = Convert.ToInt32(Session["FileID"]);
            string filePath = Server.MapPath("Files/" + Session["FileID"] + "_YKien.pdf");

            //tblPDF_FileData file = null;
            //string branchName = "";
            //string typeName = "";
            using (PDFEntities entities = new PDFEntities())
            {
                var file = entities.tblPDF_FileData.Where(x => x.ID == fileID).ToList();
                //branchName = entities.tblDM_Branch.SingleOrDefault(x => x.BranchID == file.BranchID).BranchName;
                //typeName = entities.tblDM_Type.SingleOrDefault(x => x.TypeID == file.TypeID).TypeName;
                VerticalGrid.DataSource = file;
                VerticalGrid.DataBind();
                VerticalGrid.ExportPdfToResponse("YKien.pdf", true);
            }

            //PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filePath));
            //Document doc = new Document(pdfDoc);

            //Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();
            //PdfFont font = PdfFontFactory.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIAL.TTF", PdfEncodings.IDENTITY_H, true);
            //table.SetFont(font);
            //// The complete cell is a link:
            //Cell cell11 = new Cell().Add(new Paragraph("Tên tệp: "));
            //cell11.SetWidth(UnitValue.CreatePercentValue(30));
            //table.AddCell(cell11);
            //Cell cell12 = new Cell().Add(new Paragraph(file.FileName));
            //cell12.SetWidth(UnitValue.CreatePercentValue(70));
            //table.AddCell(cell12);

            //Cell cell21 = new Cell().Add(new Paragraph("Đơn vị: "));
            //cell21.SetWidth(UnitValue.CreatePercentValue(30));
            //table.AddCell(cell21);
            //Cell cell22 = new Cell().Add(new Paragraph(branchName));
            //cell22.SetWidth(UnitValue.CreatePercentValue(70));
            //table.AddCell(cell22);

            //Cell cell31 = new Cell().Add(new Paragraph("Loại dữ liệu: "));
            //cell31.SetWidth(UnitValue.CreatePercentValue(30));
            //table.AddCell(cell31);
            //Cell cell32 = new Cell().Add(new Paragraph(typeName));
            //cell32.SetWidth(UnitValue.CreatePercentValue(70));
            //table.AddCell(cell32);

            //Cell cell41 = new Cell().Add(new Paragraph("Ngày cập nhật: "));
            //cell41.SetWidth(UnitValue.CreatePercentValue(30));
            //table.AddCell(cell41);
            //Cell cell42 = new Cell().Add(new Paragraph(file.UpdatedDate.ToShortDateString()));
            //cell42.SetWidth(UnitValue.CreatePercentValue(70));
            //table.AddCell(cell42);

            //Cell cell51 = new Cell().Add(new Paragraph("Người cập nhật: "));
            //cell51.SetWidth(UnitValue.CreatePercentValue(30));
            //table.AddCell(cell51);
            //Cell cell52 = new Cell().Add(new Paragraph(file.UpdatedUser));
            //cell52.SetWidth(UnitValue.CreatePercentValue(70));
            //table.AddCell(cell52);


            //Cell cell61 = new Cell().Add(new Paragraph("Các ý kiến: "));
            //cell61.SetWidth(UnitValue.CreatePercentValue(30));
            //table.AddCell(cell61);
            //Cell cell62 = new Cell().Add(new Paragraph(file.Idea));
            //cell62.SetWidth(UnitValue.CreatePercentValue(70));
            //table.AddCell(cell62);

            //doc.Add(table);
            //doc.Close();

            //Response.ContentType = "Application/pdf";
            //Response.AppendHeader("content-disposition",
            //        "attachment; filename=YKien.pdf");
            //Response.WriteFile(filePath);
            //Response.End();
        }