Esempio n. 1
0
        private Chapter GetChapter(FeedEntity entity)
        {
            Font ft = new Font(baseFT, 12);

            Chapter chp = new Chapter(new Paragraph(entity.Title, new Font(baseFT, 18))
            {
                Alignment = Element.ALIGN_CENTER
            }, chp_idx++);

            chp.Add(new Paragraph(" "));
            chp.Add(new Paragraph(" "));

            string text = GetContent(entity);

            foreach (string line in text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                try
                {
                    if (line == "[code_begin]")
                    {
                        ft = codeFT;
                    }
                    else if (line == "[code_end]")
                    {
                        ft = new Font(baseFT, 12);
                    }
                    else if (line.StartsWith("[img]"))
                    {
                        Image img = Image.GetInstance(line.Substring(5));
                        if (img.Width > 40)
                        {
                            if (img.Width > 560)
                            {
                                img.ScaleToFit(560, 560);
                            }
                            img.Alignment = Element.ALIGN_CENTER;
                            chp.Add(img);
                        }
                    }
                    else
                    {
                        chp.Add(new Paragraph(line, ft));
                    }
                }
                catch { }
            }
            return(chp);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds test group info.
        /// </summary>
        private void AddTestGroupInfo()
        {
            Document.NewPage();

            Paragraph title   = new Paragraph("ONVIF TEST", FontFactory.GetFont(FontFactory.TIMES, 18));
            Chapter   chapter = new Chapter(title, 2);

            chapter.NumberDepth = 0;
            Paragraph empty = new Paragraph("\n\n");

            chapter.Add(empty);

            string  lastGroup = string.Empty;
            Section section   = null;

            foreach (TestInfo info in Log.TestResults.Keys.OrderBy(T => T.Category).ThenBy(TI => TI.Order))
            {
                string group = info.Group.Split('\\')[0];
                if (lastGroup != group)
                {
                    Paragraph groupTitle = new Paragraph(string.Format("\n\n{0}", group), FontFactory.GetFont(FontFactory.TIMES, 18));
                    section             = chapter.AddSection(groupTitle);
                    section.NumberDepth = 0;
                    Paragraph someSectionText = new Paragraph("\n");
                    section.Add(someSectionText);
                    lastGroup = group;
                }

                Paragraph testTitle = new Paragraph(info.Name);
                Anchor    ancor     = new Anchor(".");
                ancor.Name = info.Name;
                testTitle.Add(ancor);
                Section testSection = section.AddSection(testTitle);
                testSection.NumberDepth = 0;

                if (info.RequirementLevel == RequirementLevel.Optional)
                {
                    Paragraph optional = new Paragraph("* Optional Test");
                    testSection.Add(optional);
                }

                string testDescription = string.Empty;

                if (Log.TestResults.ContainsKey(info))
                {
                    testDescription = string.Format("\nTestResult\n{0}\n", Log.TestResults[info].ShortTextLog);
                    testDescription = testDescription.Replace(string.Format("{0}\r\n", info.Name), "");
                }
                else
                {
                    testDescription = "Test not run\n\n";
                }

                Paragraph sectionText = new Paragraph(testDescription, FontFactory.GetFont(FontFactory.TIMES, 11));
                testSection.Add(sectionText);
            }

            Document.Add(chapter);
        }
Esempio n. 3
0
        public void Archive(IEnumerable <FileInfo> files, string epubPath)
        {
            Document  doc           = new Document();
            int       chapterNumber = 1;
            PdfWriter writer        = PdfWriter.GetInstance(doc, new FileStream(epubPath, FileMode.Create));

            doc.Open();
            foreach (var file in files)
            {
                try
                {
                    using (StreamReader sr = new StreamReader(file.FullName))
                    {
                        string contents = sr.ReadToEnd();

                        /*
                         * string title = GetTitle(contents);
                         * // For redirect case.
                         * title = title == "" ? Path.GetFileNameWithoutExtension(file.Name) : title;
                         * */
                        string title = GetTitleFromFilePath(file.Name);

                        Chapter chapter1 = new Chapter(new Paragraph(title, _font), 1 /* chapterNumber */);

                        /*
                         *
                         * var lists = HTMLWorker.ParseToList(new StringReader(contents), new StyleSheet());
                         * lists.All((e) => chapter1.Add(e));
                         * */
                        chapter1.Add(new Paragraph(contents, _font));
                        try
                        {
                            doc.Add(chapter1);
                        }
                        catch (IndexOutOfRangeException)
                        {
                            //used unknown font.
                            // just skip.
                            continue;
                        }
                    }
                    chapterNumber++;
                }
                catch (FileNotFoundException)
                {
                    // in some Greeth filename, StreamReader return file not found exception.
                    // Just ignore it.
                }
            }
            try
            {
                doc.Close();
            }
            catch (IOException)
            {
                // if nothing add, close return IOException.
                // this is FileNotFoundException case only and just ignore it.
            }
        }
Esempio n. 4
0
        private static void SetAnchor(ISPage iSPage, Chapter chapter, Dictionary <string, int> pageMap)
        {
            Anchor anchorTarget = new Anchor(iSPage.RoomId);

            anchorTarget.Name = iSPage.RoomId;
            Paragraph targetParagraph = new Paragraph();

            targetParagraph.Add(anchorTarget);
            chapter.Add(targetParagraph);
        }
Esempio n. 5
0
        private void AddTestGroupInfo()
        {
            m_Document.NewPage();

            //Добавление основного заголовка ONVIF TEST
            Paragraph title    = new Paragraph("ONVIF TEST", FontFactory.GetFont(FontFactory.TIMES, 18));
            Chapter   chapter2 = new Chapter(title, 2);

            //Для отсутсвия нумерации
            chapter2.NumberDepth = 0;
            Paragraph someText = new Paragraph("\n\n");

            chapter2.Add(someText);

            //Добавление группы тестов
            Paragraph title1   = new Paragraph("Device Discovery Test Cases", FontFactory.GetFont(FontFactory.TIMES, 18));
            Section   section1 = chapter2.AddSection(title1);

            section1.NumberDepth = 0;
            Paragraph someSectionText = new Paragraph("\n\n");

            section1.Add(someSectionText);

            //Добавление теста
            Paragraph title11 = new Paragraph("8.1.1 - MULTICAST NVT HELLO MESSAGE");
            //Добавление конечной точки для ссылки из содержания
            Anchor anc11 = new Anchor(".");

            anc11.Name = "MULTICAST NVT HELLO MESSAGE";
            title11.Add(anc11);
            Section section11 = section1.AddSection(title11);

            section11.NumberDepth = 0;
            Paragraph someSectionText11 = new Paragraph("Test Results\nTest Marked as Skipped\nSkipping all test steps\nTest complete\nTest SKIPPED\n\n");

            section11.Add(someSectionText11);

            //Добавление теста
            Paragraph title12 = new Paragraph("8.1.2 - MULTICAST NVT HELLO MESSAGE VALIDATION");
            Anchor    anc12   = new Anchor(".");

            anc12.Name = "MULTICAST NVT HELLO MESSAGE VALIDATION";
            title12.Add(anc12);
            Section section12 = section1.AddSection(title12);

            section12.NumberDepth = 0;
            Paragraph someSectionText12 = new Paragraph("Test Results\nTest Marked as Skipped\nSkipping all test steps\nTest complete\nTest SKIPPED\n\n");

            section12.Add(someSectionText12);


            m_Document.Add(chapter2);
        }
Esempio n. 6
0
        /// <summary>
        /// Create chapter content from html
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public Chapter CreateChapterContent(string html)
        {
            // Declare a font to used for the bookmarks
            iTextSharp.text.Font bookmarkFont = FontFactory.GetFont(FontFactory.HELVETICA, 16, iTextSharp.text.Font.NORMAL);

            Chapter chapter = new Chapter(new Paragraph(""), 0);

            chapter.NumberDepth = 0;

            // Create css for some tag
            StyleSheet styles = new StyleSheet();

            styles.LoadTagStyle("h2", HtmlTags.ALIGN_MIDDLE, "center");
            styles.LoadTagStyle("h2", HtmlTags.COLOR, "#F90");
            styles.LoadTagStyle("pre", "size", "10pt");

            // Split H2 Html Tag
            string pattern = @"<\s*h2[^>]*>(.*?)<\s*/h2\s*>";

            string[] result = Regex.Split(html, pattern);

            // Create section title & content
            int sectionIndex = 0;

            foreach (var item in result)
            {
                if (string.IsNullOrEmpty(item))
                {
                    continue;
                }

                if (sectionIndex % 2 == 0)
                {
                    chapter.AddSection(20f, new Paragraph(item, bookmarkFont), 0);
                }
                else
                {
                    foreach (IElement element in HTMLWorker.ParseToList(new StringReader(item), styles))
                    {
                        chapter.Add(element);
                    }
                }

                sectionIndex++;
            }

            chapter.BookmarkTitle = "Demo for Load More Button in Kendo UI Grid";
            return(chapter);
        }
Esempio n. 7
0
        /// <summary>
        /// Create chapter content from html
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public Chapter CreateChapterContent(string html)
        {
            // Declare a font to used for the bookmarks
            var bookmarkFont = FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.NORMAL, new Color(255, 153, 0));

            var chapter = new Chapter(new Paragraph(""), 0)
            {
                NumberDepth = 0
            };

            // Create css for some tag
            var styles = new StyleSheet();

            styles.LoadTagStyle("h2", HtmlTags.HORIZONTALALIGN, "center");
            styles.LoadTagStyle("h2", HtmlTags.COLOR, "#F90");
            styles.LoadTagStyle("pre", "size", "10pt");

            // Split H2 Html Tag
            var pattern = @"<\s*h2[^>]*>(.*?)<\s*/h2\s*>";
            var result  = Regex.Split(html, pattern);

            // Create section title & content
            var sectionIndex = 0;

            foreach (var item in result)
            {
                if (string.IsNullOrEmpty(item))
                {
                    continue;
                }

                if (sectionIndex % 2 == 0)
                {
                    chapter.AddSection(20f, new Paragraph(item, bookmarkFont), 0);
                }
                else
                {
                    foreach (IElement element in HTMLWorker.ParseToList(new StringReader(item), styles))
                    {
                        chapter.Add(element);
                    }
                }

                sectionIndex++;
            }

            chapter.BookmarkTitle = Constants.UnaAbbr + " " + Constants.CisAbbr;
            return(chapter);
        }
Esempio n. 8
0
        private static void WriteChoices(ISPage iSPage, Dictionary <string, int> pageMap, Chapter chapter)
        {
            chapter.Add(new iTextSharp.text.Phrase(String.Format("\nYou have {0} choices:\n", iSPage.Choices.Count)));
            foreach (Choice choice in iSPage.Choices)
            {
                if (pageMap.ContainsKey(choice.RoomId))
                {
                    Anchor anchor = new Anchor(String.Format("{0} - Page {1}\n", choice.Text, pageMap[choice.RoomId]));
                    anchor.Reference = "#" + choice.RoomId;
                    Paragraph paragraph = new Paragraph();
                    paragraph.Add(anchor);
                    chapter.Add(paragraph);


                    //Chunk chunk = new Chunk(String.Format("{0} - Page {1}\n", choice.Text, pageMap[choice.RoomId]));
                    //PdfAction action = PdfAction.GotoLocalPage(pageMap[choice.RoomId], new PdfDestination(0), );
                    //chunk.SetAction(action);
                }
                else
                {
                    chapter.Add(new iTextSharp.text.Phrase(String.Format("{0} - Page {1}\n", choice.Text, "XXX")));
                }
            }
        }
Esempio n. 9
0
 public void Print(string fileName, ProgramIndex programData)
 {
     using (var stream = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
     {
         using (var document = new Document())
         {
             var writer = PdfWriter.GetInstance(document, stream);
             document.Open();
             var numberOfChapters = 0;
             foreach (var student in programData.Students)
             {
                 var c = new Chapter($"{student.LastName}, {student.FirstName} {student.StudentID}",
                                     numberOfChapters++);
                 var t = new PdfPTable(8)
                 {
                     HeaderRows = 1
                 };
                 t.AddCell("Course Name");
                 t.AddCell("Course ID");
                 t.AddCell("Course Number");
                 t.AddCell("Credit");
                 t.AddCell("Semester");
                 t.AddCell("Year");
                 t.AddCell("Course Type");
                 t.AddCell("Grade");
                 var courses = programData.FindCoursesForStudent(student);
                 foreach (var course in courses)
                 {
                     t.AddCell(course.Course.CourseName);
                     t.AddCell(course.Course.CourseID.ToString());
                     t.AddCell(course.Course.CourseNumber);
                     t.AddCell(course.Course.Credit.ToString());
                     t.AddCell(course.Course.Semester);
                     t.AddCell(course.Course.Year.ToString());
                     t.AddCell(course.Course.CourseType);
                     t.AddCell(course.Grade);
                 }
                 c.Add(t);
                 document.Add(c);
             }
         }
     }
 }
Esempio n. 10
0
        public Chap0403()
        {
            Console.WriteLine("Chapter 4 example 3: Chapters and Sections");

            // step 1: creation of a document-object
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);

            try
            {
                // step 2: we create a writer that listens to the document
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0403.pdf", FileMode.Create));
                // step 3: we open the document
                document.Open();
                // step 4: we Add content to the document
                Paragraph title1   = new Paragraph("This is Chapter 1", FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));
                Chapter   chapter1 = new Chapter(title1, 2);
                chapter1.NumberDepth = 0;
                Paragraph someText = new Paragraph("This is some text");
                chapter1.Add(someText);
                Paragraph title11         = new Paragraph("This is Section 1 in Chapter 1", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));
                Section   section1        = chapter1.AddSection(title11);
                Paragraph someSectionText = new Paragraph("This is some silly paragraph in a chapter and/or section. It contains some text to test the functionality of Chapters and Section.");
                section1.Add(someSectionText);
                document.Add(chapter1);

                Paragraph title2   = new Paragraph("This is Chapter 2", FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));
                Chapter   chapter2 = new Chapter(title2, 2);
                chapter2.NumberDepth = 0;
                chapter2.Add(someText);
                Paragraph title21  = new Paragraph("This is Section 1 in Chapter 2", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));
                Section   section2 = chapter2.AddSection(title21);
                section2.Add(someSectionText);
                chapter2.BookmarkOpen = false;
                document.Add(chapter2);
            }
            catch (Exception de)
            {
                Console.Error.WriteLine(de.StackTrace);
            }
            // step 5: we close the document
            document.Close();
        }
