当前位置: 首页>>代码示例>>C#>>正文


C# Document.AddHeader方法代码示例

本文整理汇总了C#中iTextSharp.text.Document.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# Document.AddHeader方法的具体用法?C# Document.AddHeader怎么用?C# Document.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在iTextSharp.text.Document的用法示例。


在下文中一共展示了Document.AddHeader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnCreateReport_Click

        private void btnCreateReport_Click(object sender, EventArgs e)
        {
            // _______________________________________________________1_______________________________________________________
            // Setting pagetype, margins and encryption
            iTextSharp.text.Rectangle pageType = iTextSharp.text.PageSize.A4;
            float marginLeft = 72;
            float marginRight = 36;
            float marginTop = 60;
            float marginBottom = 50;
            String reportName = "Test.pdf";

            Document report = new Document(pageType, marginLeft, marginRight, marginTop, marginBottom);
            PdfWriter writer = PdfWriter.GetInstance(report, new FileStream(reportName, FileMode.Create));
            //writer.SetEncryption(PdfWriter.STRENGTH40BITS, "Good", "Bad", PdfWriter.ALLOW_COPY);
            report.Open();

            // _______________________________________________________2_______________________________________________________
            // Setting Document properties(Meta data)
            // 1. Title
            // 2. Subject
            // 3. Keywords
            // 4. Creator
            // 5. Author
            // 6. Header
            report.AddTitle("Employee Details Report");
            report.AddSubject("This file is generated for administrative use only");
            report.AddKeywords("Civil Security Department, Employee Management System, Version 1.0.0, Report Generator");
            report.AddCreator("Ozious Technologies");
            report.AddAuthor("Eranga Heshan");
            report.AddHeader("Owner", "Civil Security Department");

            // _______________________________________________________3_______________________________________________________
            // Setup the font factory
            /*
            int totalFonts = FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts");
            StringBuilder sb = new StringBuilder();
            foreach (string fontname in FontFactory.RegisteredFonts) { sb.Append(fontname + "\n"); }
            report.Add(new Paragraph("All Fonts:\n" + sb.ToString()));
            */
            iTextSharp.text.Font fontHeader_1 = FontFactory.GetFont("Calibri", 30, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(0, 0, 0));
            iTextSharp.text.Font fontHeader_2 = FontFactory.GetFont("Calibri", 15, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(125, 125, 125));

            // _______________________________________________________x_______________________________________________________
            // Create header
            PdfContentByte cb = writer.DirectContent;
            cb.MoveTo(marginLeft, marginTop);
            cb.LineTo(500, marginTop);
            cb.Stroke();

            Paragraph paraHeader_1 = new Paragraph("Civil Security Department", fontHeader_1);
            paraHeader_1.Alignment = Element.ALIGN_CENTER;
            paraHeader_1.SpacingAfter = 0f;
            report.Add(paraHeader_1);

            Paragraph paraHeader_2 = new Paragraph("Employee Detailed Report", fontHeader_2);
            paraHeader_2.Alignment = Element.ALIGN_CENTER;
            paraHeader_2.SpacingAfter = 10f;
            report.Add(paraHeader_2);

            // _______________________________________________________x_______________________________________________________
            // Adding employee image
            iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imgEmployee.ImageLocation);
            img.ScaleToFit(100f, 100f);
            img.Border = iTextSharp.text.Rectangle.BOX;
            img.BorderColor = iTextSharp.text.BaseColor.BLACK;
            img.BorderWidth = 5f;
            img.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT | iTextSharp.text.Image.ALIGN_TOP;
            img.IndentationLeft = 50f;
            img.SpacingAfter = 20f;
            img.SpacingBefore = 20f;
            report.Add(img);

            Paragraph para1 = new Paragraph("Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... Testing... ");
            para1.Alignment = Element.ALIGN_JUSTIFIED;
            report.Add(para1);

            report.Close();
            this.Close();
        }
开发者ID:lakmalbuddikalucky,项目名称:OOSD-Project,代码行数:79,代码来源:frmSearch.cs

