Exemple #1
0
        /// <summary>
        /// Generates the TOC.
        /// </summary>
        /// <param name="docPDF">The doc PDF.</param>
        /// <param name="xmlPathDocumentCriteria">The XML path document criteria.</param>
        internal void GenerateTOC(Document docPDF, XPathDocument xmlPathDocumentCriteria, String context,Boolean isTOCApplicable, Boolean isStoryBoardApplicable, bool isPageTitleApplicable)
        {
            objpdfHelper = new PDFHelper();
            try
            {
                strBTOC = new StringBuilder();

                objpdfBLL = new PdfBLL();
                XPathNavigator objXPNavigator = xmlPathDocumentCriteria.CreateNavigator();
                // Set up namespace manager for XPath
                XmlNamespaceManager objXMLnameSpaces = new XmlNamespaceManager(objXPNavigator.NameTable);
                objXMLnameSpaces.AddNamespace("PDF", "http://www.shell.com/");

                if (isTOCApplicable)
                {
                    Int32 intPgCount = Convert.ToInt32(objpdfBLL.GetAttributeBookInfo(xmlPathDocumentCriteria, "PageCount"));
                    Int32 TOCPageCount = intPgCount / 63;
                    if (!(intPgCount % 63 == 0))
                        TOCPageCount++;
                    for (int pageCounter = 0; pageCounter < TOCPageCount; pageCounter++)
                    {
                        docPDF.Pages.AddNewPage(PageSize.A4, new Margins(40), PageOrientation.Portrait);

                    }
                    strBTOC.Append(strTOCBeginHTML);
                }
                XPathNodeIterator chapternodes = objXPNavigator.Select("/BookInfo/Chapter");
                while (chapternodes.MoveNext())//chapters
                {
                    if (isTOCApplicable)
                    {
                        strBTOC.AppendFormat(@"<tr><td colspan=""2"" >{0}</td><td ></td><td ></td></tr>",
                                chapternodes.Current.GetAttribute("ChapterTitle", objXMLnameSpaces.DefaultNamespace));
                    }
                    //Add page for Chapter Title if is Printable
                    if (Convert.ToBoolean(chapternodes.Current.GetAttribute("IsPrintable", objXMLnameSpaces.DefaultNamespace)))
                    {
                        objpdfHelper.AddChapterTitlePage(docPDF, chapternodes.Current.GetAttribute("ChapterTitle", objXMLnameSpaces.DefaultNamespace));
                    }
                    XPathNodeIterator pagenodes = chapternodes.Current.Select("PageInfo");
                    while (pagenodes.MoveNext())//pages in a chapter
                    {
                        if (isTOCApplicable)
                        {
                            //strBHyphen = new StringBuilder();
                            strPageTitle = pagenodes.Current.GetAttribute("PageTitle", objXMLnameSpaces.DefaultNamespace);
                            //for (int counter = 0; counter < (113 - strPageTitle.Length); counter++)
                            //{
                            //    strBHyphen.Append("-");
                            //}
                            strBTOC.AppendFormat(@"<tr>
                                        <td style=""width:5%""></td>
                                        <td style=""width:95%"" align=""right""><font style=""float:left"">{0}</font></td>
                                   </tr>",
                                                  strPageTitle);

                        }
                        objbkpage = new BookPage();
                        objbkpage.GeneratePDFPage(docPDF, pagenodes.Current, context, isPageTitleApplicable);
                        if (isStoryBoardApplicable)
                        {
                            objbkpage.GeneratePDFPageStoryBoard(docPDF, pagenodes.Current, context);
                        }
                    }
                    objpdfHelper.PrintLog(context, string.Format("Chapter {0} is created", chapternodes.Current.GetAttribute("ChapterTitle", objXMLnameSpaces.DefaultNamespace)), "WellBookTOC.GenerateTOC", "ChapterCreation");
                }
                if (isTOCApplicable)
                {
                    strBTOC.Append(strTOCEndHTML);
                    objpdfHelper.AddHTMLtoPDF(docPDF, Convert.ToString(strBTOC), context, true);
                }
            }
            catch (Exception ex)
            {
                objpdfHelper.PrintLog(context, ex.Message, "WellBookTOC.GenerateTOC", "Exception");
                objpdfHelper.PrintLog(context, ex.StackTrace, "WellBookTOC.GenerateTOC", "Exception");
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        /// Generates the book.
        /// </summary>
        /// <param name="xmldocCriteria">The xmldoc criteria.</param>
        public int GenerateBook(XPathDocument xpDocument, String strContext)
        {
            try
            {
                LicensingManager.LicenseKey = PortalConfiguration.GetInstance().FindWebServiceKey("WinnovativeLicenseKey", strContext,true);
                objPdfhelper = new PDFHelper();
                objPdfBLL = new PdfBLL();
                objBookTOC = new WellBookTOC();
                blnIsTOCApplicable = new Boolean();
                ///Once Book Title is obtained get the First Page of PDF ready with Book Title and
                ///Current Date and time Below it.
                PDFDocument = new Document();

                LibraryName = objPdfBLL.GetAttributeBookInfo(xpDocument, "Type");
                if (LibraryName.Equals("pdf"))
                    LibraryName = Constant.LISTPUBLISHED;
                else if (LibraryName.Equals("print"))
                    LibraryName = Constant.LISTPRINTED;
                blnIsTOCApplicable = Convert.ToBoolean(objPdfBLL.GetAttributeBookInfo(xpDocument, "IsTOCApplicable"));
                blnIsStoryBoardApplicable = Convert.ToBoolean(objPdfBLL.GetAttributeBookInfo(xpDocument, "IsStoryBoardApplicable"));
                blnIsPageTitleApplicable = Convert.ToBoolean(objPdfBLL.GetAttributeBookInfo(xpDocument, "IsPageTitleApplicable"));
                objPdfhelper.PrintLog(strContext, "PDF generation for {" + objPdfBLL.GetAttributeBookInfo(xpDocument, "BookName") + " }is Started.Calling GenerateTOC to generate PDF", "BookDetails.GenerateBook", "BeforeUploading");

                objBookTOC.GenerateTOC(PDFDocument, xpDocument, strContext, blnIsTOCApplicable, blnIsStoryBoardApplicable, blnIsPageTitleApplicable);
                if ((Convert.ToBoolean(objPdfBLL.GetAttributeBookInfo(xpDocument, "IsBookTitleApplicable"))))
                {
                    objPdfhelper.AddBookTitle(PDFDocument, xpDocument, blnIsTOCApplicable, LibraryName);
                }

                PDFDocument.CompressionLevel = CompressionLevel.BestCompression;
                objPdfhelper.PrintLog(strContext, "PDF for {" + objPdfBLL.GetAttributeBookInfo(xpDocument, "BookName") + " }is generated.Calling UploadPublishedDocument to upload to document library", "BookDetails.GenerateBook", "BeforeUploading");

                intResult = objPdfBLL.UploadPublishedDocument(strContext, objPdfBLL.GetAttributeBookInfo(xpDocument, "BookID"), PDFDocument, objPdfBLL.GetAttributeBookInfo(xpDocument, "BookName"), LibraryName);
                if (intResult > 0)
                {
                    objPdfhelper.PrintLog(strContext, "PDF for {" + objPdfBLL.GetAttributeBookInfo(xpDocument, "BookName") + "} is uploaded successfully.", "BookDetails.GenerateBook", "AfterUploading");

                }
                else
                {
                    objPdfhelper.PrintLog(strContext, "PDF for {" + objPdfBLL.GetAttributeBookInfo(xpDocument, "BookName") + "} is NOT uploaded successfully.", "BookDetails.GenerateBook", "AfterUploading");

                }
                return intResult;
            }
            catch (Exception ex)
            {
                objPdfhelper.PrintLog(strContext, ex.Message, "BookDetails.GenerateBook", "Exception");
                objPdfhelper.PrintLog(strContext, ex.StackTrace, "BookDetails.GenerateBook", "Exception");
                throw;
            }
            finally
            {
                PDFDocument.Close();
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds the book title.
        /// </summary>
        /// <param name="docPDF">The doc PDF.</param>
        /// <param name="strBooktitle">The STR booktitle.</param>
        internal void AddBookTitle(Document docPDF, XPathDocument xmlDocumentCriteria, Boolean IsTOCApplicable, string type)
        {
            strbookHeader = string.Empty;
            strbookHeader = "DIGITAL WELL BOOK _____________________________________________________";
            try
            {
                pdfBLL = new PdfBLL();
                strbookTitle = pdfBLL.GetAttributeBookInfo(xmlDocumentCriteria, "BookName");

                if (IsTOCApplicable)
                {
                    pdfPage = docPDF.Pages[0];
                }
                else
                {
                    docPDF.InsertPage(0, PageSize.A4, new Margins(), PageOrientation.Portrait);
                    pdfPage = docPDF.Pages[0];
                }

                #region Header for Book Title Page
                //Generate Text
                // Create a Bold .NET font of 10 points
                System.Drawing.Font fntVerdanaHeadaer = new System.Drawing.Font("Verdana", 15,
                            System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
                // Create the PDF fonts based on the .NET true type fonts
                PdfFont newfntVerdanaHeadaer = docPDF.AddFont(fntVerdanaHeadaer);

                // Add Title elements to the document
                TextElement PageTitleVerdanaHeadaer = new TextElement(3, 20, strbookHeader, newfntVerdanaHeadaer);
                PageTitleVerdanaHeadaer.TextAlign = HorizontalTextAlign.Left;
                pdfPage.AddElement(PageTitleVerdanaHeadaer);
                #endregion

                //Generate Text
                #region bOOK tITLE
                System.Drawing.Font ttfFontBold = new System.Drawing.Font("Verdana", 30,
                                System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
                // Create the PDF fonts based on the .NET true type fonts
                PdfFont newVerdanaFontBold = docPDF.AddFont(ttfFontBold);

                // Add Title elements to the document
                TextElement TypeTitle = new TextElement(3, 300, strbookTitle, newVerdanaFontBold);
                TypeTitle.TextAlign = HorizontalTextAlign.Center;
                AddElementResult addTitle = pdfPage.AddElement(TypeTitle);
                #endregion

                ///Generate Text for Book Owner
                #region bOOK oWNER

                System.Drawing.Font fntVerdanaBold = new System.Drawing.Font("Verdana", 20,
                            System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
                // Create the PDF fonts based on the .NET true type fonts
                PdfFont newfntVerdanaBold = docPDF.AddFont(fntVerdanaBold);
                //Add Book Owner to Page
                TextElement TypeVerdanaBold = new TextElement(3, addTitle.EndPageBounds.Bottom + 5,
                                    "Book Owner - " + pdfBLL.GetAttributeBookInfo(xmlDocumentCriteria, "BookOwner"),
                                                        newfntVerdanaBold);
                TypeVerdanaBold.TextAlign = HorizontalTextAlign.Center;
                AddElementResult addOwner = pdfPage.AddElement(TypeVerdanaBold);
                #endregion

                #region Published Date
                System.Drawing.Font ttfFont = new System.Drawing.Font("Verdana", 10,
                                System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
                // Create the PDF fonts based on the .NET true type fonts
                PdfFont newVerdanaFont = docPDF.AddFont(ttfFont);
                TextElement TypeVerdanaDate;
                if (type.Equals("pdf"))
                {
                    TypeVerdanaDate = new TextElement(3, addOwner.EndPageBounds.Bottom + 5, "Published date: " + DateTime.Now.ToString(DATEFORMAT), newVerdanaFont);
                }
                else
                {
                    TypeVerdanaDate = new TextElement(3, addOwner.EndPageBounds.Bottom + 5, "Date: " + DateTime.Now.ToString(DATEFORMAT), newVerdanaFont);
                }
                TypeVerdanaDate.TextAlign = HorizontalTextAlign.Center;
                pdfPage.AddElement(TypeVerdanaDate);
                #endregion
            }
            finally
            {
            }
        }