Esempio n. 11
0
        private static void WriteContents(String htmlInput, Chapter chapter)
        {
            Font currentFont = FontFactory.GetFont(FontFactory.HELVETICA);

            string output   = htmlInput;
            int    position = 0;

            while (position < output.Length)
            {
                int nextLT = output.Substring(position).IndexOf('<') + position;
                if (nextLT < 0)
                {
                    break;
                }

                if (position != nextLT)
                {
                    chapter.Add(new iTextSharp.text.Chunk(output.Substring(position, nextLT - position), currentFont));
                }

                int    nextGT = output.Substring(position).IndexOf('>') + position;
                string tag    = output.Substring(nextLT, nextGT - nextLT);

                position = nextGT + 1;

                if (tag.StartsWith("<img"))  //insert image
                {
                    if (tag.StartsWith("<img src=\""))
                    {
                        int    startQuote = tag.IndexOf("\"") + 1;
                        int    endQuote   = tag.Substring(startQuote).IndexOf("\"") + startQuote;
                        string imgPath    = tag.Substring(startQuote, endQuote - startQuote);

                        chapter.Add(Image.GetInstance(imgPath));
                    }
                }
                else if (tag.StartsWith("<p>")) //insert paragraph
                {
                    chapter.Add(new iTextSharp.text.Chunk("\t", currentFont));
                }
                else if (tag.StartsWith("<br>")) //insert line break
                {
                    chapter.Add(new iTextSharp.text.Phrase("\r\n", currentFont));
                }
                else if (tag.StartsWith("<b>")) //insert bold
                {
                    if (currentFont.IsItalic())
                    {
                        currentFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLDOBLIQUE);
                    }
                    else
                    {
                        currentFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD);
                    }
                }
                else if (tag.StartsWith("<i>")) //insert italics
                {
                    if (currentFont.IsBold())
                    {
                        currentFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLDOBLIQUE);
                    }
                    else
                    {
                        currentFont = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE);
                    }
                }
                else if (tag.StartsWith("</b>")) //insert bold
                {
                    if (currentFont.IsItalic())
                    {
                        currentFont = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE);
                    }
                    else
                    {
                        currentFont = FontFactory.GetFont(FontFactory.HELVETICA);
                    }
                }
                else if (tag.StartsWith("</i>")) //insert italics
                {
                    if (currentFont.IsBold())
                    {
                        currentFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD);
                    }
                    else
                    {
                        currentFont = FontFactory.GetFont(FontFactory.HELVETICA);
                    }
                }
            }
        }
Esempio n. 12
0
    //public void GeneratePDF(DataSet _ms)
    public void GeneratePDF(String EstNum, String IsFinancial)
    {
        Whitfieldcore _wc = new Whitfieldcore();
        // MemoryStream m = new MemoryStream();
        // Document document = new Document();
        FileStream MyStream = null;
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try
        {
            iTextSharp.text.Font[] fonts = new iTextSharp.text.Font[16];
            fonts[0] = FontFactory.GetFont(FontFactory.COURIER, 8, iTextSharp.text.Font.NORMAL);
            fonts[1] = FontFactory.GetFont(FontFactory.COURIER, 8, iTextSharp.text.Font.BOLD);
            fonts[2] = FontFactory.GetFont(FontFactory.COURIER, 8, iTextSharp.text.Font.ITALIC);
            fonts[3] = FontFactory.GetFont(FontFactory.COURIER, 8, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.ITALIC);
            fonts[4] = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL);
            fonts[5] = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD);
            fonts[6] = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.ITALIC);
            fonts[7] = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.ITALIC);
            fonts[8] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL);
            fonts[9] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD);
            fonts[10] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.ITALIC);
            fonts[11] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.ITALIC);
            fonts[12] = FontFactory.GetFont(FontFactory.SYMBOL, 10, iTextSharp.text.Font.NORMAL);
            fonts[13] = FontFactory.GetFont(FontFactory.ZAPFDINGBATS, 10, iTextSharp.text.Font.NORMAL);
            fonts[14] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.UNDERLINE, iTextSharp.text.Color.GRAY);
            fonts[15] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.GRAY);

            // Response.ContentType = "application/pdf";
            // Response.AddHeader("content-disposition", "attachment;filename=Proposal_Document.pdf");
            //<Current Date> - <Project Name>, Architectural Millwork - WhitfieldCo
            //String _filename = DateTime.Now.ToString("MM-dd-yyyy") + "-"  + txtprjname  + ", Architectural Millwork - WhitfieldCo.pdf"
            //PdfWriter.GetInstance(document, new FileStream(_filename, FileMode.Create));
            //PdfWriter writer = PdfWriter.GetInstance(document, m);
            //writer.CloseStream = false;

            IDataReader iReader = _wc.GetProjectInfo(Convert.ToInt32(EstNum));
            while (iReader.Read())
            {
                txtprjname = iReader["ProjName"] == DBNull.Value ? "" : iReader["ProjName"].ToString();
                lblPrjHeader = iReader["ProjName"] == DBNull.Value ? "" : iReader["ProjName"].ToString();
                txtbasebid = iReader["BaseBid"] == DBNull.Value ? "" : iReader["BaseBid"].ToString();
                txtfinalbid = iReader["FinalPrice"] == DBNull.Value ? "" : iReader["FinalPrice"].ToString();
                txtdesc = iReader["ProjDescr"] == DBNull.Value ? "" : iReader["ProjDescr"].ToString();
                txtNotes = iReader["Notes"] == DBNull.Value ? "" : iReader["Notes"].ToString();
                txtBidDate = iReader["BidDate"] == DBNull.Value ? "" : iReader["BidDate"].ToString();
                txtEditStartTime = iReader["BidTime"] == DBNull.Value ? "" : iReader["BidTime"].ToString();
                txtARDt = iReader["AwardDur"] == DBNull.Value ? "" : iReader["AwardDur"].ToString();
                txtawardDate = iReader["AwardDate"] == DBNull.Value ? "" : iReader["AwardDate"].ToString();
                txtConstStdate = iReader["ConstrStart"] == DBNull.Value ? "" : iReader["ConstrStart"].ToString();
                txtConstDuration = iReader["ConstrDur"] == DBNull.Value ? "" : iReader["ConstrDur"].ToString();
                txtConstEndDate = iReader["ConstrCompl"] == DBNull.Value ? DateTime.Now.ToString() : iReader["ConstrCompl"].ToString();
                //Adding New Fields
                txtfabEndDate = iReader["fab_end"] == DBNull.Value ? "" : iReader["fab_end"].ToString();
                txtfabStartdate = iReader["fab_start"] == DBNull.Value ? "" : iReader["fab_start"].ToString();
                txtfabdurationt = iReader["fab_duration"] == DBNull.Value ? "" : iReader["fab_duration"].ToString();
                txtStreet = iReader["prj_street"] == DBNull.Value ? "" : iReader["prj_street"].ToString();
                txtCity = iReader["prj_city"] == DBNull.Value ? "" : iReader["prj_city"].ToString();
                txtState = iReader["prj_state"] == DBNull.Value ? "" : iReader["prj_state"].ToString();
                txtzip = iReader["prj_zip"] == DBNull.Value ? "" : iReader["prj_zip"].ToString();
                //New Fields Ends
                txtrealprjNumbert = iReader["Real_proj_Number"] == DBNull.Value ? "" : iReader["Real_proj_Number"].ToString();
                prjArch = iReader["Architect"] == DBNull.Value ? "" : iReader["Architect"].ToString();
                prjEsti = iReader["loginid"] == DBNull.Value ? "" : iReader["loginid"].ToString();
                txtTotCotCost = iReader["Contengency"] == DBNull.Value ? "0" : iReader["Contengency"].ToString();
                txtEngRate = iReader["enghourrate"] == DBNull.Value ? "45.00" : iReader["enghourrate"].ToString();
                txtFabRate = iReader["fabhourrate"] == DBNull.Value ? "32.00" : iReader["fabhourrate"].ToString();
                txtInstRate = iReader["insthourrate"] == DBNull.Value ? "45.00" : iReader["insthourrate"].ToString();
                txtMiscRate = iReader["mischourrate"] == DBNull.Value ? "25.00" : iReader["mischourrate"].ToString();
                txtOverHeadRate = iReader["overheadrate"] == DBNull.Value ? "24.11" : iReader["overheadrate"].ToString();
                txtMarkUpPercent = iReader["profit_markup"] == DBNull.Value ? "15.00" : iReader["profit_markup"].ToString();
                txtDrawingDate = iReader["drawingdate"] == DBNull.Value ? "" : iReader["drawingdate"].ToString();
                txtTypeOfWork = iReader["typeofwork"] == DBNull.Value ? "" : iReader["typeofwork"].ToString();
            }

            Chunk chunkHeading;
            if (txtprjname.Length >= 30)
            {
                chunkHeading = new Chunk(txtprjname + "                                                                                                      ", fonts[15]);
            }
            else
            {
                chunkHeading = new Chunk(txtprjname + "                                                                                                                                      ", fonts[15]);
            }

            String _modetype = IsFinancial == "Y" ? "Proposal" : "Scope";

            Int32 _document_rev_number = GenerateseqNumberforDocs(Convert.ToInt32(EstNum), _modetype);

            _filename = DateTime.Now.ToString("MM-dd-yyyy") + "-" + txtprjname.Replace("."," ").Trim() + " Architectural Millwork - WhitfieldCo " + _modetype + "-REV 0" + _document_rev_number + ".pdf";

                //if (File.Exists(HttpContext.Current.Server.MapPath("~/attachments/") + _filename))  //If the file exists, create new one.
                //{
                //    //File.Delete(HttpContext.Current.Server.MapPath("~/attachments/") + _filename);
                //    char[] splitchar = { '.' };
                //    string[] strArr = null;
                //    strArr = _filename.Split(splitchar);
                //    String _filenmTest = strArr[0];
                //    int intIndexSubstring = 0;
                //    intIndexSubstring = _filenmTest.IndexOf("-REV#");
                //    _filename = DateTime.Now.ToString("MM-dd-yyyy") + "-" + txtprjname.Replace(".", " ").Trim() + " Architectural Millwork - WhitfieldCo " + _modetype  +"-REV#0" + (Convert.ToInt32(_filenmTest.Substring(intIndexSubstring).Substring(5)) + 1).ToString() + ".pdf";

                //}
                //FileStream MyStream;
                //MyStream = new FileStream(HttpContext.Current.Server.MapPath("~/attachments/") + _filename, FileMode.Create);
                //PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Server.MapPath("~/attachments/") + _filename, FileMode.Create));
                //using (StreamWriter sw = File.CreateText(mappath + "patientquery.txt"))

            using ( MyStream = new FileStream(HttpContext.Current.Server.MapPath("~/attachments/") + _filename, FileMode.Create))
            //using (FileStream MyStream = File.Create(HttpContext.Current.Server.MapPath("~/attachments/") + _filename))
            //new FileStream(HttpContext.Current.Server.MapPath("~/attachments/") + _filename, FileMode.Create)
            {
                PdfWriter.GetInstance(document, MyStream);
                //attachments
                document.AddAuthor("Whitfield Corporation");
                document.AddSubject("Proposal Generator");

                iTextSharp.text.Image img = this.DoGetImageFile(HttpContext.Current.Server.MapPath("~/assets/img/TWC Primary Logo1.JPG"));
                img.ScalePercent(50);
                Chunk ck = new Chunk(img, 0, -5);

                HeaderFooter headerRight = new HeaderFooter(new Phrase(chunkHeading), new Phrase(ck));
                document.Header = headerRight;
                headerRight.Alignment = iTextSharp.text.Rectangle.ALIGN_RIGHT;
                headerRight.Border = iTextSharp.text.Rectangle.NO_BORDER;

                // we Add a Footer that will show up on PAGE 1
                Phrase phFooter = new Phrase("The Whitfield Corporation, Incorporated  ", fonts[15]);
                phFooter.Add(new Phrase("P.O. Box 0385, Fulton, MD 20759  ", fonts[8]));
                phFooter.Add(new Phrase("Main: 301 483 0791 Fax: 301 483 0792  ", fonts[8]));
                phFooter.Add(new Phrase("\nDelivering on Promises", fonts[11]));
                //
                HeaderFooter footer = new HeaderFooter(phFooter, false);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                footer.Alignment = iTextSharp.text.Rectangle.ALIGN_CENTER;
                document.Footer = footer;
                // step 3: we open the document
                document.Open();

                // we Add a Header that will show up on PAGE 2

                DateTime dt = DateTime.Now;
                //Chapters and Sections
                int ChapterSequence = 1;
                document.NewPage();
                iTextSharp.text.Font chapterFont = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 16, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);
                iTextSharp.text.Font sectionFont = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
                iTextSharp.text.Font subsectionFont = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 14, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);

                //Chapter 1 Overview
                Paragraph cTitle = new Paragraph(_modetype, chapterFont);
                Chapter chapter = new Chapter(cTitle, ChapterSequence);

                Paragraph ChapterDate = new Paragraph(dt.ToString("\nMMMM dd, yyyy \n\n"), fonts[8]);
                Paragraph ChapterRef = new Paragraph("RE:   " + txtprjname + "\n\n", fonts[8]);

                Paragraph ChapterText1;

                if (txtTypeOfWork.Trim() == "Time & Material")
                {

                    ChapterText1 = new Paragraph("Whitfield proposes to complete the scope of work on a Time & Material basis per the rates included in the Item Breakdown section of this proposal.\n\n", fonts[8]);
                }
                else
                {
                    ChapterText1 = new Paragraph("Whitfield proposes to furnish all materials and perform all labor necessary, including " + txtTypeOfWork + ", to complete the following scope of work as per the Scope of Work breakdown.\n\n", fonts[8]);
                }

                String _fnlAmt = "";
                String amtWithnoDecimal = "";

                if (txtbasebid != "")
                {
                    string[] txtBaseBidStr = txtbasebid.Split('.');
                    custom.util.NumberToEnglish num = new custom.util.NumberToEnglish();
                    _fnlAmt = num.changeCurrencyToWords(txtBaseBidStr[0].Replace("$", "").Trim());
                    amtWithnoDecimal = txtBaseBidStr[0] + ".00";
                }

                contingency _cont = new contingency();
                if (IsFinancial == "Y")
                {

                    Paragraph ChapterText2;
                    if (txtTypeOfWork.Trim() == "Time & Material")
                    {
                        ChapterText2 = new Paragraph("The Material cost in the amount of " + _fnlAmt + " Dollars and No Cents (" + Convert.ToDecimal(amtWithnoDecimal).ToString("C") + ") includes all profit markup and assumes a construction start on approximately " + Convert.ToDateTime(txtConstStdate).ToString("MMMM dd, yyyy") + " with a completion on or around " + Convert.ToDateTime(txtConstEndDate).ToString("MMMM dd, yyyy") + " .\n\n", fonts[8]);
                        //ChapterText2.Add(new Phrase(new Chunk("This cost is in addition to any Time & Material cost and will be calculated on a unit price basis as included in the Item Breakdown section of this proposal for any time extension beyond the agreed upon construction schedule as included in this proposal.\n\n", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK))));
                    }
                    else
                    {
                        ChapterText2 = new Paragraph("This proposal assumes all of the above work completed by " + Convert.ToDateTime(txtConstEndDate).ToString("MMMM dd, yyyy") + " for the sum of ", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK));
                        ChapterText2.Add(new Phrase(new Chunk(" " + _fnlAmt + "Dollars and No Cents (" + Convert.ToDecimal(amtWithnoDecimal).ToString("C") + ").\n\n", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK))));
                    }

                    chapter.Add(ChapterDate);
                    chapter.Add(ChapterRef);
                    chapter.Add(ChapterText1);
                    chapter.Add(ChapterText2);

                    // Chapter Item Breakdown
                    DataSet dsCont = _cont.FetchProjectItemBreakdown(Convert.ToInt32(EstNum));
                    if (dsCont.Tables[0].Rows.Count > 0)
                    {
                        Paragraph cBreakDown = new Paragraph("Item Breakdown", chapterFont);
                        chapter.Add(cBreakDown);
                        DataTable myValues;
                        myValues = dsCont.Tables[0];
                        int icntBreakDown = 1;
                        foreach (DataRow dRow in myValues.Rows)
                        {
                            String _cntlDesc = dRow["Description"] == DBNull.Value ? "" : dRow["Description"].ToString();
                            String _cntlAmt = dRow["Amount"] == DBNull.Value ? "" : dRow["Amount"].ToString();
                            Paragraph itemAlternatives = new Paragraph(icntBreakDown.ToString() + ". " + _cntlDesc + "...." + _cntlAmt, fonts[8]);
                            icntBreakDown++;
                            chapter.Add(itemAlternatives);
                        }

                    }

                    // Chapter Alternatives
                    DataSet dsAlternatives = _cont.FetchAlternatives(Convert.ToInt32(EstNum));
                    if (dsAlternatives.Tables[0].Rows.Count > 0)
                    {
                        Paragraph c = new Paragraph("\nAlternates", fonts[14]);
                        chapter.Add(c);
                        DataTable myValues;
                        myValues = dsAlternatives.Tables[0];
                        int icntAlternatives = 1;
                        foreach (DataRow dRow in myValues.Rows)
                        {
                            String _altType = dRow["Type"] == DBNull.Value ? "" : dRow["Type"].ToString();
                            String _cntlDesc = dRow["Description"] == DBNull.Value ? "" : dRow["Description"].ToString();
                            String _cntlAmt = dRow["Amount"] == DBNull.Value ? "" : dRow["Amount"].ToString();
                            Paragraph itemAlternatives = new Paragraph(icntAlternatives.ToString() + ". " + _altType + ":" + _cntlDesc + "...." + _cntlAmt, fonts[8]);
                            icntAlternatives++;
                            chapter.Add(itemAlternatives);
                        }
                    }
                    //document.Add(chapter);
                    //Chapters and Sections Declarations End.
                }

                //**********************Chapter for Itemized Scope of Work Begins
                //ChapterSequence++;
                Paragraph cAssumptions = new Paragraph("\nItemized Scope of Work", chapterFont);
                chapter.Add(cAssumptions);
                //Chapter chapterAssumptions = new Chapter(cAssumptions, ChapterSequence);

                //Paragraph AssumptionsHeading = new Paragraph("Scope of Work\n\n", sectionFont);
                Paragraph AssumptionsText1 = new Paragraph("Provided hereto is an itemized clarification of the proposed scope. It has been developed and derived from the pricing documents to clarify various assumptions that were considered while compiling this estimate. The General Conditions (listed last) occur throughout the scope of work and apply to “typical applications”, which are subsequently itemized in the corresponding breakdown. " + ".\n\n", fonts[8]);
                //AssumptionsText1.Add(new Phrase(new Chunk("Proposed price includes " + txtTypeOfWork + ".\n\n", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK))));
                //chapterAssumptions.Add(AssumptionsHeading);
                chapter.Add(AssumptionsText1);

                DataSet dsScope = _wc.GetWorkOrders(EstNum);
                if (dsScope.Tables[0].Rows.Count > 0)
                {
                    LoadScopeOfWork(chapter, dsScope, fonts[14]);
                }

                Paragraph DrawingsPara1 = new Paragraph("Drawings:", fonts[14]);
                chapter.Add(DrawingsPara1);

                Paragraph itemDrawing = new Paragraph(txtprjname + " drawings prepared by " + _wc.GetArchitectName(Convert.ToInt32(prjArch)) + " dated " + txtDrawingDate + ".", fonts[8]);
                chapter.Add(itemDrawing);

                DataSet dsSpecs = _cont.FetchAmendmenList(Convert.ToInt32(EstNum));
                if (dsSpecs.Tables[0].Rows.Count > 0)
                {
                    Paragraph DrawingsPara = new Paragraph("\nAdditional Documents:", fonts[14]);
                    chapter.Add(DrawingsPara);
                    DataTable MyTerms;
                    MyTerms = dsSpecs.Tables[0];
                    int icntamendments = 1;
                    foreach (DataRow dRow in MyTerms.Rows)
                    {
                        String _AmedmentsType = dRow["type"] == DBNull.Value ? "" : dRow["type"].ToString();
                        String _AmedmentNumber = dRow["amendment_number"] == DBNull.Value ? "" : dRow["amendment_number"].ToString();
                        String _AmedmentDate = dRow["amendment_date"] == DBNull.Value ? "" : dRow["amendment_date"].ToString();
                        String amendment_impact = dRow["amendment_impact"] == DBNull.Value ? "" : dRow["amendment_impact"].ToString();
                        //if (_AmedmentsType == "Amendment")
                        //{
                        if (amendment_impact.ToLower() == "yes")
                        {
                            Paragraph itemAmendment = new Paragraph(icntamendments.ToString() + ". " + _AmedmentsType + " " + _AmedmentNumber + " dated " + _AmedmentDate + " impacts this scope of work.", fonts[8]);
                            chapter.Add(itemAmendment);
                            //Amendment 001 dated 11/19/2010; This Amendment has no impact to this scope of work.
                        }
                        else
                        {
                            Paragraph itemAmendment = new Paragraph(icntamendments.ToString() + ". " + _AmedmentsType + " " + _AmedmentNumber + " dated " + _AmedmentDate + " does not impact this scope of work.", fonts[8]);
                            chapter.Add(itemAmendment);
                        }

                        //}
                        //else
                        //{
                        //    Paragraph itemAmendment = new Paragraph(icntamendments.ToString() + ". " + _AmedmentsType + " " + _AmedmentNumber + " " + _AmedmentDate, fonts[8]);
                        //    chapter.Add(itemAmendment);
                        //}

                        icntamendments++;
                    }
                }
                //Qualifications
                DataSet dsConditions = _wc.GetSpecExcl(Convert.ToInt32(EstNum));
                if (dsConditions.Tables[0].Rows.Count > 0)
                {
                    Paragraph DrawingsPara = new Paragraph("\nQualifications:", fonts[14]);
                    chapter.Add(DrawingsPara);
                    int icnt = 1;
                    DataTable MyConditions;
                    MyConditions = dsConditions.Tables[0];
                    int tQualid = 0;
                    foreach (DataRow dRow in MyConditions.Rows)
                    {
                        if (Convert.ToInt32(dRow["qual_id"].ToString()) != tQualid)
                        {
                            Paragraph itemheading = new Paragraph(dRow["gName1"].ToString(), fonts[9]);
                            chapter.Add(itemheading);
                        }
                        String _cntlDesc = dRow["description"] == DBNull.Value ? "" : dRow["description"].ToString();
                        Paragraph itemTerms = new Paragraph(icnt.ToString() + ".  " + _cntlDesc, fonts[8]);
                        chapter.Add(itemTerms);
                        tQualid = Convert.ToInt32(dRow["qual_id"].ToString());
                        icnt++;
                    }
                }

                // document.Add(chapter);
                //************************Chapter for Itemized Scope of Work Ends

                //*******Chapter Terms Begins********************
                //ChapterSequence++;
                Paragraph cTerms = new Paragraph("\nTerms", fonts[14]);
                //Chapter chapterTerms = new Chapter(cTerms, ChapterSequence);
                chapter.Add(cTerms);
                //Chapter chapterTerms = new Chapter(cTerms, ChapterSequence);
                DataSet dsTerms = _wc.GetTerms(Convert.ToInt32(EstNum));

                if (dsTerms.Tables[0].Rows.Count > 0)
                {
                    DataTable MyTerms;
                    MyTerms = dsTerms.Tables[0];
                    int icntTerms = 1;
                    foreach (DataRow dRow in MyTerms.Rows)
                    {
                        String _cntlDesc = dRow["description"] == DBNull.Value ? "" : dRow["description"].ToString();
                        Paragraph itemTerms = new Paragraph(icntTerms.ToString() + ". " + _cntlDesc, fonts[8]);
                        chapter.Add(itemTerms);
                        icntTerms++;
                    }
                }

                Paragraph ChapterFooterText1 = new Paragraph("\nAll or part of the contract amount may be subject to change pending completion delay beyond agreed completion date and/or if changes to quantities are made. All agreements must be in writing prior to execution of any work.\n\n", fonts[8]);
                ChapterFooterText1.Add(Chunk.NEWLINE);
                ChapterFooterText1.Add(new Chunk("Respectfully submitted, ", fonts[8]));
                ChapterFooterText1.Add(new Chunk("                                                                  "));
                ChapterFooterText1.Add(new Chunk("Accepted By:, ", fonts[8]));
                ChapterFooterText1.Add(Chunk.NEWLINE);
                ChapterFooterText1.Add(new Chunk("The Whitfield Co., Inc., ", fonts[8]));
                ChapterFooterText1.Add(new Chunk("                                                                      "));
                ChapterFooterText1.Add(new Chunk("________________________ Date_________", fonts[8]));
                ChapterFooterText1.Add(Chunk.NEWLINE);
                ChapterFooterText1.Add(new Chunk("Jammie Whitfield, ", fonts[8]));
                ChapterFooterText1.Add(new Chunk("                                                                              "));
                ChapterFooterText1.Add(new Chunk("Name, Title", fonts[8]));
                //Paragraph ChapterFooterText2 = new Paragraph("Respectfully submitted,", fonts[8]);
                //Paragraph ChapterFooterText3 = new Paragraph("The Whitfield Co., Inc.\n\n", fonts[8]);
                //Paragraph ChapterFooterText4 = new Paragraph("Jammie Whitfield,", fonts[8]);
                //Paragraph ChapterFooterText5 = new Paragraph("Estimator", fonts[8]);

                chapter.Add(ChapterFooterText1);
                // Paragraph ChapterFooterText2 = new Paragraph("Respectfully submitted,", fonts[8]);
               // Paragraph ChapterFooterText3 = new Paragraph("The Whitfield Co., Inc.\n\n", fonts[8]);
                //Paragraph ChapterFooterText4 = new Paragraph("Jammie Whitfield,\n\n", fonts[8]);
                //Paragraph ChapterFooterText5 = new Paragraph("Accepted By:\n\n", fonts[8]);
               // Paragraph ChapterFooterText6 = new Paragraph("________________________ Date__________", fonts[8]);
               // Paragraph ChapterFooterText7 = new Paragraph("Name, Title", fonts[8]);

                chapter.Add(ChapterFooterText1);
               // chapter.Add(ChapterFooterText2);
               // chapter.Add(ChapterFooterText3);
               // chapter.Add(ChapterFooterText4);
               // chapter.Add(ChapterFooterText5);
                document.Add(chapter);

                //document.Add(new Chunk("Respectfully submitted, ", fonts[8]));
                //document.Add(new Chunk("                                                               "));
                //document.Add(new Chunk("Accepted By:, ", fonts[8]));
                //document.Add(Chunk.NEWLINE);
                //document.Add(new Chunk("The Whitfield Co., Inc., ", fonts[8]));
                //document.Add(new Chunk("                                                            "));
                //document.Add(new Chunk("________________________ Date_________", fonts[8]));
                //document.Add(Chunk.NEWLINE);
                //document.Add(new Chunk("Jammie Whitfield, ", fonts[8]));
                //document.Add(new Chunk("                                                                     "));
                //document.Add(new Chunk("Name, Title", fonts[8]));
                //*******Chapter Terms Ends********************
                document.Close();
                //MyStream.Flush();
                //MyStream.Close();
                //MyStream.Dispose();
                //}
                SetupEmailDocs(Convert.ToInt32(EstNum), _document_rev_number, _filename, _modetype);
                sendEmail(EstNum, _filename, IsFinancial);
            }
        }
        catch (DocumentException ex)
        {
            HttpResponse objResponse = HttpContext.Current.Response;
            objResponse.Write(ex.Message);
        }
        finally
        {
            if (MyStream != null)
            {
                MyStream.Close();
                MyStream.Dispose();
            }
        }

        //Response.Buffer = true;
        //Response.Clear();
        //Write pdf byes to outputstream
        //Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
        //Response.OutputStream.Flush();
        //Response.End();
    }