示例2: GetOrCreatePDF

 /// <summary>
 /// 读取或创建Pdf文档并打开写入文件流
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="folderPath"></param>
 public Document GetOrCreatePDF(string fileName, string folderPath)
 {
     string filePath = folderPath + fileName;
     FileStream fs = null;
     if (!File.Exists(filePath))
     {
         fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
     }
     else
     {
         fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.None);
     }
     //获取A4纸尺寸
     Rectangle rec = new Rectangle(PageSize.A4);
     Document doc = new Document(rec);
     //创建一个 iTextSharp.text.pdf.PdfWriter 对象: 它有助于把Document书写到特定的FileStream:
     PdfWriter writer = PdfWriter.GetInstance(doc, fs);
     doc.AddTitle(fileName.Remove(fileName.LastIndexOf('.')));
     doc.AddSubject(fileName.Remove(fileName.LastIndexOf('.')));
     doc.AddKeywords("Metadata, iTextSharp 5.4.4, Chapter 1, Tutorial");
     doc.AddCreator("MCS");
     doc.AddAuthor("Chingy");
     doc.AddHeader("Nothing", "No Header");
     //打开 Document:
     doc.Open();
     ////关闭 Document:
     //doc.Close();
     return doc;
 }
开发者ID:fuhongliang,项目名称:GraduateProject,代码行数:34,代码来源:DIStatementExport.aspx.cs

示例3: RenderAllTables

        /// <summary>
        /// Render all data add and writes it to the specified writer
        /// </summary>
        /// <param name="model">
        /// The model to render
        /// </param>
        /// <param name="os">
        /// The output to write to
        /// </param>
        public override void RenderAllTables(IDataSetModel model, Stream os)
        {
            // TODO check the number of horizontal & vertical key values to determine the orientation of the page
            var doc = new Document(this._pageSize, 80, 50, 30, 65);

            // This doesn't seem to do anything...
            doc.AddHeader(Markup.HTML_ATTR_STYLESHEET, "style/pdf.css");
            doc.AddCreationDate();
            doc.AddCreator("NSI .NET Client");
            try
            {
                PdfWriter.GetInstance(doc, os);
                doc.Open();
                this.WriteTableModels(model, doc);
            }
            catch (DocumentException ex)
            {
                Trace.Write(ex.ToString());
                LogError.Instance.OnLogErrorEvent(ex.ToString());
            }
            catch (DbException ex)
            {
                Trace.Write(ex.ToString());
                LogError.Instance.OnLogErrorEvent(ex.ToString());
            }
            finally
            {
                if (doc.IsOpen())
                {
                    doc.Close();
                }
            }
        }
开发者ID:alcardac,项目名称:SDMX_DATA_BROWSER,代码行数:42,代码来源:PdfRenderer.cs

示例4: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFile1.SafeFileName == "" || openFile2.SafeFileName == "")
            {
                MessageBox.Show("No haz seleccionado ningún PDF", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            MessageBox.Show("Se unira \"" + openFile1.SafeFileName + "\" con \"" + openFile2.SafeFileName + "\"");
            saveFile.Filter = "Adobe Acrobat Document PDF (*.pdf)|*.pdf";
            saveFile.FilterIndex = 1;
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                MessageBox.Show("Se guardara en la siguiente ruta:\n" + saveFile.FileName);

                FileStream myStream = new FileStream(saveFile.FileName,FileMode.OpenOrCreate);

                PdfReader reader  = new PdfReader(openFile1.FileName);
                PdfReader reader2 = new PdfReader(openFile2.FileName);
                Document document = new Document(reader.GetPageSizeWithRotation(1));
                PdfCopy writer = new PdfCopy(document, myStream);
                document.Open();
                document.AddCreationDate();
                if (txtAutor.Text != null)
                {
                    document.AddAuthor(txtAutor.Text);
                }
                if (txtHeader.Text != null)
                {
                    document.AddHeader(txtHeader.Text, "Document");
                }
                if (txtKeywords.Text != null)
                {
                    document.AddKeywords(txtKeywords.Text);
                }

                document.AddProducer();

                if (txtTitulo.Text != null)
                {
                    document.AddTitle(txtTitulo.Text);
                }
                // Calculando incremento
                progressBar.Refresh();
                int incremento = (int)(100 / (reader.NumberOfPages + reader2.NumberOfPages));
                MessageBox.Show("Incremento es: " + incremento);
                for (int i = 1; i <= reader.NumberOfPages; i++)
                {
                    writer.AddPage(writer.GetImportedPage(reader, i));
                    progressBar.PerformStep();
                    progressBar.Increment(++incremento);
                }
                progressBar.Increment(50);
                for (int i = 1; i <= reader2.NumberOfPages; i++)
                {
                    writer.AddPage(writer.GetImportedPage(reader2, i));
                    progressBar.PerformStep();
                }
                progressBar.Increment(100);
                document.Close();
            }
        }
开发者ID:elialejandro,项目名称:unirpdf,代码行数:61,代码来源:Form1.cs

示例5: Prepare_Print


