/// <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(); } }
/// <summary> /// Adds the file to PDF document. /// </summary> /// <param name="docPDF">The doc PDF.</param> /// <param name="file">The file.</param> internal void AddFiletoPDFDoc(Document docPDF, SPFile file) { pdfHelper = new PDFHelper(); if (file != null) { FileExtn = file.Name.Substring(file.Name.LastIndexOf(".") + 1).ToLowerInvariant(); if (FileExtn.Equals("pdf")) { Document newDoc = new Document(file.OpenBinaryStream()); docPDF.AppendDocument(newDoc); } else if (FileExtn.Equals("bmp") || FileExtn.Equals("gif") || FileExtn.Equals("jpg") || FileExtn.Equals("tif") || FileExtn.Equals("png") || FileExtn.Equals("jpeg") || FileExtn.Equals("tiff") || FileExtn.Equals("png")) { PdfPage pagePDF = docPDF.AddPage(); Stream ImageStream = file.OpenBinaryStream(); System.Drawing.Image Image = System.Drawing.Image.FromStream(ImageStream); /// Display image in the available space in page and with a auto determined height to keep the aspect ratio ImageElement imageElement = new ImageElement(0, 0, Image); pagePDF.AddElement(imageElement); } else { pdfHelper.AddWarningTitleToNewPDfPage(docPDF, "File Type is not Supported"); } } else { pdfHelper.AddWarningTitleToNewPDfPage(docPDF, "File Does not Exist"); } }
/// <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; } }
/// <summary> /// Generates the PDF page. /// </summary> /// <param name="docPDF">The doc PDF.</param> /// <param name="xPathNavigator">The x path navigator.</param> internal void GeneratePDFPage(Document docPDF, XPathNavigator xpatpageNode,String strContext, bool isPageTitleApplicable) { objpdfHelper = new PDFHelper(); try { strarrPageDetails = new string[5]; strbHtml = new StringBuilder(); strPageTitleHtml = new StringBuilder(); strType1Html = string.Empty; objSPfile = null; objStream = new MemoryStream(); XmlNamespaceManager objXMLnameSpaces = new XmlNamespaceManager(xpatpageNode.NameTable); objXMLnameSpaces.AddNamespace("PDF", "http://www.shell.com/"); StrConnectType = xpatpageNode.GetAttribute("ConnectionType", objXMLnameSpaces.DefaultNamespace); ///Add First Page pdfBLL = new PdfBLL(); strarrPageDetails[0] = xpatpageNode.GetAttribute("ActualColumnname", objXMLnameSpaces.DefaultNamespace); strarrPageDetails[1] = Constant.EQUALS; strarrPageDetails[2] = xpatpageNode.GetAttribute("AssetValue", objXMLnameSpaces.DefaultNamespace); strarrPageDetails[3] = xpatpageNode.GetAttribute("ReportName", objXMLnameSpaces.DefaultNamespace); strarrPageDetails[4] = xpatpageNode.GetAttribute("AssetType", objXMLnameSpaces.DefaultNamespace); IntPageId = Convert.ToInt32(xpatpageNode.GetAttribute("PageID", objXMLnameSpaces.DefaultNamespace)); if (isPageTitleApplicable) { StrNarrative = pdfBLL.GetNarrative(IntPageId, strContext, Constant.LISTNARRATIVE); if (string.IsNullOrEmpty(StrNarrative)) StrNarrative = "N/A"; StrSignOffStatus = xpatpageNode.GetAttribute("SignOffStatus", objXMLnameSpaces.DefaultNamespace); switch (StrSignOffStatus) { case "Yes": StrSignOffStatus = "Signed Off"; break; case "No": StrSignOffStatus = "Not Signed Off"; break; } StrPageOwner = xpatpageNode.GetAttribute("PageOwner", objXMLnameSpaces.DefaultNamespace); StrPageTitle = xpatpageNode.GetAttribute("Title", objXMLnameSpaces.DefaultNamespace); xpatpageNode.MoveToParent(); StrAssetValue = xpatpageNode.GetAttribute("AssetValue", objXMLnameSpaces.DefaultNamespace); StrPageTitle = StrPageTitle.Replace("$", StrAssetValue); #region PageTitleHtml strPageTitleHtml.Append(@"<table width=""90%"" align=""center"" style="" font-family:Verdana;font-size:42px;font-weight:bold;"" > <tr > <td align=""center"" width=""40%"" style=""padding-right: 8px; height: 600px;""> <b>"); strPageTitleHtml.Append(StrPageTitle); strPageTitleHtml.Append(@" </b></td> </tr> </table> <table width=""70%"" align=""center"" style="" font-family:Verdana;font-size:20px; background-color:Black;border:solid 1px Black;"" cellpadding=""2"" cellspacing=""2"" > <tr style=""background-color:White;""> <td align=""right"" width=""40%"" style=""padding-right: 8px; height: 21px;""> <b>Page Owner</b></td> <td align=""left"" width=""60%"" style=""height: 21px""> "); strPageTitleHtml.Append(StrPageOwner); strPageTitleHtml.Append(@" </td> </tr> <tr style=""background-color:White;""> <td align=""right"" style=""padding-right: 8px;""> <b>Sign Off Status</b></td> <td align=""left"" > "); strPageTitleHtml.Append(StrSignOffStatus); strPageTitleHtml.Append(@"</td> </tr> <tr style=""height:100px;background-color:White;""> <td align=""right"" style=""padding-right: 8px;"" valign=""top""> <b>Narrative</b></td> <td align=""left"" valign=""top""> "); strPageTitleHtml.Append(StrNarrative); strPageTitleHtml.Append(@"</td> </tr> </table>"); #endregion objpdfHelper.AddHTMLtoPDF(docPDF, Convert.ToString(strPageTitleHtml), strContext, false); } switch (StrConnectType) { case "1": try { strType1Html = objpdfHelper.AddType1toPDFDoc(strarrPageDetails, strContext); strbHtml.Append(Constant.HEAD); strbHtml.Append(strType1Html); strbHtml.Append(Constant.END); HtmlToPdfElement htmlToPdfElement; htmlToPdfElement = new HtmlToPdfElement(0, 0, -1, -1, Convert.ToString(strbHtml), HttpContext.Current.Request.Url.ToString()); htmlToPdfElement.FitWidth = true; htmlToPdfElement.EmbedFonts = true; htmlToPdfElement.LiveUrlsEnabled = true; htmlToPdfElement.ScriptsEnabled = true; htmlToPdfElement.ActiveXEnabled = true; htmlToPdfElement.PdfBookmarkOptions.TagNames = null; //Add a first page to the document. The next pages will inherit the settings from this page PdfPage page = docPDF.Pages.AddNewPage(PageSize.A4, new Margins(10, 10, 0, 0), PageOrientation.Portrait); page.AddElement(htmlToPdfElement); } catch (SoapException soapEx) { objpdfHelper.AddWarningTitleToNewPDfPage(docPDF,soapEx.Message); } catch (WebException ex) { objpdfHelper.AddWarningTitleToNewPDfPage(docPDF, ex.Message); } break; case "2": objSPfile = pdfBLL.DownloadFileFromDocumentLibrary(strContext, Constant.LISTPUBLISHEDDOCUMENTS, Convert.ToString(IntPageId)); objpdfHelper.AddFiletoPDFDoc(docPDF, objSPfile); break; case "3": objSPfile = pdfBLL.DownloadFileFromDocumentLibrary(strContext, Constant.LISTUSERDEFINEDDOCUMENTS, Convert.ToString(IntPageId)); objpdfHelper.AddFiletoPDFDoc(docPDF, objSPfile); break; } } catch (Exception ex) { objpdfHelper.PrintLog(strContext, ex.Message, "BookPage.GeneratePDFPage", "Exception"); objpdfHelper.PrintLog(strContext, ex.StackTrace, "BookPage.GeneratePDFPage", "Exception"); throw; } finally { objStream.Dispose(); } }