Esempio n. 13
0
    private void LoadScopeOfWork(Chapter chapterScope, DataSet ds, iTextSharp.text.Font font1)
    {
        int NumColumns = 4;
        try
        {
            // we add some meta information to the document
            //Paragraph DrawingsPara = new Paragraph("Scope of Work:\n\n", font1);
            //chapterScope.Add(DrawingsPara);

            PdfPTable datatable = new PdfPTable(NumColumns);
            //iTextSharp.text.Table datatable = new iTextSharp.text.Table(NumColumns);
            datatable.DefaultCell.Padding = 4;
            float[] headerwidths = { 8, 20, 45, 20 }; // percentage
            datatable.SetWidths(headerwidths);
            datatable.WidthPercentage = 100; // percentage

            datatable.DefaultCell.BorderWidth = 1;
            datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
            //datatable.AddCell("No.");
            datatable.AddCell(new Phrase("No.", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.Font.NORMAL)));
            //datatable.AddCell("Description");
            datatable.AddCell(new Phrase("Description", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.Font.NORMAL)));
            //datatable.AddCell("Notes");
            datatable.AddCell(new Phrase("Notes", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.Font.NORMAL)));
            //datatable.AddCell("Reference");
            datatable.AddCell(new Phrase("Reference", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.Font.NORMAL)));
            datatable.HeaderRows = 1;  // this is the end of the table header
            datatable.DefaultCell.BorderWidth = 1;

            int i = 1;
            DataTable MyScope;
            MyScope = ds.Tables[0];

            foreach (DataRow dRow in MyScope.Rows)
            {
                String _number = dRow["work_order_id"] == DBNull.Value ? "" : dRow["work_order_id"].ToString();
                String _description = dRow["Description"] == DBNull.Value ? "" : dRow["Description"].ToString();
                String _notes = dRow["notes1"] == DBNull.Value ? "" : dRow["notes1"].ToString();
                String _reference = dRow["reftext"] == DBNull.Value ? "" : dRow["reftext"].ToString();
                datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                if (i % 2 == 1)
                {
                    datatable.DefaultCell.GrayFill = 0.9f;
                }
                datatable.AddCell(new Phrase(_number, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL)));
                datatable.AddCell(new Phrase(_description, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL)));
                datatable.AddCell(new Phrase(_notes, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL)));
                datatable.AddCell(new Phrase(_reference, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL)));

                if (i % 2 == 1)
                {
                    datatable.DefaultCell.GrayFill = 1.0f;
                }
                i++;
            }
            chapterScope.Add(datatable);
        }
        catch (Exception ex)
        {
            HttpResponse objResponse = HttpContext.Current.Response;
            objResponse.Write(ex.Message);
        }
    }