//.........这里部分代码省略.........
        foreach (String weekDay in weekDays)
        {
            tempCell[rowIndex] = new PdfPCell[10];
            tempRow[rowIndex] = new PdfPRow(tempCell[rowIndex]);
            foreach (int session in sessions)
            {
                if (session == 0 || session == 6)
                {
                    if (session == 0)
                    {
                        dayPara = new Paragraph(weekDays[rowIndex],day_session_para);
                        tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara);
                    }
                    else
                        if (weekDay != " ")
                        {
                            tempCell[rowIndex][cellIndex] = new PdfPCell(lunch);
                        }
                        else
                        {
                            //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(Convert.ToString(sessions[cellIndex])));
                            dayPara = new Paragraph(Convert.ToString(sessions[cellIndex]), day_session_para);
                            tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara);
                        }
                }
                else
                {
                    if (weekDay == " ")
                    {
                        dayPara = new Paragraph(Convert.ToString(sessions[cellIndex]), day_session_para);
                        tempCell[rowIndex][cellIndex] = new PdfPCell(dayPara);
                        //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(Convert.ToString(sessions[cellIndex])));
                    }
                    else
                    {
                        string query = "select B.CourseTitle,A.TeacherID from tblStudentCourseMap as A,tblCourses as B where A.ComCod = B.ComCod and A.DaySession = '" + weekDay + session + "' and A.StudentID = '" + Current_User_ID + "'";
                        myCon.ConOpen();
                        SqlDataReader sessionDet = myCon.ExecuteReader(query);

                        if (sessionDet.Read())
                            if (!sessionDet.IsDBNull(0))
                            {
                                sessionPara = new Paragraph(sessionDet.GetString(0), session_font);
                                //tempCell[rowIndex][cellIndex] = new PdfPCell(sessionPara);
                                teacherPara = new Paragraph(sessionDet.GetString(1), teacher_font);
                                tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(sessionPara));
                                tempCell[rowIndex][cellIndex].Phrase.Add(new Phrase("\n"));
                                tempCell[rowIndex][cellIndex].Phrase.Add(teacherPara);
                                //tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(sessionDet.GetString(0) + "\n" + sessionDet.GetString(1)));
                            }
                            else
                            {
                                tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(""));
                                //tempCell[rowIndex][cellIndex
                            }
                        else
                            tempCell[rowIndex][cellIndex] = new PdfPCell(new Phrase(""));
                        myCon.ConClose();
                        tempCell[rowIndex][cellIndex].FixedHeight = 75;
                    }

                }

                //tempCell[rowIndex][cellIndex].Width = 50;
                cellIndex++;
                //tempRow[rowIndex].Cells.Add(tempCell[cellIndex++, rowIndex]);
            }
            cellIndex = 0;
            //rowIndex++;
            tblSchedule.Rows.Add(tempRow[rowIndex++]);
        }

        Font HeaderFont = new Font();
        Font HeadingFont = new Font();
        HeaderFont.Size = 20;
        HeaderFont.SetStyle(Font.UNDERLINE);
        HeadingFont.Size = 15;
        HeadingFont.SetStyle(Font.UNDERLINE);
        Paragraph HeaderPara = new Paragraph("BITS PILANI, DUBAI OFFCAMPUS - TIMETABLE", HeaderFont);
        Paragraph HeadingPara = new Paragraph("Time Table allotment for " + Current_User_ID + ".",HeadingFont);
        HeaderPara.Alignment = HeadingPara.Alignment = 1;

        Document rptTimetable = new Document(PageSize.A4_LANDSCAPE.Rotate());
        PdfWriter.GetInstance(rptTimetable, new FileStream(Request.PhysicalApplicationPath + "\\" + Current_User_ID + "_timetable.pdf", FileMode.Create));
        rptTimetable.Open();
        rptTimetable.AddCreationDate();
        rptTimetable.AddHeader("BITS PILANI, DUBAI OFFCAMPUS", "TIMETABLE");
        rptTimetable.Add(new Paragraph("\n"));
        rptTimetable.AddTitle("BITS PILANI, DUBAI OFFCAMPUS - TIMETABLE");
        rptTimetable.Add(HeaderPara);
        rptTimetable.Add(HeadingPara);
        rptTimetable.Add(new Paragraph("\n\n"));

        if (rptTimetable != null && tblSchedule != null)
        {
            rptTimetable.Add(tblSchedule);
        }
        rptTimetable.Close();
        Response.Redirect("~\\" + Current_User_ID + "_timetable.pdf");
    }
开发者ID:kannan4355,项目名称:TimeTableManagementSystem,代码行数:101,代码来源:StudentHome.aspx.cs