Esempio n. 14
0
        public static void Export(string file, Dictionary <TestMethod, StepFrame> frames, int flowCount, long recordCount, float randomness, ComputerConfiguration computerInfo, ReportType type)
        {
            var doc = new Document(PageSize.A4);

            if (File.Exists(file))
            {
                File.Delete(file);
            }

            var fileStream = new FileStream(file, FileMode.OpenOrCreate);

            PdfWriter.GetInstance(doc, fileStream);
            doc.Open();

            // Add header page.
            PdfPTable firstPageTable = new PdfPTable(1);

            firstPageTable.WidthPercentage = 100;

            PdfPCell title = new PdfPCell();

            title.VerticalAlignment   = Element.ALIGN_MIDDLE;
            title.HorizontalAlignment = Element.ALIGN_CENTER;
            title.MinimumHeight       = doc.PageSize.Height - (doc.BottomMargin + doc.TopMargin);
            title.AddElement(Image.GetInstance((System.Drawing.Image)DatabaseBenchmark.Properties.Resources.logo_01, Color.WHITE));

            firstPageTable.AddCell(title);
            doc.Add(firstPageTable);

            int  chapterCount = 1;
            Font chapterFont  = new Font(Font.TIMES_ROMAN, 16f, Font.TIMES_ROMAN, new Color(System.Drawing.Color.CornflowerBlue));

            Chapter benchamrkConfiguration = new Chapter(new Paragraph("Benchmark parameters.", chapterFont), chapterCount++);

            benchamrkConfiguration.Add(new Chunk("\n"));

            ExportTestSettings(benchamrkConfiguration, chapterFont, flowCount, recordCount, randomness);
            ExportComputerSpecification(benchamrkConfiguration, chapterFont, computerInfo);

            doc.Add(benchamrkConfiguration);

            foreach (var fr in frames)
            {
                StepFrame       frame = fr.Value;
                List <BarChart> barCharts;

                if (type == ReportType.Summary)
                {
                    barCharts = frame.GetSummaryBarCharts();
                }
                else
                {
                    barCharts = frame.GetAllBarCharts();
                }

                string  chapterTitle = fr.Key == TestMethod.SecondaryRead ? "Secondary read" : fr.Key.ToString();
                Chapter chapter      = new Chapter(new Paragraph(chapterTitle, chapterFont), chapterCount++);
                chapter.Add(new Chunk("\n"));

                for (int i = 0; i < barCharts.Count; i++)
                {
                    Image image = Image.GetInstance(barCharts[i].ConvertToByteArray());
                    image.Alignment = Element.ALIGN_CENTER;

                    if (type == ReportType.Summary)
                    {
                        image.ScaleToFit(doc.PageSize.Width - 20, 271);
                    }
                    else
                    {
                        image.ScalePercent(100);
                    }

                    chapter.Add(image);
                }

                if (type == ReportType.Detailed)
                {
                    PdfPTable table = new PdfPTable(1);
                    table.WidthPercentage = 100;

                    AddCellToTable(table, "Average Speed:", frame.lineChartAverageSpeed.ConvertToByteArray);
                    AddCellToTable(table, "Moment Speed:", frame.lineChartMomentSpeed.ConvertToByteArray);
                    AddCellToTable(table, "Average Memory:", frame.lineChartMomentMemory.ConvertToByteArray);
                    //AddCellToTable(table, "Average CPU:", frame.lineChartAverageCPU.ConvertToByteArray);
                    //AddCellToTable(table, "Average I/O:", frame.lineChartAverageIO.ConvertToByteArray);

                    chapter.Add(table);
                }

                doc.Add(chapter);
            }

            doc.Close();

            foreach (var item in frames)
            {
                item.Value.ResetColumnStyle();
            }
        }
        public void ExportAsPDF(FileStream stream)
        {
            //set up letter size document,
            //with 36 PT( .5 in) left and right margins
            //and 108PT (1.5in) top and bottom margin
            using (Document document = new Document(PageSize.LETTER, 36, 36, 108, 108))
                //setup writer
                using (PdfWriter writer = PdfWriter.GetInstance(document, stream))
                {
                    document.AddHeader(Header.AUTHOR, "FMSC");
                    document.AddHeader(Header.CREATIONDATE, DateTime.Today.ToShortDateString());
                    document.Open();
                    if (IsExportTreesSelected)
                    {
                        Chapter chapter = new Chapter("Trees", 0);
                        chapter.NumberDepth = 0;
                        PdfPTable table = new PdfPTable(TreeFields.Count)
                        {
                            WidthPercentage = 100F,
                            HeaderRows      = 1,
                            SpacingBefore   = 10F,
                            SplitLate       = false
                        };

                        //write the headers
                        foreach (FieldDiscriptor field in TreeFields)
                        {
                            table.AddCell(field.Header);
                        }

                        //fill in data
                        foreach (TreeDO tree in Trees)
                        {
                            foreach (FieldDiscriptor field in TreeFields)
                            {
                                String text = GetFieldText(tree, field);
                                table.AddCell(text);
                            }
                        }

                        //add chapter to document

                        chapter.Add(table);
                        document.Add(chapter);
                    }

                    if (IsExportLogsSelected)
                    {
                        Chapter chapter = new Chapter("Logs", 0);
                        chapter.NumberDepth = 0;
                        PdfPTable table = new PdfPTable(LogFields.Count)
                        {
                            HeaderRows      = 1,
                            WidthPercentage = 100F,
                            SpacingBefore   = 10F
                        };

                        //write headers
                        foreach (FieldDiscriptor field in LogFields)
                        {
                            table.AddCell(field.Header);
                        }

                        foreach (LogDO log in Logs)
                        {
                            foreach (FieldDiscriptor field in LogFields)
                            {
                                String text = GetFieldText(log, field);
                                table.AddCell(text);
                            }
                        }

                        chapter.Add(table);
                        document.Add(chapter);
                    }

                    if (IsExportPlotsSelected)
                    {
                        Chapter chapter = new Chapter("Plots", 0);
                        chapter.NumberDepth = 0;
                        PdfPTable table = new PdfPTable(PlotFields.Count)
                        {
                            HeaderRows      = 1,
                            WidthPercentage = 100F,
                            SpacingBefore   = 10F
                        };

                        //write headers

                        foreach (FieldDiscriptor field in PlotFields)
                        {
                            table.AddCell(field.Header);
                        }

                        foreach (PlotDO plot in Plots)
                        {
                            foreach (FieldDiscriptor field in PlotFields)
                            {
                                String text = GetFieldText(plot, field);
                                table.AddCell(text);
                            }
                        }

                        chapter.Add(table);
                        document.Add(chapter);
                    }

                    if (IsExportCountsSelected)
                    {
                        Chapter chapter = new Chapter("Counts", 0);
                        chapter.NumberDepth = 0;
                        PdfPTable table = new PdfPTable(CountFields.Count)
                        {
                            WidthPercentage = 100F,
                            HeaderRows      = 1,
                            SpacingBefore   = 10F
                        };

                        foreach (FieldDiscriptor field in CountFields)
                        {
                            table.AddCell(field.Header);
                        }

                        foreach (CountTreeDO count in Counts)
                        {
                            foreach (FieldDiscriptor field in CountFields)
                            {
                                String text = GetFieldText(count, field);
                                table.AddCell(text);
                            }
                        }

                        chapter.Add(table);
                        document.Add(chapter);
                    }
                }
        }
Esempio n. 16
0
        public void BuildReport(ReportInfo report, string targetFile)
        {
            Font     font     = GetFont();
            Document document = new Document(PageSize.A4);

            PdfWriter writer       = PdfWriter.GetInstance(document, new FileStream(targetFile, FileMode.Create));
            bool      hasCoverPath = !string.IsNullOrEmpty(report.CoverPath);
            // Our custom Header and Footer is done using Event Handler
            MyPageEventHelper PageEventHandler = new MyPageEventHelper();

            writer.PageEvent = PageEventHandler;
            // Define the page header
            PageEventHandler.BaseFont   = BaseFont;
            PageEventHandler.Title      = report.PageTitle;
            PageEventHandler.HeaderFont = new Font(BaseFont, 10, Font.BOLD);
            PageEventHandler.HasCover   = hasCoverPath;

            //MyPdfPageEventHelpPageNo pageeventhandler = new MyPdfPageEventHelpPageNo();
            //writer.PageEvent = pageeventhandler;

            if (string.IsNullOrEmpty(report.WaterMarkName))
            {
                if (!string.IsNullOrEmpty(report.Password))
                {
                    writer.SetEncryption(PdfWriter.STRENGTH40BITS, report.Password, report.Password, PdfWriter.AllowPrinting);
                }
            }

            document.AddAuthor(report.Author);
            document.AddCreationDate();
            document.AddCreator(report.Creator);
            document.AddSubject(report.Subject);
            document.AddTitle(report.Title);
            document.AddKeywords(report.Keywords);
            document.AddHeader("Expires", "0");
            document.Open();

            PdfContentByte cb = writer.DirectContent;

            if (hasCoverPath)
            {
                PdfReader       reader  = new PdfReader(report.CoverPath);
                PdfImportedPage newPage = writer.GetImportedPage(reader, 1);
                cb.AddTemplate(newPage, 0, 0);
            }

            // 目录导航
            int chapterNum = 1;

            Chapter chapter0 = new Chapter(new Paragraph(report.Title, new Font(BaseFont, 15f, Font.BOLD)), chapterNum);
            List    list     = new List(List.UNORDERED, false, 10f);

            list.ListSymbol      = new Chunk("\u2022", font);
            list.IndentationLeft = 15f;
            BuildList(report.PeportFiles, list, "1.", 1);
            chapter0.Add(list);
            document.Add(chapter0);

            // 生成章节
            BuildChapter(report, document, writer, cb, font, chapter0, chapterNum);
            document.Close();
        }
Esempio n. 17
0
        private void CreateTable(string id_add, string name_add, string measure_add, string amount_add, string date_add, string price_add, string final_price_add)
        {
            string   fg         = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "Fradm.TTF");
            BaseFont fgBaseFont = BaseFont.CreateFont(fg, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font     fgFont     = new Font(fgBaseFont, 9, Font.NORMAL, BaseColor.BLACK);

            var title = new Paragraph("Счет на оплату", fgFont);

            title.Alignment    = Element.ALIGN_CENTER;
            title.SpacingAfter = 5;

            var    chapter = new Chapter(1);
            var    table   = new PdfPTable(7);
            Phrase p;

            p = new Phrase("номер по порядку", fgFont);
            table.AddCell(CreateCell(p, rows: 2));

            p = new Phrase("товар", fgFont);
            table.AddCell(CreateCell(p, rows: 1));

            p = new Phrase("единица измерения", fgFont);
            table.AddCell(CreateCell(p, rows: 1));

            p = new Phrase("количество", fgFont);
            table.AddCell(CreateCell(p, rows: 2));

            p = new Phrase("цена за единицу товара", fgFont);
            table.AddCell(CreateCell(p, rows: 2));

            p = new Phrase("общая цена", fgFont);
            table.AddCell(CreateCell(p, rows: 2));

            p = new Phrase("дата", fgFont);
            table.AddCell(CreateCell(p, rows: 2));

            p = new Phrase("наименование", fgFont);
            table.AddCell(CreateCell(p));

            p = new Phrase("наименование", fgFont);
            table.AddCell(CreateCell(p));

            p = new Phrase("1 ");
            table.AddCell(CreateCell(p));

            p = new Phrase("2 ");
            table.AddCell(CreateCell(p));

            p = new Phrase("3 ");
            table.AddCell(CreateCell(p));

            p = new Phrase("4 ");
            table.AddCell(CreateCell(p));

            p = new Phrase("5 ");
            table.AddCell(CreateCell(p));

            p = new Phrase("6 ");
            table.AddCell(CreateCell(p));

            p = new Phrase("7 ");
            table.AddCell(CreateCell(p));

            p = new Phrase(id_add);
            table.AddCell(CreateCell(p));

            p = new Phrase(name_add);
            table.AddCell(CreateCell(p));

            p = new Phrase(amount_add);
            table.AddCell(CreateCell(p));

            p = new Phrase(measure_add);
            table.AddCell(CreateCell(p));

            p = new Phrase(price_add);
            table.AddCell(CreateCell(p));

            p = new Phrase(final_price_add);
            table.AddCell(CreateCell(p));

            p = new Phrase(date_add);
            table.AddCell(CreateCell(p));

            table.SpacingAfter = 10;

            var subtitle1 = new Paragraph("___________", fgFont);

            subtitle1.Alignment = Element.ALIGN_RIGHT;

            var subtitle = new Paragraph("Подпись", fgFont);

            subtitle.Alignment    = Element.ALIGN_RIGHT;
            subtitle.SpacingAfter = 5;

            chapter.Add(title);
            chapter.Add(table);
            chapter.Add(subtitle1);
            chapter.Add(subtitle);
            _doc.Add(chapter);
        }
Esempio n. 18
0
    //public void GeneratePDF(DataSet _ms)
    public void GeneratePDF(String EstNum, String IsFinancial)
    {
        Whitfieldcore _wc = new Whitfieldcore();
        // MemoryStream m = new MemoryStream();
        // Document document = new Document();
        FileStream MyStream = null;
        Document   document = new Document(PageSize.A4, 50, 50, 50, 50);

        try
        {
            iTextSharp.text.Font[] fonts = new iTextSharp.text.Font[16];
            fonts[0]  = FontFactory.GetFont(FontFactory.COURIER, 8, iTextSharp.text.Font.NORMAL);
            fonts[1]  = FontFactory.GetFont(FontFactory.COURIER, 8, iTextSharp.text.Font.BOLD);
            fonts[2]  = FontFactory.GetFont(FontFactory.COURIER, 8, iTextSharp.text.Font.ITALIC);
            fonts[3]  = FontFactory.GetFont(FontFactory.COURIER, 8, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.ITALIC);
            fonts[4]  = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL);
            fonts[5]  = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD);
            fonts[6]  = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.ITALIC);
            fonts[7]  = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.ITALIC);
            fonts[8]  = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL);
            fonts[9]  = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD);
            fonts[10] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.ITALIC);
            fonts[11] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.ITALIC);
            fonts[12] = FontFactory.GetFont(FontFactory.SYMBOL, 10, iTextSharp.text.Font.NORMAL);
            fonts[13] = FontFactory.GetFont(FontFactory.ZAPFDINGBATS, 10, iTextSharp.text.Font.NORMAL);
            fonts[14] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.UNDERLINE, iTextSharp.text.Color.GRAY);
            fonts[15] = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.GRAY);

            // Response.ContentType = "application/pdf";
            // Response.AddHeader("content-disposition", "attachment;filename=Proposal_Document.pdf");
            //<Current Date> - <Project Name>, Architectural Millwork - WhitfieldCo
            //String _filename = DateTime.Now.ToString("MM-dd-yyyy") + "-"  + txtprjname  + ", Architectural Millwork - WhitfieldCo.pdf"
            //PdfWriter.GetInstance(document, new FileStream(_filename, FileMode.Create));
            //PdfWriter writer = PdfWriter.GetInstance(document, m);
            //writer.CloseStream = false;



            IDataReader iReader = _wc.GetProjectInfo(Convert.ToInt32(EstNum));
            while (iReader.Read())
            {
                txtprjname       = iReader["ProjName"] == DBNull.Value ? "" : iReader["ProjName"].ToString();
                lblPrjHeader     = iReader["ProjName"] == DBNull.Value ? "" : iReader["ProjName"].ToString();
                txtbasebid       = iReader["BaseBid"] == DBNull.Value ? "" : iReader["BaseBid"].ToString();
                txtfinalbid      = iReader["FinalPrice"] == DBNull.Value ? "" : iReader["FinalPrice"].ToString();
                txtdesc          = iReader["ProjDescr"] == DBNull.Value ? "" : iReader["ProjDescr"].ToString();
                txtNotes         = iReader["Notes"] == DBNull.Value ? "" : iReader["Notes"].ToString();
                txtBidDate       = iReader["BidDate"] == DBNull.Value ? "" : iReader["BidDate"].ToString();
                txtEditStartTime = iReader["BidTime"] == DBNull.Value ? "" : iReader["BidTime"].ToString();
                txtARDt          = iReader["AwardDur"] == DBNull.Value ? "" : iReader["AwardDur"].ToString();
                txtawardDate     = iReader["AwardDate"] == DBNull.Value ? "" : iReader["AwardDate"].ToString();
                txtConstStdate   = iReader["ConstrStart"] == DBNull.Value ? "" : iReader["ConstrStart"].ToString();
                txtConstDuration = iReader["ConstrDur"] == DBNull.Value ? "" : iReader["ConstrDur"].ToString();
                txtConstEndDate  = iReader["ConstrCompl"] == DBNull.Value ? DateTime.Now.ToString() : iReader["ConstrCompl"].ToString();
                //Adding New Fields
                txtfabEndDate   = iReader["fab_end"] == DBNull.Value ? "" : iReader["fab_end"].ToString();
                txtfabStartdate = iReader["fab_start"] == DBNull.Value ? "" : iReader["fab_start"].ToString();
                txtfabdurationt = iReader["fab_duration"] == DBNull.Value ? "" : iReader["fab_duration"].ToString();
                txtStreet       = iReader["prj_street"] == DBNull.Value ? "" : iReader["prj_street"].ToString();
                txtCity         = iReader["prj_city"] == DBNull.Value ? "" : iReader["prj_city"].ToString();
                txtState        = iReader["prj_state"] == DBNull.Value ? "" : iReader["prj_state"].ToString();
                txtzip          = iReader["prj_zip"] == DBNull.Value ? "" : iReader["prj_zip"].ToString();
                //New Fields Ends
                txtrealprjNumbert = iReader["Real_proj_Number"] == DBNull.Value ? "" : iReader["Real_proj_Number"].ToString();
                prjArch           = iReader["Architect"] == DBNull.Value ? "" : iReader["Architect"].ToString();
                prjEsti           = iReader["loginid"] == DBNull.Value ? "" : iReader["loginid"].ToString();
                txtTotCotCost     = iReader["Contengency"] == DBNull.Value ? "0" : iReader["Contengency"].ToString();
                txtEngRate        = iReader["enghourrate"] == DBNull.Value ? "45.00" : iReader["enghourrate"].ToString();
                txtFabRate        = iReader["fabhourrate"] == DBNull.Value ? "32.00" : iReader["fabhourrate"].ToString();
                txtInstRate       = iReader["insthourrate"] == DBNull.Value ? "45.00" : iReader["insthourrate"].ToString();
                txtMiscRate       = iReader["mischourrate"] == DBNull.Value ? "25.00" : iReader["mischourrate"].ToString();
                txtOverHeadRate   = iReader["overheadrate"] == DBNull.Value ? "24.11" : iReader["overheadrate"].ToString();
                txtMarkUpPercent  = iReader["profit_markup"] == DBNull.Value ? "15.00" : iReader["profit_markup"].ToString();
                txtDrawingDate    = iReader["drawingdate"] == DBNull.Value ? "" : iReader["drawingdate"].ToString();
                txtTypeOfWork     = iReader["typeofwork"] == DBNull.Value ? "" : iReader["typeofwork"].ToString();
            }

            Chunk chunkHeading;
            if (txtprjname.Length >= 30)
            {
                chunkHeading = new Chunk(txtprjname + "                                                                                                      ", fonts[15]);
            }
            else
            {
                chunkHeading = new Chunk(txtprjname + "                                                                                                                                      ", fonts[15]);
            }

            String _modetype = IsFinancial == "Y" ? "Proposal" : "Scope";

            Int32 _document_rev_number = GenerateseqNumberforDocs(Convert.ToInt32(EstNum), _modetype);

            _filename = DateTime.Now.ToString("MM-dd-yyyy") + "-" + txtprjname.Replace(".", " ").Trim() + " Architectural Millwork - WhitfieldCo " + _modetype + "-REV 0" + _document_rev_number + ".pdf";


            //if (File.Exists(HttpContext.Current.Server.MapPath("~/attachments/") + _filename))  //If the file exists, create new one.
            //{
            //    //File.Delete(HttpContext.Current.Server.MapPath("~/attachments/") + _filename);
            //    char[] splitchar = { '.' };
            //    string[] strArr = null;
            //    strArr = _filename.Split(splitchar);
            //    String _filenmTest = strArr[0];
            //    int intIndexSubstring = 0;
            //    intIndexSubstring = _filenmTest.IndexOf("-REV#");
            //    _filename = DateTime.Now.ToString("MM-dd-yyyy") + "-" + txtprjname.Replace(".", " ").Trim() + " Architectural Millwork - WhitfieldCo " + _modetype  +"-REV#0" + (Convert.ToInt32(_filenmTest.Substring(intIndexSubstring).Substring(5)) + 1).ToString() + ".pdf";

            //}
            //FileStream MyStream;
            //MyStream = new FileStream(HttpContext.Current.Server.MapPath("~/attachments/") + _filename, FileMode.Create);
            //PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Server.MapPath("~/attachments/") + _filename, FileMode.Create));
            //using (StreamWriter sw = File.CreateText(mappath + "patientquery.txt"))


            using (MyStream = new FileStream(HttpContext.Current.Server.MapPath("~/attachments/") + _filename, FileMode.Create))
            //using (FileStream MyStream = File.Create(HttpContext.Current.Server.MapPath("~/attachments/") + _filename))
            //new FileStream(HttpContext.Current.Server.MapPath("~/attachments/") + _filename, FileMode.Create)
            {
                PdfWriter.GetInstance(document, MyStream);
                //attachments
                document.AddAuthor("Whitfield Corporation");
                document.AddSubject("Proposal Generator");

                iTextSharp.text.Image img = this.DoGetImageFile(HttpContext.Current.Server.MapPath("~/assets/img/TWC Primary Logo1.JPG"));
                img.ScalePercent(50);
                Chunk ck = new Chunk(img, 0, -5);

                HeaderFooter headerRight = new HeaderFooter(new Phrase(chunkHeading), new Phrase(ck));
                document.Header       = headerRight;
                headerRight.Alignment = iTextSharp.text.Rectangle.ALIGN_RIGHT;
                headerRight.Border    = iTextSharp.text.Rectangle.NO_BORDER;


                // we Add a Footer that will show up on PAGE 1
                Phrase phFooter = new Phrase("The Whitfield Corporation, Incorporated  ", fonts[15]);
                phFooter.Add(new Phrase("P.O. Box 0385, Fulton, MD 20759  ", fonts[8]));
                phFooter.Add(new Phrase("Main: 301 483 0791 Fax: 301 483 0792  ", fonts[8]));
                phFooter.Add(new Phrase("\nDelivering on Promises", fonts[11]));
                //
                HeaderFooter footer = new HeaderFooter(phFooter, false);
                footer.Border    = iTextSharp.text.Rectangle.NO_BORDER;
                footer.Alignment = iTextSharp.text.Rectangle.ALIGN_CENTER;
                document.Footer  = footer;
                // step 3: we open the document
                document.Open();

                // we Add a Header that will show up on PAGE 2

                DateTime dt = DateTime.Now;
                //Chapters and Sections
                int ChapterSequence = 1;
                document.NewPage();
                iTextSharp.text.Font chapterFont    = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 16, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);
                iTextSharp.text.Font sectionFont    = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK);
                iTextSharp.text.Font subsectionFont = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 14, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK);

                //Chapter 1 Overview
                Paragraph cTitle  = new Paragraph(_modetype, chapterFont);
                Chapter   chapter = new Chapter(cTitle, ChapterSequence);

                Paragraph ChapterDate = new Paragraph(dt.ToString("\nMMMM dd, yyyy \n\n"), fonts[8]);
                Paragraph ChapterRef  = new Paragraph("RE:   " + txtprjname + "\n\n", fonts[8]);

                Paragraph ChapterText1;

                if (txtTypeOfWork.Trim() == "Time & Material")
                {
                    ChapterText1 = new Paragraph("Whitfield proposes to complete the scope of work on a Time & Material basis per the rates included in the Item Breakdown section of this proposal.\n\n", fonts[8]);
                }
                else
                {
                    ChapterText1 = new Paragraph("Whitfield proposes to furnish all materials and perform all labor necessary, including " + txtTypeOfWork + ", to complete the following scope of work as per the Scope of Work breakdown.\n\n", fonts[8]);
                }

                String _fnlAmt          = "";
                String amtWithnoDecimal = "";

                if (txtbasebid != "")
                {
                    string[] txtBaseBidStr          = txtbasebid.Split('.');
                    custom.util.NumberToEnglish num = new custom.util.NumberToEnglish();
                    _fnlAmt          = num.changeCurrencyToWords(txtBaseBidStr[0].Replace("$", "").Trim());
                    amtWithnoDecimal = txtBaseBidStr[0] + ".00";
                }

                contingency _cont = new contingency();
                if (IsFinancial == "Y")
                {
                    Paragraph ChapterText2;
                    if (txtTypeOfWork.Trim() == "Time & Material")
                    {
                        ChapterText2 = new Paragraph("The Material cost in the amount of " + _fnlAmt + " Dollars and No Cents (" + Convert.ToDecimal(amtWithnoDecimal).ToString("C") + ") includes all profit markup and assumes a construction start on approximately " + Convert.ToDateTime(txtConstStdate).ToString("MMMM dd, yyyy") + " with a completion on or around " + Convert.ToDateTime(txtConstEndDate).ToString("MMMM dd, yyyy") + " .\n\n", fonts[8]);
                        //ChapterText2.Add(new Phrase(new Chunk("This cost is in addition to any Time & Material cost and will be calculated on a unit price basis as included in the Item Breakdown section of this proposal for any time extension beyond the agreed upon construction schedule as included in this proposal.\n\n", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK))));
                    }
                    else
                    {
                        ChapterText2 = new Paragraph("This proposal assumes all of the above work completed by " + Convert.ToDateTime(txtConstEndDate).ToString("MMMM dd, yyyy") + " for the sum of ", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK));
                        ChapterText2.Add(new Phrase(new Chunk(" " + _fnlAmt + "Dollars and No Cents (" + Convert.ToDecimal(amtWithnoDecimal).ToString("C") + ").\n\n", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK))));
                    }


                    chapter.Add(ChapterDate);
                    chapter.Add(ChapterRef);
                    chapter.Add(ChapterText1);
                    chapter.Add(ChapterText2);

                    // Chapter Item Breakdown
                    DataSet dsCont = _cont.FetchProjectItemBreakdown(Convert.ToInt32(EstNum));
                    if (dsCont.Tables[0].Rows.Count > 0)
                    {
                        Paragraph cBreakDown = new Paragraph("Item Breakdown", chapterFont);
                        chapter.Add(cBreakDown);
                        DataTable myValues;
                        myValues = dsCont.Tables[0];
                        int icntBreakDown = 1;
                        foreach (DataRow dRow in myValues.Rows)
                        {
                            String    _cntlDesc        = dRow["Description"] == DBNull.Value ? "" : dRow["Description"].ToString();
                            String    _cntlAmt         = dRow["Amount"] == DBNull.Value ? "" : dRow["Amount"].ToString();
                            Paragraph itemAlternatives = new Paragraph(icntBreakDown.ToString() + ". " + _cntlDesc + "...." + _cntlAmt, fonts[8]);
                            icntBreakDown++;
                            chapter.Add(itemAlternatives);
                        }
                    }

                    // Chapter Alternatives
                    DataSet dsAlternatives = _cont.FetchAlternatives(Convert.ToInt32(EstNum));
                    if (dsAlternatives.Tables[0].Rows.Count > 0)
                    {
                        Paragraph c = new Paragraph("\nAlternates", fonts[14]);
                        chapter.Add(c);
                        DataTable myValues;
                        myValues = dsAlternatives.Tables[0];
                        int icntAlternatives = 1;
                        foreach (DataRow dRow in myValues.Rows)
                        {
                            String    _altType         = dRow["Type"] == DBNull.Value ? "" : dRow["Type"].ToString();
                            String    _cntlDesc        = dRow["Description"] == DBNull.Value ? "" : dRow["Description"].ToString();
                            String    _cntlAmt         = dRow["Amount"] == DBNull.Value ? "" : dRow["Amount"].ToString();
                            Paragraph itemAlternatives = new Paragraph(icntAlternatives.ToString() + ". " + _altType + ":" + _cntlDesc + "...." + _cntlAmt, fonts[8]);
                            icntAlternatives++;
                            chapter.Add(itemAlternatives);
                        }
                    }
                    //document.Add(chapter);
                    //Chapters and Sections Declarations End.
                }

                //**********************Chapter for Itemized Scope of Work Begins
                //ChapterSequence++;
                Paragraph cAssumptions = new Paragraph("\nItemized Scope of Work", chapterFont);
                chapter.Add(cAssumptions);
                //Chapter chapterAssumptions = new Chapter(cAssumptions, ChapterSequence);

                //Paragraph AssumptionsHeading = new Paragraph("Scope of Work\n\n", sectionFont);
                Paragraph AssumptionsText1 = new Paragraph("Provided hereto is an itemized clarification of the proposed scope. It has been developed and derived from the pricing documents to clarify various assumptions that were considered while compiling this estimate. The General Conditions (listed last) occur throughout the scope of work and apply to “typical applications”, which are subsequently itemized in the corresponding breakdown. " + ".\n\n", fonts[8]);
                //AssumptionsText1.Add(new Phrase(new Chunk("Proposed price includes " + txtTypeOfWork + ".\n\n", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK))));
                //chapterAssumptions.Add(AssumptionsHeading);
                chapter.Add(AssumptionsText1);

                DataSet dsScope = _wc.GetWorkOrders(EstNum);
                if (dsScope.Tables[0].Rows.Count > 0)
                {
                    LoadScopeOfWork(chapter, dsScope, fonts[14]);
                }

                Paragraph DrawingsPara1 = new Paragraph("Drawings:", fonts[14]);
                chapter.Add(DrawingsPara1);

                Paragraph itemDrawing = new Paragraph(txtprjname + " drawings prepared by " + _wc.GetArchitectName(Convert.ToInt32(prjArch)) + " dated " + txtDrawingDate + ".", fonts[8]);
                chapter.Add(itemDrawing);

                DataSet dsSpecs = _cont.FetchAmendmenList(Convert.ToInt32(EstNum));
                if (dsSpecs.Tables[0].Rows.Count > 0)
                {
                    Paragraph DrawingsPara = new Paragraph("\nAdditional Documents:", fonts[14]);
                    chapter.Add(DrawingsPara);
                    DataTable MyTerms;
                    MyTerms = dsSpecs.Tables[0];
                    int icntamendments = 1;
                    foreach (DataRow dRow in MyTerms.Rows)
                    {
                        String _AmedmentsType   = dRow["type"] == DBNull.Value ? "" : dRow["type"].ToString();
                        String _AmedmentNumber  = dRow["amendment_number"] == DBNull.Value ? "" : dRow["amendment_number"].ToString();
                        String _AmedmentDate    = dRow["amendment_date"] == DBNull.Value ? "" : dRow["amendment_date"].ToString();
                        String amendment_impact = dRow["amendment_impact"] == DBNull.Value ? "" : dRow["amendment_impact"].ToString();
                        //if (_AmedmentsType == "Amendment")
                        //{
                        if (amendment_impact.ToLower() == "yes")
                        {
                            Paragraph itemAmendment = new Paragraph(icntamendments.ToString() + ". " + _AmedmentsType + " " + _AmedmentNumber + " dated " + _AmedmentDate + " impacts this scope of work.", fonts[8]);
                            chapter.Add(itemAmendment);
                            //Amendment 001 dated 11/19/2010; This Amendment has no impact to this scope of work.
                        }
                        else
                        {
                            Paragraph itemAmendment = new Paragraph(icntamendments.ToString() + ". " + _AmedmentsType + " " + _AmedmentNumber + " dated " + _AmedmentDate + " does not impact this scope of work.", fonts[8]);
                            chapter.Add(itemAmendment);
                        }

                        //}
                        //else
                        //{
                        //    Paragraph itemAmendment = new Paragraph(icntamendments.ToString() + ". " + _AmedmentsType + " " + _AmedmentNumber + " " + _AmedmentDate, fonts[8]);
                        //    chapter.Add(itemAmendment);
                        //}

                        icntamendments++;
                    }
                }
                //Qualifications
                DataSet dsConditions = _wc.GetSpecExcl(Convert.ToInt32(EstNum));
                if (dsConditions.Tables[0].Rows.Count > 0)
                {
                    Paragraph DrawingsPara = new Paragraph("\nQualifications:", fonts[14]);
                    chapter.Add(DrawingsPara);
                    int       icnt = 1;
                    DataTable MyConditions;
                    MyConditions = dsConditions.Tables[0];
                    int tQualid = 0;
                    foreach (DataRow dRow in MyConditions.Rows)
                    {
                        if (Convert.ToInt32(dRow["qual_id"].ToString()) != tQualid)
                        {
                            Paragraph itemheading = new Paragraph(dRow["gName1"].ToString(), fonts[9]);
                            chapter.Add(itemheading);
                        }
                        String    _cntlDesc = dRow["description"] == DBNull.Value ? "" : dRow["description"].ToString();
                        Paragraph itemTerms = new Paragraph(icnt.ToString() + ".  " + _cntlDesc, fonts[8]);
                        chapter.Add(itemTerms);
                        tQualid = Convert.ToInt32(dRow["qual_id"].ToString());
                        icnt++;
                    }
                }

                // document.Add(chapter);
                //************************Chapter for Itemized Scope of Work Ends

                //*******Chapter Terms Begins********************
                //ChapterSequence++;
                Paragraph cTerms = new Paragraph("\nTerms", fonts[14]);
                //Chapter chapterTerms = new Chapter(cTerms, ChapterSequence);
                chapter.Add(cTerms);
                //Chapter chapterTerms = new Chapter(cTerms, ChapterSequence);
                DataSet dsTerms = _wc.GetTerms(Convert.ToInt32(EstNum));

                if (dsTerms.Tables[0].Rows.Count > 0)
                {
                    DataTable MyTerms;
                    MyTerms = dsTerms.Tables[0];
                    int icntTerms = 1;
                    foreach (DataRow dRow in MyTerms.Rows)
                    {
                        String    _cntlDesc = dRow["description"] == DBNull.Value ? "" : dRow["description"].ToString();
                        Paragraph itemTerms = new Paragraph(icntTerms.ToString() + ". " + _cntlDesc, fonts[8]);
                        chapter.Add(itemTerms);
                        icntTerms++;
                    }
                }


                Paragraph ChapterFooterText1 = new Paragraph("\nAll or part of the contract amount may be subject to change pending completion delay beyond agreed completion date and/or if changes to quantities are made. All agreements must be in writing prior to execution of any work.\n\n", fonts[8]);
                ChapterFooterText1.Add(Chunk.NEWLINE);
                ChapterFooterText1.Add(new Chunk("Respectfully submitted, ", fonts[8]));
                ChapterFooterText1.Add(new Chunk("                                                                  "));
                ChapterFooterText1.Add(new Chunk("Accepted By:, ", fonts[8]));
                ChapterFooterText1.Add(Chunk.NEWLINE);
                ChapterFooterText1.Add(new Chunk("The Whitfield Co., Inc., ", fonts[8]));
                ChapterFooterText1.Add(new Chunk("                                                                      "));
                ChapterFooterText1.Add(new Chunk("________________________ Date_________", fonts[8]));
                ChapterFooterText1.Add(Chunk.NEWLINE);
                ChapterFooterText1.Add(new Chunk("Jammie Whitfield, ", fonts[8]));
                ChapterFooterText1.Add(new Chunk("                                                                              "));
                ChapterFooterText1.Add(new Chunk("Name, Title", fonts[8]));
                //Paragraph ChapterFooterText2 = new Paragraph("Respectfully submitted,", fonts[8]);
                //Paragraph ChapterFooterText3 = new Paragraph("The Whitfield Co., Inc.\n\n", fonts[8]);
                //Paragraph ChapterFooterText4 = new Paragraph("Jammie Whitfield,", fonts[8]);
                //Paragraph ChapterFooterText5 = new Paragraph("Estimator", fonts[8]);

                chapter.Add(ChapterFooterText1);
                // Paragraph ChapterFooterText2 = new Paragraph("Respectfully submitted,", fonts[8]);
                // Paragraph ChapterFooterText3 = new Paragraph("The Whitfield Co., Inc.\n\n", fonts[8]);
                //Paragraph ChapterFooterText4 = new Paragraph("Jammie Whitfield,\n\n", fonts[8]);
                //Paragraph ChapterFooterText5 = new Paragraph("Accepted By:\n\n", fonts[8]);
                // Paragraph ChapterFooterText6 = new Paragraph("________________________ Date__________", fonts[8]);
                // Paragraph ChapterFooterText7 = new Paragraph("Name, Title", fonts[8]);

                chapter.Add(ChapterFooterText1);
                // chapter.Add(ChapterFooterText2);
                // chapter.Add(ChapterFooterText3);
                // chapter.Add(ChapterFooterText4);
                // chapter.Add(ChapterFooterText5);
                document.Add(chapter);

                //document.Add(new Chunk("Respectfully submitted, ", fonts[8]));
                //document.Add(new Chunk("                                                               "));
                //document.Add(new Chunk("Accepted By:, ", fonts[8]));
                //document.Add(Chunk.NEWLINE);
                //document.Add(new Chunk("The Whitfield Co., Inc., ", fonts[8]));
                //document.Add(new Chunk("                                                            "));
                //document.Add(new Chunk("________________________ Date_________", fonts[8]));
                //document.Add(Chunk.NEWLINE);
                //document.Add(new Chunk("Jammie Whitfield, ", fonts[8]));
                //document.Add(new Chunk("                                                                     "));
                //document.Add(new Chunk("Name, Title", fonts[8]));
                //*******Chapter Terms Ends********************
                document.Close();
                //MyStream.Flush();
                //MyStream.Close();
                //MyStream.Dispose();
                //}
                SetupEmailDocs(Convert.ToInt32(EstNum), _document_rev_number, _filename, _modetype);
                sendEmail(EstNum, _filename, IsFinancial);
            }
        }
        catch (DocumentException ex)
        {
            HttpResponse objResponse = HttpContext.Current.Response;
            objResponse.Write(ex.Message);
        }
        finally
        {
            if (MyStream != null)
            {
                MyStream.Close();
                MyStream.Dispose();
            }
        }

        //Response.Buffer = true;
        //Response.Clear();
        //Write pdf byes to outputstream
        //Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
        //Response.OutputStream.Flush();
        //Response.End();
    }