示例6: Build

        public void Build()
        {
            iTextSharp.text.Document doc = null;

            try
            {
                // Initialize the PDF document
                doc = new Document();
                iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc,
                    new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() + "\\ScienceReport.pdf",
                        System.IO.FileMode.Create));

                // Set the margins and page size
                this.SetStandardPageSize(doc);

                // Add metadata to the document.  This information is visible when viewing the
                // document properities within Adobe Reader.
                doc.AddTitle("My Science Report");
                doc.AddHeader("title", "My Science Report");
                doc.AddHeader("author", "M. Lichtenberg");
                doc.AddCreator("M. Lichtenberg");
                doc.AddKeywords("paper airplanes");
                doc.AddHeader("subject", "paper airplanes");

                // Add Xmp metadata to the document.
                this.CreateXmpMetadata(writer);

                // Open the document for writing content
                doc.Open();

                // Add pages to the document
                this.AddPageWithBasicFormatting(doc);
                this.AddPageWithInternalLinks(doc);
                this.AddPageWithBulletList(doc);

                // Add a page with an image to the document.  The page will be sized to match the image size.
                this.AddPageWithImage(doc, System.IO.Directory.GetCurrentDirectory() + "\\FinalGraph.jpg");

                // Add a final page
                this.SetStandardPageSize(doc);  // Reset the margins and page size
                this.AddPageWithExternalLinks(doc);

                // Add page labels to the document
                iTextSharp.text.pdf.PdfPageLabels pdfPageLabels = new iTextSharp.text.pdf.PdfPageLabels();
                pdfPageLabels.AddPageLabel(1, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Basic Formatting");
                pdfPageLabels.AddPageLabel(2, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Internal Links");
                pdfPageLabels.AddPageLabel(3, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Bullet List");
                pdfPageLabels.AddPageLabel(4, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Image");
                pdfPageLabels.AddPageLabel(5, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "External Links");
                writer.PageLabels = pdfPageLabels;
            }
            catch (iTextSharp.text.DocumentException dex)
            {
                // Handle iTextSharp errors
            }
            finally
            {
                // Clean up
                doc.Close();
                doc = null;
            }
        }
开发者ID:JosefinaAiyar,项目名称:iTextSharpTester,代码行数:62,代码来源:PDFCreator.cs

示例7: CreateWorkReportPdf

        /// <summary>
        /// Creates the PDF.
        /// </summary>
        /// <param name="workReportData">The work report data.</param>
        public static void CreateWorkReportPdf(WorkReportData workReportData)
        {
            try
            {
                Document document = new Document(PageSize.A4, 10, 10, 42, 35);
                FileStream fileStream = new FileStream(Filename, FileMode.Create);
                PdfWriter pdfWriter = PdfWriter.GetInstance(document, fileStream);

                document.Open();

                #region Header

                //// Header
                Paragraph paragraph = new Paragraph("Work report");
                document.Add(paragraph);
                document.AddHeader("Header", "Work report");

                #endregion

                #region Report information table

                PdfPTable rptTable = new PdfPTable(5);
                rptTable.SpacingBefore = 30f;
                rptTable.SpacingAfter = 15f;
                rptTable.TotalWidth = 500f;
                rptTable.LockedWidth = true;
                float[] rptWidths = { 2.1f, 1.5f, 2.1f, 1f, 1f };
                rptTable.SetWidths(rptWidths);

                #region Row 1

                PdfPCell cell = new PdfPCell(new Phrase("Creation Date:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase(workReportData.DateOfCreation.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase("Period:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase(workReportData.PeriodStart.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase(workReportData.PeriodStop.ToShortDateString(), new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                #endregion

                #region Row 2

                cell = new PdfPCell(new Phrase("Serial Number:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase(workReportData.SerialNumber, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase("Project Number:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase(workReportData.ProjectNumber, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                cell.Colspan = 2;
                rptTable.AddCell(cell);

                #endregion

                #region Row 3

                cell = new PdfPCell(new Phrase("Machine Type:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase(workReportData.MachineType, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);

                cell = new PdfPCell(new Phrase(string.Empty, new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                cell.Colspan = 3;
                rptTable.AddCell(cell);

                #endregion

                #region Row 4

                cell = new PdfPCell(new Phrase("Engineer Name:", new Font(Font.FontFamily.HELVETICA, 10f, Font.NORMAL)));
                cell.FixedHeight = 20f;
                rptTable.AddCell(cell);
//.........这里部分代码省略.........
开发者ID:Breaveheard,项目名称:IT.Start,代码行数:101,代码来源:PdfAccess.cs


注:本文中的iTextSharp.text.Document.AddHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。