Esempio n. 19
0
 private static void WriteEnd(ISPage iSPage, Chapter chapter)
 {
     chapter.Add(new iTextSharp.text.Phrase(iSPage.EndText, FontFactory.GetFont(FontFactory.HELVETICA_BOLD)));
 }
Esempio n. 20
0
        /// <summary>
        /// Generates the eval report.
        /// </summary>
        /// <returns>The eval report.</returns>
        /// <param name="model">Model.</param>
        /// <param name="path">Path.</param>
        public static string GenerateEvalReport(EvalReportModel model, string path)
        {
            Document content = new Document();

            try
            {
                //准备字体
                BaseFont bfsun     = BaseFont.CreateFont(@"c:\Windows\fonts\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                BaseFont titleFont = BaseFont.CreateFont(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\方正宋黑简体.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                var      font      = new Font(bfsun);

                // make content pdf (calculate page number)
                PdfWriter contentWriter = PdfWriter.GetInstance(content, new System.IO.FileStream(path, System.IO.FileMode.Create));
                //ContentEvent eventd = new ContentEvent();
                //contentWriter.PageEvent = eventd;
                content.Open();
                #region 页眉页脚
                //PdfContentByte cb = contentWriter.DirectContent;
                //PdfTemplate template = cb.CreateTemplate(500, 200);
                ////template.MoveTo(0,(content.PageSize.Width-200/2));
                //template.LineTo(500, 0);
                //template.Stroke();
                //template.BeginText();
                //template.SetFontAndSize(bfsun, 10);
                //template.SetTextMatrix(0, 0);
                //template.ShowText(model.CompanyName);
                //template.EndText();
                //cb.AddTemplate(template, 0, (content.PageSize.Width - 200) / 2);
                #endregion

                #region 生成首页
                //添加标题
                //var titleChapter = new Chapter(new Paragraph(new Chunk("封面", new Font(font) { Size = 24 })) { Alignment = Element.ALIGN_CENTER }, 1);
                //titleChapter.NumberDepth = -1;
                //content.Add(titleChapter);

                content.Add(new Paragraph(model.Title, new Font(font)
                {
                    Size = 24
                })
                {
                    Alignment = Element.ALIGN_CENTER
                });
                content.Add(new Paragraph(" "));
                //添加副标题
                content.Add(new Paragraph(model.SecTitle, new Font(font)
                {
                    Size = 16
                })
                {
                    Alignment = Element.ALIGN_CENTER
                });
                //titleChapter.NumberDepth = -1;


                content.Add(new Paragraph(" ")
                {
                    SpacingBefore = 40f
                });


                #region 用表格模拟“综合等级”的星
                var levelTable = new PdfPTable(new float[] { 90f, 470f });
                var levelCell  = new PdfPCell()
                {
                    Border              = 0,
                    VerticalAlignment   = Element.ALIGN_MIDDLE,
                    HorizontalAlignment = Element.ALIGN_CENTER
                };
                //levelCell.Border = 0;
                levelCell.AddElement(new Paragraph("综合等级:", font)
                {
                    Alignment = Element.ALIGN_CENTER
                });
                levelCell.VerticalAlignment = Element.ALIGN_MIDDLE;

                levelTable.AddCell(levelCell);
                //第二个单元格
                var starCell = new PdfPCell();
                var sttable  = new PdfPTable(15);
                for (int i = 1; i < 6; i++)
                {
                    string imgPath;
                    if (i <= model.Level)
                    {
                        imgPath = System.Web.HttpContext.Current.Server.MapPath("~/images/ui_star_red.png");
                    }
                    else
                    {
                        imgPath = System.Web.HttpContext.Current.Server.MapPath("~/images/ui_star_red_null.png");
                    }
                    sttable.AddCell(new PdfPCell(Image.GetInstance(imgPath))
                    {
                        Border              = 0,
                        VerticalAlignment   = Element.ALIGN_MIDDLE,
                        HorizontalAlignment = Element.ALIGN_CENTER
                    });
                }
                for (int i = 0; i < 10; i++)
                {
                    sttable.AddCell(new PdfPCell(new Phrase(""))
                    {
                        Border = 0
                    });
                }

                levelTable.AddCell(new PdfPCell(sttable)
                {
                    Border = 0
                });

                content.Add(levelTable);
                #endregion

                try
                {
                    var fimg = Image.GetInstance(model.FrontImage);
                    fimg.ScaleAbsolute(content.PageSize.Width, 200);

                    fimg.Alignment = Element.ALIGN_CENTER;
                    content.Add(fimg);
                }
                catch
                {
                }


                content.Add(new Paragraph(" ")
                {
                    SpacingBefore = 20f
                });
                PdfPTable homeTable = new PdfPTable(3);
                //homeTable.TotalWidth = 340;

                foreach (var item in model.FrontCoverDataItems)
                {
                    var spaceCell = new PdfPCell();
                    spaceCell.AddElement(new Paragraph("  "));
                    spaceCell.Border = 0;
                    var cell1 = new PdfPCell();
                    cell1.AddElement(new Paragraph(item.Key + ":", font));
                    cell1.Border = 0;
                    var cell2 = new PdfPCell();
                    cell2.AddElement(new Paragraph(item.Value, font));
                    cell2.Border = 0;
                    homeTable.Rows.Add(new PdfPRow(new[] { spaceCell, cell1, cell2 }));
                }
                //homeTable.HorizontalAlignment=
                content.Add(homeTable);

                #endregion

                //List<Chapter> chapterList = new List<Chapter>();

                #region 生成内容

                for (int i = 0; i < model.Items.Count; i++)
                {
                    var     item    = model.Items[i];
                    Chapter chapter = new Chapter(new Paragraph(item.Title, new Font(titleFont)
                    {
                        Size = 16
                    })
                    {
                        Alignment = Element.ALIGN_CENTER
                    }, i + 2);
                    chapter.NumberDepth = -1;
                    //chapter.NumberDepth = 1;

                    //chapterList.Add(chapter);
                    foreach (var c in item.Contents)
                    {
                        chapter.Add(new Paragraph(c, font));
                    }

                    for (int j = 0; j < item.Sections.Count; j++)
                    {
                        var section = item.Sections[j];
                        var sec     = chapter.AddSection(new Paragraph(section.SectionTitle, new Font(titleFont)
                        {
                            Size = 14
                        }), j + 1);
                        sec.NumberDepth = -1;
                        foreach (var c in section.Contents)
                        {
                            sec.Add(new Paragraph(c, font) /* FirstLineIndent = 26 */ }
                            {
                            );
                        }
Esempio n. 21
0
        public Chap0701()
        {
            Console.WriteLine("Chapter 7 example 1: my first XML");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a XML-stream to a file
                XmlWriter.GetInstance(document, new FileStream("Chap0701.xml", FileMode.Create), "itext.dtd");

                // step 3: we open the document
                document.Open();

                // step 4: we add content to the document
                Paragraph paragraph = new Paragraph("Please visit my ");
                Anchor    anchor1   = new Anchor("website (external reference)", FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.UNDERLINE, new Color(0, 0, 255)));
                anchor1.Reference = "http://www.lowagie.com/iText/";
                anchor1.Name      = "top";
                paragraph.Add(anchor1);
                document.Add(paragraph);

                Paragraph entities = new Paragraph("These are some special characters: <, >, &, \" and '");
                document.Add(entities);

                document.Add(new Paragraph("some books I really like:"));
                List     list;
                ListItem listItem;
                list     = new List(true, 15);
                listItem = new ListItem("When Harlie was one", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12));
                listItem.Add(new Chunk(" by David Gerrold", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC)).SetTextRise(8.0f));
                list.Add(listItem);
                listItem = new ListItem("The World according to Garp", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12));
                listItem.Add(new Chunk(" by John Irving", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC)).SetTextRise(-8.0f));
                list.Add(listItem);
                listItem = new ListItem("Decamerone", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12));
                listItem.Add(new Chunk(" by Giovanni Boccaccio", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC)));
                list.Add(listItem);
                document.Add(list);

                paragraph = new Paragraph("some movies I really like:");
                list      = new List(false, 10);
                list.Add("Wild At Heart");
                list.Add("Casablanca");
                list.Add("When Harry met Sally");
                list.Add("True Romance");
                list.Add("Le mari de la coiffeuse");
                paragraph.Add(list);
                document.Add(paragraph);

                document.Add(new Paragraph("Some authors I really like:"));
                list            = new List(false, 20);
                list.ListSymbol = new Chunk("*", FontFactory.GetFont(FontFactory.HELVETICA, 20, Font.BOLD));
                listItem        = new ListItem("Isaac Asimov");
                list.Add(listItem);
                List sublist;
                sublist            = new List(true, 10);
                sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                sublist.Add("The Foundation Trilogy");
                sublist.Add("The Complete Robot");
                sublist.Add("Caves of Steel");
                sublist.Add("The Naked Sun");
                list.Add(sublist);
                listItem = new ListItem("John Irving");
                list.Add(listItem);
                sublist            = new List(true, 10);
                sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                sublist.Add("The World according to Garp");
                sublist.Add("Hotel New Hampshire");
                sublist.Add("A prayer for Owen Meany");
                sublist.Add("Widow for a year");
                list.Add(sublist);
                listItem = new ListItem("Kurt Vonnegut");
                list.Add(listItem);
                sublist            = new List(true, 10);
                sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                sublist.Add("Slaughterhouse 5");
                sublist.Add("Welcome to the Monkey House");
                sublist.Add("The great pianola");
                sublist.Add("Galapagos");
                list.Add(sublist);
                document.Add(list);

                paragraph = new Paragraph("\n\n");
                document.Add(paragraph);

                Table table = new Table(3);
                table.BorderWidth = 1;
                table.BorderColor = new Color(0, 0, 255);
                table.Padding     = 5;
                table.Spacing     = 5;
                Cell cell = new Cell("header");
                cell.Header  = true;
                cell.Colspan = 3;
                table.AddCell(cell);
                table.EndHeaders();
                cell             = new Cell("example cell with colspan 1 and rowspan 2");
                cell.Rowspan     = 2;
                cell.BorderColor = new Color(255, 0, 0);
                table.AddCell(cell);
                table.AddCell("1.1");
                table.AddCell("2.1");
                table.AddCell("1.2");
                table.AddCell("2.2");
                table.AddCell("cell test1");
                cell         = new Cell("big cell");
                cell.Rowspan = 2;
                cell.Colspan = 2;
                table.AddCell(cell);
                table.AddCell("cell test2");
                document.Add(table);

                Image jpeg = Image.GetInstance("myKids.jpg");
                document.Add(jpeg);
                Image png = Image.GetInstance(new Uri("http://www.lowagie.com/iText/examples/hitchcock.png"));
                document.Add(png);
                Anchor anchor2 = new Anchor("please jump to a local destination", FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255)));
                anchor2.Reference = "#top";
                document.Add(anchor2);

                document.Add(paragraph);

                // we define some fonts
                Font chapterFont    = FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new Color(255, 0, 0));
                Font sectionFont    = FontFactory.GetFont(FontFactory.HELVETICA, 20, Font.NORMAL, new Color(0, 0, 255));
                Font subsectionFont = FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));
                // we create some paragraphs
                Paragraph blahblah     = new Paragraph("blah blah blah blah blah blah blaah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah");
                Paragraph blahblahblah = new Paragraph("blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blaah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah");

                // this loop will create 7 chapters
                for (int i = 1; i < 8; i++)
                {
                    Paragraph cTitle  = new Paragraph("This is chapter " + i, chapterFont);
                    Chapter   chapter = new Chapter(cTitle, i);

                    if (i == 4)
                    {
                        blahblahblah.Alignment = Element.ALIGN_JUSTIFIED;
                        blahblah.Alignment     = Element.ALIGN_JUSTIFIED;
                        chapter.Add(blahblah);
                    }
                    if (i == 5)
                    {
                        blahblahblah.Alignment = Element.ALIGN_CENTER;
                        blahblah.Alignment     = Element.ALIGN_RIGHT;
                        chapter.Add(blahblah);
                    }
                    // add a table in the 6th chapter
                    if (i == 6)
                    {
                        blahblah.Alignment = Element.ALIGN_JUSTIFIED;
                        chapter.Add(table);
                    }
                    // in every chapter 3 sections will be added
                    for (int j = 1; j < 4; j++)
                    {
                        Paragraph sTitle  = new Paragraph("This is section " + j + " in chapter " + i, sectionFont);
                        Section   section = chapter.AddSection(sTitle, 1);
                        // in all chapters except the 1st one, some extra text is added to section 3
                        if (j == 3 && i > 1)
                        {
                            section.Add(blahblah);
                        }
                        // in every section 3 subsections are added
                        for (int k = 1; k < 4; k++)
                        {
                            Paragraph subTitle   = new Paragraph("This is subsection " + k + " of section " + j, subsectionFont);
                            Section   subsection = section.AddSection(subTitle, 3);
                            if (k == 1 && j == 3)
                            {
                                subsection.Add(blahblahblah);
                                subsection.Add(table);
                            }
                            subsection.Add(blahblah);
                        }
                        if (j == 2 && i > 2)
                        {
                            section.Add(blahblahblah);
                            section.Add(table);
                        }
                    }
                    document.Add(chapter);
                }
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();
        }
Esempio n. 22
0
 public void AddImage(iTextSharp.text.Image image)
 {
     image.Alignment     = Element.ALIGN_LEFT;
     image.SpacingBefore = 50;
     chapter.Add(image);
 }
Esempio n. 23
0
        public bool CreatePdf()
        {
            bool result = true;

            try
            {
                if (patient == null || doctor == null)
                {
                    result = false;
                }
                else
                {
                    PdfDocument.Open();

                    Chapter chapter1 = AddChapter(
                        new Paragraph(GetTitleText(patient.FullName))
                    {
                        Alignment = HAlingmentCenter, SpacingAfter = 10f
                    },
                        0, 0);
                    iTextSharp.text.Section personalInfoSection = AddSection(chapter1, 0f, new Paragraph(GetSectionText("Osobné údaje")), 0);

                    PdfPTable table = new PdfPTable(new[] { 60f, 40f })
                    {
                        HorizontalAlignment = HAlingmentLeft, SpacingBefore = 10f, SpacingAfter = 10f, WidthPercentage = 100f
                    };

                    PdfPTable personalInfoTable = CreatePersonalInfoTable();
                    Image     pic = null;
                    if (patient.AvatarImagePath != null && System.IO.File.Exists(patient.AvatarImagePath))
                    {
                        pic = Image.GetInstance(patient.AvatarImagePath);
                        pic.ScaleToFit((RX - LX) / 2f, GetTableHeight(personalInfoTable));
                    }
                    else
                    {
                        pic = Image.GetInstance((System.Drawing.Image)Properties.Resources.noUserImage, System.Drawing.Imaging.ImageFormat.Png);
                    }

                    PdfPCell imageCell = new PdfPCell(pic, false)
                    {
                        PaddingTop = 5f, BorderColor = BaseColor.WHITE
                    };
                    PdfPCell tableCell = new PdfPCell(personalInfoTable)
                    {
                        PaddingTop = 5f, BorderColor = BaseColor.WHITE
                    };

                    table.AddCell(tableCell);
                    table.AddCell(imageCell);
                    personalInfoSection.Add(table);

                    iTextSharp.text.Section addressAndContactSection = AddSection(chapter1, 0f, new Paragraph(GetSectionText("Adresa a kontaktné údaje")), 0);
                    table = new PdfPTable(new[] { 100f })
                    {
                        HorizontalAlignment = HAlingmentLeft, SpacingBefore = 10f, WidthPercentage = 100f
                    };
                    PdfPCell addressCell = new PdfPCell(CreateAddressTable())
                    {
                        PaddingTop = 5f, BorderColor = BaseColor.WHITE
                    };
                    PdfPCell contactCell = new PdfPCell(CreateContactTable())
                    {
                        PaddingTop = 5f, BorderColor = BaseColor.WHITE
                    };
                    table.AddCell(addressCell);
                    table.AddCell(contactCell);
                    addressAndContactSection.Add(table);

                    Chapter chapter2 = AddChapter(
                        new Paragraph(GetTitleText("Zdravotná karta pacienta"))
                    {
                        SpacingAfter = 10f
                    },
                        0, 0);

                    foreach (var ezkoSection in ezkoController.GetSections().OrderBy(x => x.Name))
                    {
                        iTextSharp.text.Section pdfSection = AddSection(chapter2, 0f, new Paragraph(GetSectionText(ezkoSection.Name)), 0);
                        PdfPTable sectionTable             = CreateEzkoSectionTable(pdfSection, ezkoSection);
                        pdfSection.Add(sectionTable);
                    }

                    PdfDocument.Add(chapter1);
                    PdfDocument.Add(chapter2);

                    Chapter chapter3 = AddChapter(
                        new Paragraph(GetTitleText("Návštevy pacienta"))
                    {
                        SpacingAfter = 10f
                    },
                        0, 0);
                    if (patient.CalendarEvents.Count > 0)
                    {
                        PdfPTable eventsTable = CreateEventsTable();
                        chapter3.Add(eventsTable);
                    }
                    else
                    {
                        chapter3.Add(new Paragraph(GetNoteText("Pacient zatial nemá žiadne návštevy")));
                    }
                    //chapter3.Add(new Paragraph(GetText("Pacient zatial nemá žiadne návštevy")));

                    PdfDocument.Add(chapter3);
                    PdfDocument.Close();
                }
            }
            catch (Exception ex)
            {
                BasicMessagesHandler.LogException(ex);
                result = false;
            }

            return(result);
        }
Esempio n. 24
0
        public Chap0402()
        {
            Console.WriteLine("Chapter 4 example 2: Chapters and Sections");

            // step 1: creation of a document-object
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);

            try
            {
                // step 2: we create a writer that listens to the document
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0402.pdf", FileMode.Create));
                // step 3: we open the document
                document.Open();
                // step 4: we Add content to the document
                // we define some fonts
                Font chapterFont    = FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new Color(255, 0, 0));
                Font sectionFont    = FontFactory.GetFont(FontFactory.HELVETICA, 20, Font.NORMAL, new Color(0, 0, 255));
                Font subsectionFont = FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLD, new Color(0, 64, 64));
                // we create some paragraphs
                Paragraph blahblah     = new Paragraph("blah blah blah blah blah blah blaah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah");
                Paragraph blahblahblah = new Paragraph("blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blaah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah");
                // this loop will create 7 chapters
                for (int i = 1; i < 8; i++)
                {
                    Paragraph cTitle  = new Paragraph("This is chapter " + i, chapterFont);
                    Chapter   chapter = new Chapter(cTitle, i);

                    if (i == 4)
                    {
                        blahblahblah.Alignment = Element.ALIGN_JUSTIFIED;
                        blahblah.Alignment     = Element.ALIGN_JUSTIFIED;
                        chapter.Add(blahblah);
                    }
                    if (i == 5)
                    {
                        blahblahblah.Alignment = Element.ALIGN_CENTER;
                        blahblah.Alignment     = Element.ALIGN_RIGHT;
                        chapter.Add(blahblah);
                    }
                    // Add a table in the 6th chapter
                    if (i == 6)
                    {
                        blahblah.Alignment = Element.ALIGN_JUSTIFIED;
                    }
                    // in every chapter 3 sections will be Added
                    for (int j = 1; j < 4; j++)
                    {
                        Paragraph sTitle  = new Paragraph("This is section " + j + " in chapter " + i, sectionFont);
                        Section   section = chapter.AddSection(sTitle, 1);
                        // in all chapters except the 1st one, some extra text is Added to section 3
                        if (j == 3 && i > 1)
                        {
                            section.Add(blahblah);
                        }
                        // in every section 3 subsections are Added
                        for (int k = 1; k < 4; k++)
                        {
                            Paragraph subTitle   = new Paragraph("This is subsection " + k + " of section " + j, subsectionFont);
                            Section   subsection = section.AddSection(subTitle, 3);
                            if (k == 1 && j == 3)
                            {
                                subsection.Add(blahblahblah);
                            }
                            subsection.Add(blahblah);
                        }
                        if (j == 2 && i > 2)
                        {
                            section.Add(blahblahblah);
                        }
                    }
                    document.Add(chapter);
                }
            }
            catch (Exception de)
            {
                Console.Error.WriteLine(de.StackTrace);
            }
            // step 5: we close the document
            document.Close();
        }
        private async Task <byte[]> CreateAlsrPdf(int id)
        {
            var reportModel = await db.BillsAlsrReports
                              .Where(r => r.ID == id)
                              .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.Bill))
                              .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.BillVersion))
                              .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.CreatedByUser))
                              .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.CreatedByUserInDept))
                              .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.CreatedByUserInDiv))
                              .Include(r => r.AlsrBillReviewSnapshots.Select(s => s.Recommendation))
                              .FirstOrDefaultAsync();

            // initialize iText document
            using (MemoryStream ms = new MemoryStream())
            {
                string agencyTitle = reportModel.AlsrBillReviewSnapshots.FirstOrDefault().CreatedByUserInDept.Description;

                //initialize PDF Document
                var       doc    = new Document(PageSize.LETTER, 36, 36, 36, 36);
                PdfWriter writer = PdfWriter.GetInstance(doc, ms);
                // add page # footer
                PageEventHelper pageEventHelper = new PageEventHelper();
                writer.PageEvent = pageEventHelper;

                doc.AddAuthor(agencyTitle);
                doc.AddCreationDate();
                doc.Open();

                // formatting variables
                float tableFullPageWidth     = 540f;
                float tableCellBottomPadding = 6f;
                float paragraphSpacingBefore = 18f;

                // header (used on each page)
                Chunk     alsrAgencyHeader = new Chunk(agencyTitle);
                Chunk     alsrHeaderLine2  = new Chunk("\nAgency Legislative Status Report");
                Chunk     alsrHeaderLine3  = new Chunk("\n78th Legislative Session (2015)");
                Paragraph header           = new Paragraph();
                header.Alignment = Element.ALIGN_CENTER;
                header.Add(alsrAgencyHeader);
                header.Add(alsrHeaderLine2);
                header.Add(alsrHeaderLine3);

                // cover sheet
                Chapter coverSheet = new Chapter(header, 1);
                coverSheet.NumberDepth   = 0;
                coverSheet.BookmarkTitle = "Cover Sheet";

                doc.Add(coverSheet);

                // individual BillReviews
                for (int i = 0; i < reportModel.AlsrBillReviewSnapshots.Count; i++)
                {
                    Chapter reviewPage = new Chapter(header, 1);
                    reviewPage.NumberDepth   = 0;
                    reviewPage.BookmarkTitle = reportModel.AlsrBillReviewSnapshots[i].Bill.CompositeBillNumber;

                    // Agency contact section
                    PdfPTable contactTable = new PdfPTable(2);
                    contactTable.DefaultCell.Border        = Rectangle.NO_BORDER;
                    contactTable.DefaultCell.PaddingBottom = tableCellBottomPadding;
                    contactTable.TotalWidth    = tableFullPageWidth;
                    contactTable.LockedWidth   = true;
                    contactTable.SpacingBefore = paragraphSpacingBefore;
                    contactTable.AddCell(string.Format("Agency: {0}", agencyTitle));
                    contactTable.AddCell(string.Format("Delivery Date: {0}", reportModel.GovOfficeDeliveryDate.ToShortDateString()));
                    PdfPCell contactNameCell = new PdfPCell(new Phrase(string.Format("Contact Name: Ann Wilkinson (Deputy Administrator)")));
                    contactNameCell.Colspan       = 2;
                    contactNameCell.Border        = Rectangle.NO_BORDER;
                    contactNameCell.PaddingBottom = tableCellBottomPadding;
                    contactTable.AddCell(contactNameCell);
                    contactTable.AddCell(string.Format("Phone: 775-684-0222"));
                    contactTable.AddCell(string.Format("Fax: 775-684-0260"));
                    reviewPage.Add(contactTable);

                    // Bill info section
                    PdfPTable billInfoTable = new PdfPTable(3);
                    billInfoTable.DefaultCell.Border        = Rectangle.NO_BORDER;
                    billInfoTable.DefaultCell.PaddingBottom = tableCellBottomPadding;
                    billInfoTable.TotalWidth    = tableFullPageWidth;
                    billInfoTable.LockedWidth   = true;
                    billInfoTable.SpacingBefore = paragraphSpacingBefore;
                    float[] billInfoTableWidths = new float[] { 1, 1, 2 };
                    billInfoTable.SetWidths(billInfoTableWidths);
                    billInfoTable.AddCell(string.Format("Bill No: {0}", reportModel.AlsrBillReviewSnapshots[i].Bill.CompositeBillNumber));
                    billInfoTable.AddCell(string.Format("BDR No: {0}", reportModel.AlsrBillReviewSnapshots[i].Bill.CompositeNelisBdrNumber));
                    billInfoTable.AddCell(string.Format("Sponsor: {0}", reportModel.AlsrBillReviewSnapshots[i].BillVersion.Sponsor));
                    PdfPCell reprintNoCell = new PdfPCell(new Phrase(string.Format("Reprint No: {0}", reportModel.AlsrBillReviewSnapshots[i].BillVersion.VersionDescription)));
                    reprintNoCell.Colspan       = 4;
                    reprintNoCell.Border        = Rectangle.NO_BORDER;
                    reprintNoCell.PaddingBottom = tableCellBottomPadding;
                    billInfoTable.AddCell(reprintNoCell);
                    reviewPage.Add(billInfoTable);

                    // BillReview section
                    Paragraph billReviewHeaderParagraph = new Paragraph(string.Format("This Bill Review is being provided on behalf of Agency: {1}", agencyTitle, reportModel.AlsrBillReviewSnapshots[i].CreatedByUserInDiv.Description));
                    billReviewHeaderParagraph.SpacingBefore = paragraphSpacingBefore;
                    reviewPage.Add(billReviewHeaderParagraph);

                    PdfPTable billReviewTable = new PdfPTable(2);
                    billReviewTable.DefaultCell.Border        = Rectangle.NO_BORDER;
                    billReviewTable.DefaultCell.PaddingBottom = tableCellBottomPadding;
                    billReviewTable.DefaultCell.PaddingRight  = tableCellBottomPadding;
                    billReviewTable.TotalWidth    = tableFullPageWidth;
                    billReviewTable.LockedWidth   = true;
                    billReviewTable.SpacingBefore = paragraphSpacingBefore;
                    float[] billReviewTableWidths = new float[] { 1, 2 };
                    billReviewTable.SetWidths(billReviewTableWidths);
                    billReviewTable.AddCell("Position:");
                    billReviewTable.AddCell(reportModel.AlsrBillReviewSnapshots[i].Recommendation.Description);
                    billReviewTable.AddCell("Agency is tracking this Bill:");
                    billReviewTable.AddCell((reportModel.AlsrBillReviewSnapshots[i].ActivelyTracking ? "Yes" : "No"));
                    billReviewTable.AddCell("Information/testimony or data to be provided by agency:");
                    billReviewTable.AddCell((reportModel.AlsrBillReviewSnapshots[i].InformationToBeProvided ? "Yes" : "No"));
                    billReviewTable.AddCell("Policy impact on agency:");
                    string policyImpact = "";
                    switch (reportModel.AlsrBillReviewSnapshots[i].PolicyImpact)
                    {
                    case null:
                        policyImpact = "Unknown";
                        break;

                    case false:
                        policyImpact = "No";
                        break;

                    case true:
                        policyImpact = "Yes";
                        break;

                    default:
                        break;
                    }
                    billReviewTable.AddCell(policyImpact);
                    billReviewTable.AddCell("Fiscal impact on agency:");
                    billReviewTable.AddCell((reportModel.AlsrBillReviewSnapshots[i].FiscalNoteSubmitted ? "Yes" : "No"));
                    billReviewTable.AddCell("Estimated fiscal impact for biennium:");
                    billReviewTable.AddCell(string.Format("${0}", reportModel.AlsrBillReviewSnapshots[i].FiscalImpactBiennium));
                    reviewPage.Add(billReviewTable);

                    Paragraph billReviewCommentsHeaderParagraph = new Paragraph("Comments: Would passage of this bill constitute good public policy?\n");
                    billReviewCommentsHeaderParagraph.SpacingBefore = paragraphSpacingBefore;
                    reviewPage.Add(billReviewCommentsHeaderParagraph);

                    Paragraph billReviewCommentsParagraph = new Paragraph(reportModel.AlsrBillReviewSnapshots[i].Comments);
                    //billReviewCommentsParagraph.SpacingBefore = paragraphSpacingBefore;
                    reviewPage.Add(billReviewCommentsParagraph);

                    doc.Add(reviewPage);
                }


                doc.Close();
                writer.Close();
                return(ms.ToArray());
            }
        }
Esempio n. 26
0
        private void Form1_Load(object sender, EventArgs e)
        {
            iText.Rectangle pageSize = new iText.Rectangle(216f, 1000f);
            pageSize.BackgroundColor = BaseColor.BLUE;
            Document document = new Document();
            //			Document document = new Document(pageSize, 72, 72, 144, 144);
            //			Document doc = new Document(PageSize.LETTER);
            //			Document doc = new Document(PageSize.LETTER.Rotate());

            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"HelloWorld.pdf", FileMode.Create));

            writer.PageEvent = new FoxDogGeneric1();

            document.AddTitle("Hello world example");
            document.AddSubject("This example shows how to add metadata");
            document.AddKeywords("Metadata, iText, step 3, tutorial");
            document.AddCreator("My program using iText");
            document.AddAuthor("Bruno Lowagie");
            document.AddHeader("Expires", "0");
            document.Open();

            /* chapter04/FoxDogChunk1.java */
            document.Add(new Paragraph("This is an example of chunks"));
            iText.Font font = new iText.Font(iText.Font.FontFamily.COURIER, 10, iText.Font.BOLD);
            font.SetColor(0xFF, 0xFF, 0xFF);
            Chunk fox = new Chunk("quick brown fox", font);

            fox.SetBackground(new BaseColor(0xa5, 0x2a, 0x2a));
            Chunk jumps = new Chunk(" jumps over ", new iText.Font());
            Chunk dog   = new Chunk("the lazy dog", new iText.Font(iText.Font.FontFamily.TIMES_ROMAN, 14, iText.Font.ITALIC));

            document.Add(fox);
            document.Add(jumps);
            document.Add(dog);

            document.Add(new Paragraph("This is an example of a Phrase"));

            /* chapter04/FoxDogPhrase.java */
            Phrase phrase = new Phrase(30);
            Chunk  space  = new Chunk(' ');

            phrase.Add(fox);
            phrase.Add(jumps);
            phrase.Add(dog);
            phrase.Add(space);

            for (int i = 0; i < 10; i++)
            {
                document.Add(phrase);
            }

            document.Add(new Paragraph("This is an example of a Paragraph"));

            /* chapter04/FoxDogParagraph.java */
            String    text      = "Quick brown fox jumps over the lazy dog.";
            Phrase    phrase1   = new Phrase(text);
            Phrase    phrase2   = new Phrase(new Chunk(text, new iText.Font(iText.Font.FontFamily.TIMES_ROMAN)));
            Phrase    phrase3   = new Phrase(text, new iText.Font(iText.Font.FontFamily.COURIER));
            Paragraph paragraph = new Paragraph();

            paragraph.Add(phrase1);
            paragraph.Add(space);
            paragraph.Add(phrase2);
            paragraph.Add(space);
            paragraph.Add(phrase3);
            paragraph.Alignment       = Element.ALIGN_RIGHT;
            paragraph.IndentationLeft = 20;
            document.Add(paragraph);
            document.Add(paragraph);

            document.Add(new Paragraph("This is an example of a link. Click the text below."));

            /* chapter04/FoxDogAnchor1.java */
            Anchor anchor = new Anchor("Quick brown fox jumps over the lazy dog.");

            anchor.Reference = "http://en.wikipedia.org/wiki/The_quick_brown_fox_jumps_over_the_lazy_dog";
            document.Add(anchor);

            document.Add(new Paragraph("This is an example of some lists"));

            /* chapter04/FoxDogList1.java */
            List list1 = new List(List.ORDERED, 20);

            list1.Add(new ListItem("the lazy dog"));
            document.Add(list1);
            List list2 = new List(List.UNORDERED, 10);

            list2.Add("the lazy cat");
            document.Add(list2);
            List list3 = new List(List.ORDERED, List.ALPHABETICAL, 20);

            list3.Add(new ListItem("the fence"));
            document.Add(list3);
            List list4 = new List(List.UNORDERED, 30);

            list4.SetListSymbol("----->");
            list4.IndentationLeft = 10;
            list4.Add("the lazy dog");
            document.Add(list4);
            List list5 = new List(List.ORDERED, 20);

            list5.First = 11;
            list5.Add(new ListItem("the lazy cat"));
            document.Add(list5);
            List list = new List(List.UNORDERED, 10);

            list.SetListSymbol("*");
            list.Add(list1);
            list.Add(list3);
            list.Add(list5);
            document.Add(list);

            /* chapter04/FoxDogChapter1.java */
            Chapter chapter1 = new Chapter(new Paragraph("This is a sample sentence:", font), 1);

            chapter1.Add(new Paragraph(text));
            Section section1 = chapter1.AddSection("Quick", 0);

            section1.Add(new Paragraph(text));
            document.Add(chapter1);

            /* chapter04/FoxDogScale.java */
            Chunk     c = new Chunk("quick brown fox jumps over the lazy dog");
            float     w = c.GetWidthPoint();
            Paragraph p = new Paragraph("The width of the chunk: '");

            p.Add(c);
            p.Add("' is ");
            p.Add(w.ToString());
            p.Add(" points or ");
            p.Add((w / 72f).ToString());
            p.Add(" inches or ");
            p.Add((w / 72f * 2.54f).ToString());
            p.Add(" cm.");
            document.Add(p);

            document.Add(new Paragraph("SetGenericTag Example"));

            /* chapter04/FoxDogGeneric1.java */
            p   = new Paragraph();
            fox = new Chunk("Quick brown fox");
            fox.SetGenericTag("box");
            p.Add(fox);
            p.Add(" jumps over ");
            dog = new Chunk("the lazy dog.");
            dog.SetGenericTag("ellipse");
            p.Add(dog);
            document.Add(p);

            document.Close();

            string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

            webBrowser1.Navigate(string.Concat(appPath, "\\", @"HelloWorld.pdf"));
        }
Esempio n. 27
0
    private void LoadScopeOfWork(Chapter chapterScope, DataSet ds, iTextSharp.text.Font font1)
    {
        int NumColumns = 4;

        try
        {
            // we add some meta information to the document
            //Paragraph DrawingsPara = new Paragraph("Scope of Work:\n\n", font1);
            //chapterScope.Add(DrawingsPara);

            PdfPTable datatable = new PdfPTable(NumColumns);
            //iTextSharp.text.Table datatable = new iTextSharp.text.Table(NumColumns);
            datatable.DefaultCell.Padding = 4;
            float[] headerwidths = { 8, 20, 45, 20 }; // percentage
            datatable.SetWidths(headerwidths);
            datatable.WidthPercentage = 100;          // percentage

            datatable.DefaultCell.BorderWidth         = 1;
            datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
            //datatable.AddCell("No.");
            datatable.AddCell(new Phrase("No.", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.Font.NORMAL)));
            //datatable.AddCell("Description");
            datatable.AddCell(new Phrase("Description", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.Font.NORMAL)));
            //datatable.AddCell("Notes");
            datatable.AddCell(new Phrase("Notes", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.Font.NORMAL)));
            //datatable.AddCell("Reference");
            datatable.AddCell(new Phrase("Reference", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.Font.NORMAL)));
            datatable.HeaderRows = 1;  // this is the end of the table header
            datatable.DefaultCell.BorderWidth = 1;

            int       i = 1;
            DataTable MyScope;
            MyScope = ds.Tables[0];

            foreach (DataRow dRow in MyScope.Rows)
            {
                String _number      = dRow["work_order_id"] == DBNull.Value ? "" : dRow["work_order_id"].ToString();
                String _description = dRow["Description"] == DBNull.Value ? "" : dRow["Description"].ToString();
                String _notes       = dRow["notes1"] == DBNull.Value ? "" : dRow["notes1"].ToString();
                String _reference   = dRow["reftext"] == DBNull.Value ? "" : dRow["reftext"].ToString();
                datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                if (i % 2 == 1)
                {
                    datatable.DefaultCell.GrayFill = 0.9f;
                }
                datatable.AddCell(new Phrase(_number, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL)));
                datatable.AddCell(new Phrase(_description, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL)));
                datatable.AddCell(new Phrase(_notes, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL)));
                datatable.AddCell(new Phrase(_reference, FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, iTextSharp.text.Font.NORMAL)));

                if (i % 2 == 1)
                {
                    datatable.DefaultCell.GrayFill = 1.0f;
                }
                i++;
            }
            chapterScope.Add(datatable);
        }
        catch (Exception ex)
        {
            HttpResponse objResponse = HttpContext.Current.Response;
            objResponse.Write(ex.Message);
        }
    }
Esempio n. 28
0
        public Chap0803()
        {
            Console.WriteLine("Chapter 8 example 3: RTF with the RtfHeaderFooters class");

            /* Create a new document */
            Document document = new Document(PageSize.A4);

            try
            {
                /* Create a RtfWriter and a PdfWriter for the document */
                RtfWriter rtf = RtfWriter.GetInstance(document, new FileStream("Chap0803.rtf", FileMode.Create));

                /* We specify that the RTF file has a Title Page */
                rtf.SetHasTitlePage(true);

                /* We create headers and footers for the RTF file */
                RtfHeaderFooters header = new RtfHeaderFooters();
                RtfHeaderFooters footer = new RtfHeaderFooters();

                /* We add a header that will only appear on the first page */
                header.Set(RtfHeaderFooters.FIRST_PAGE, new HeaderFooter(new Phrase("This header is only on the first page"), false));
                /* We add a header that will only appear on left-side pages */
                header.Set(RtfHeaderFooters.LEFT_PAGES, new HeaderFooter(new Phrase("This header is only on left pages"), false));
                /* We add a header that will only appear on right-side pages */
                header.Set(RtfHeaderFooters.RIGHT_PAGES, new HeaderFooter(new Phrase("This header is only on right pages. "), false));

                /* We add a footer that will appear on all pages except the first (because of the title page)
                 * Because the header has different left and right page footers, we have to add the footer to
                 * both the left and right pages. */
                footer.Set(RtfHeaderFooters.LEFT_PAGES, new HeaderFooter(new Phrase("This footer is on all pages except the first. Page: "), true));
                footer.Set(RtfHeaderFooters.RIGHT_PAGES, new HeaderFooter(new Phrase("This footer is on all pages except the first. Page: "), true));

                /* Open the document */
                document.Open();


                /* We add the header and footer */
                document.Header = header;
                document.Footer = footer;


                /* We add some content */
                Chapter chapter = new Chapter(new Paragraph("Advanced RTF headers and footers", new Font(Font.HELVETICA, 16, Font.BOLD)), 1);

                chapter.Add(new Paragraph("This document demonstrates the use of advanced RTF headers and footers."));

                for (int i = 0; i < 300; i++)
                {
                    chapter.Add(new Paragraph("Line " + i));
                }
                document.Add(chapter);
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            /* Close the document */
            document.Close();
        }