diff --git a/PROMS/Volian.Print.Library/PromsPrinter.cs b/PROMS/Volian.Print.Library/PromsPrinter.cs index a90d1515..368cc33c 100644 --- a/PROMS/Volian.Print.Library/PromsPrinter.cs +++ b/PROMS/Volian.Print.Library/PromsPrinter.cs @@ -84,10 +84,6 @@ namespace Volian.Print.Library } public class PromsPrinter { - // the following boolean is to help testing of various formats. If the plant has an alternating foldout - // and you want a blank page, until foldouts are developed, set to true. - // AEP DU1 - do a blank page for foldout - private bool _DoBlankForFoldout = false; public event PromsPrinterStatusEvent StatusChanged; private void OnStatusChanged(object sender, PromsPrintStatusArgs args) { @@ -255,8 +251,20 @@ namespace Volian.Print.Library } int _StepPageNumber = 0; private VlnSvgPageHelper _MyHelper = null; + private static PdfReader _MyFoldoutReader = null; + private static SectionInfo _MyFoldoutSection = null; private string Print(ProcedureInfo myProcedure, string pdfFolder) { + _MyFoldoutReader = null; + foreach (SectionInfo mySection in myProcedure.Sections) + { + if (mySection.MyContent.Number.ToUpper() == "FOLDOUT") + { + _MyFoldoutSection = mySection; + string foldoutPdf = PrintProcedureOrFoldout(myProcedure, true, Volian.Base.Library.VlnSettings.TemporaryFolder + @"\Foldout.pdf"); + _MyFoldoutReader = foldoutPdf != null ? new PdfReader(foldoutPdf) : null; + } + } OnStatusChanged("Print " + myProcedure.DisplayNumber, PromsPrinterStatusType.Start); string outputFileName = pdfFolder + "\\" + PDFFile; @@ -265,24 +273,31 @@ namespace Volian.Print.Library if (MessageBox.Show(outputFileName + " exists. Overwrite file?", "File Exists", MessageBoxButtons.YesNo) == DialogResult.No) return null; } + return PrintProcedureOrFoldout(myProcedure, false, outputFileName); + } + + private string PrintProcedureOrFoldout(ProcedureInfo myProcedure, bool doingFoldout, string outputFileName) + { // Create an MSWord Pdf // Setup a pdf Document for printing OnStatusChanged("Before OpenDoc", PromsPrinterStatusType.Before); PdfContentByte cb = OpenDoc(outputFileName); if (cb == null) return null; OnStatusChanged("Before NewPage", PromsPrinterStatusType.Before); - cb.PdfDocument.NewPage(); + cb.PdfDocument.NewPage(); // Start of print OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage); - OnStatusChanged(myProcedure.DisplayNumber, PromsPrinterStatusType.ProgressSetup,myProcedure.Sections.Count); + OnStatusChanged(myProcedure.DisplayNumber, PromsPrinterStatusType.ProgressSetup, myProcedure.Sections.Count); int progress = 0; foreach (SectionInfo mySection in myProcedure.Sections) { - OnStatusChanged((mySection.DisplayNumber??"") == "" ? mySection.DisplayText : mySection.DisplayNumber, PromsPrinterStatusType.Progress, progress++); + if ((mySection.MyContent.Number.ToUpper() == "FOLDOUT") != doingFoldout) continue; + OnStatusChanged((mySection.DisplayNumber ?? "") == "" ? mySection.DisplayText : mySection.DisplayNumber, PromsPrinterStatusType.Progress, progress++); // Set up Helper for the particular Section if (_MyHelper == null) { cb.PdfWriter.PageEvent = _MyHelper = new VlnSvgPageHelper(mySection); _MyHelper.MyPdfWriter = cb.PdfWriter; + _MyHelper.CreatingFoldoutPage = doingFoldout; _MyHelper.MyPdfContentByte = cb; if (DebugOutput) @@ -290,13 +305,13 @@ namespace Volian.Print.Library // 16-bit background string procedureFileName = BackgroundFolder + "\\" + CreateFileName(myProcedure.DisplayNumber); FileInfo VEPromsFile = new FileInfo(procedureFileName); - if (VEPromsFile.Exists) + if (VEPromsFile.Exists && !doingFoldout) { _MyHelper.BackgroundFile = procedureFileName; // X argument below: accounts for 16-bit pdf OverrideLeftMargin = -2 characters at the plant format's default Font's // characters per inch. // 16bit OverrideLeftMargin, defined as -2 in driver\drvin.rtf, - override took 2 characters out, so we're adding it back in: - _MyHelper.BackgroundOffset = new PointF(2*72F/(float)myProcedure.ActiveFormat.PlantFormat.FormatData.Font.CPI, -9.5F); + _MyHelper.BackgroundOffset = new PointF(2 * 72F / (float)myProcedure.ActiveFormat.PlantFormat.FormatData.Font.CPI, -9.5F); _MyHelper.BackgroundPageOffset = 0; } _MyHelper.WatermarkLayer = _WatermarkLayer; @@ -319,7 +334,11 @@ namespace Volian.Print.Library PdfReader readerWord = null; string myPdfFile = null; if (mySection.IsStepSection) + { + if ((mySection.MyDocStyle.StructureStyle.Style ?? 0 & E_DocStructStyle.UseSectionFoldout) != 0) + DoFoldoutPage(cb, "Beginning of Step Section", _TextLayer, _MyHelper); CreateStepPdf(mySection, cb); + } else { myPdfFile = BuildMSWordPDF(mySection); @@ -327,33 +346,54 @@ namespace Volian.Print.Library { readerWord = myPdfFile != null ? new PdfReader(myPdfFile) : null; OnStatusChanged("Get Section", PromsPrinterStatusType.GetSection); - int sectPageCount=0; - using(PdfInfo myPdf = PdfInfo.Get(mySection)) - sectPageCount = (int)(Math.Ceiling(myPdf.PageCount)); - for (int ii = 0; ii < sectPageCount; ii++) + int sectPageCount = 0; + float locEndOfWordDoc = 0; + float pdfSize = 0; + using (PdfInfo myPdf = PdfInfo.Get(mySection)) + { + sectPageCount = (int)(Math.Ceiling(myPdf.PageCount)); + locEndOfWordDoc = (float)(myPdf.PageCount - (sectPageCount-1)) * 100; + pdfSize = (float)myPdf.PageCount; + } + for (int ii = 0; ii < sectPageCount; ii++) + { + if (((mySection.MyDocStyle.StructureStyle.Style ?? 0) & E_DocStructStyle.UseSectionFoldout) != 0) + DoFoldoutPage(cb, "Word Document", _TextLayer, _MyHelper); + int pageNumber = 1 + ii; + if (readerWord != null) { - int pageNumber = 1 + ii; - if (readerWord != null) + bool doimport2 = true; + PdfImportedPage fgPage = null; + try { - bool doimport2 = true; - PdfImportedPage fgPage = null; - try - { - fgPage = cb.PdfWriter.GetImportedPage(readerWord, ii + 1); - } - catch (Exception ex) - { - Console.WriteLine(ex); - doimport2 = false; - } - OnStatusChanged("Read MSWord", PromsPrinterStatusType.ReadMSWord); - if (doimport2) AddImportedPageToLayer(cb.PdfWriter.DirectContent, _MSWordLayer, fgPage, 0, 0); - OnStatusChanged("Merge MSWord", PromsPrinterStatusType.MergeMSWord); + fgPage = cb.PdfWriter.GetImportedPage(readerWord, ii + 1); } - OnStatusChanged("Before NewPage", PromsPrinterStatusType.Before); - cb.PdfDocument.NewPage(); - OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage); + catch (Exception ex) + { + Console.WriteLine(ex); + doimport2 = false; + } + OnStatusChanged("Read MSWord", PromsPrinterStatusType.ReadMSWord); + if (doimport2) AddImportedPageToLayer(cb.PdfWriter.DirectContent, _MSWordLayer, fgPage, 0, 0); + if (ii == sectPageCount - 1) + { + // if there's and end message, add it to the appropriate location on the last page of + // the word document: + float ylocation = cb.PdfDocument.PageSize.Height - ((float)mySection.MyDocStyle.Layout.TopMargin + locEndOfWordDoc * 72); // 72 - pts per inch. + iTextSharp.text.Font fnt = VolianPdf.GetFont(mySection.MyDocStyle.End.Font.WindowsFont); + fnt.Color=new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Black)); + iTextSharp.text.Paragraph para = new Paragraph(mySection.MyDocStyle.End.Message, fnt); + float wtpm = (float)mySection.MyDocStyle.Layout.PageWidth - (float)mySection.MyDocStyle.Layout.LeftMargin; + float centerpos = (float)mySection.MyDocStyle.Layout.LeftMargin + (wtpm - (mySection.MyDocStyle.End.Message.Length * mySection.MyDocStyle.End.Font.CharsToTwips)) / 2; + Rtf2Pdf.TextAt(cb, para, centerpos, ylocation + 6, 100, 12, "", 50); + } + OnStatusChanged("Merge MSWord", PromsPrinterStatusType.MergeMSWord); } + OnStatusChanged("Before NewPage", PromsPrinterStatusType.Before); + cb.PdfDocument.NewPage(); // Word Document + + OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage); + } } catch (Exception ex) @@ -367,19 +407,19 @@ namespace Volian.Print.Library _MyHelper.MySvg = null; while (cb.PdfWriter.CurrentPageNumber <= _MyHelper.BackgroundPageCount) { - PrintTextMessage(cb, "No Proms Output"); - cb.PdfDocument.NewPage(); + PrintTextMessage(cb, "No Proms Output", _TextLayer); + cb.PdfDocument.NewPage(); // only have 16bit pages left (for DebugMode) } } OnStatusChanged(myProcedure.DisplayNumber + " PDF Creation Completed", PromsPrinterStatusType.Progress, progress); CloseDocument(cb, outputFileName); - // Return the fileName; + _MyHelper = null; return outputFileName; } - private void PrintTextMessage(PdfContentByte cb, string message) + private static void PrintTextMessage(PdfContentByte cb, string message, PdfLayer textLayer) { - if (_TextLayer != null) cb.BeginLayer(_TextLayer); + if (textLayer != null) cb.BeginLayer(textLayer); float fontSize = 30; ColumnText ct = new ColumnText(cb); iTextSharp.text.Font font = FontFactory.GetFont("Arial", fontSize, new iTextSharp.text.Color(PrintOverride.TextColor)); @@ -393,32 +433,90 @@ namespace Volian.Print.Library ct.AddElement(ph); cb.SetColorFill(new iTextSharp.text.Color(PrintOverride.TextColor)); ct.Go(); - if (_TextLayer != null) cb.EndLayer(); + if (textLayer != null) cb.EndLayer(); } + private float _NoBreakYOffset = 0; private void CreateStepPdf(SectionInfo section, PdfContentByte cb) { iTextSharp.text.pdf.PdfWriter writer = cb.PdfWriter; ItemInfo myItemInfo = section as ItemInfo; // 792: 72 * 11 inches - TopRow - Top is high value float _PointsPerPage = 792; - float yTopMargin = _PointsPerPage - (float)myItemInfo.MyDocStyle.Layout.TopRow; - float yBottomMargin = yTopMargin - (float)myItemInfo.MyDocStyle.Layout.PageLength - 2 * vlnPrintObject.SixLinesPerInch; + float yTopMargin = _PointsPerPage - (float)myItemInfo.MyDocStyle.Layout.TopMargin; + float yBottomMargin = Math.Max(0, yTopMargin - (float)myItemInfo.MyDocStyle.Layout.PageLength - 2 * vlnPrintObject.SixLinesPerInch); vlnParagraph.Prefix = myItemInfo.Path; Rtf2Pdf.PdfDebug = true; Rtf2Pdf.Offset = new PointF(0, 2.5F); _MyHelper.ChangeBarDefinition = MyChangeBarDefinition; - vlnParagraph myParagraph = new vlnParagraph(null, cb, myItemInfo, (float)myItemInfo.MyDocStyle.Layout.LeftMargin, 0, 0, myItemInfo.ColumnMode, myItemInfo.ActiveFormat); + vlnParagraph myParagraph = new vlnParagraph(null, cb, myItemInfo, (float)myItemInfo.MyDocStyle.Layout.LeftMargin, _NoBreakYOffset, 0, myItemInfo.ColumnMode, myItemInfo.ActiveFormat); if (myItemInfo.HasChildren) myParagraph.ToPdf(cb, yTopMargin, yTopMargin, yBottomMargin); else - PrintTextMessage(cb, "No Section Content"); - if (_DoBlankForFoldout && section.IsDefaultSection) + PrintTextMessage(cb, "No Section Content", _TextLayer); + ItemInfo nxtSection = null; + SectionConfig.SectionPagination sp = SectionConfig.SectionPagination.Separate; // always the default + if ( section.NextItemCount > 0) { - cb.PdfDocument.NewPage(); - cb.Circle(400, 100, 50); + SectionInfo tmpii = SectionInfo.Get(section.NextItem.ItemID); + if (tmpii == null) Console.WriteLine("here"); + nxtSection = tmpii; + if (!section.IsAccPages) + { + SectionConfig sc = tmpii.SectionConfig; + try + { + if (sc != null) sp = sc.Section_Pagination; + } + catch (Exception ex) + { + sp = SectionConfig.SectionPagination.Separate; + } + } + } + //if (nxtSection != null && sp == SectionConfig.SectionPagination.Separate) + if (sp == SectionConfig.SectionPagination.Separate) + { + cb.PdfDocument.NewPage(); // end of step section + _NoBreakYOffset = 0; + } + else + { + _NoBreakYOffset = myParagraph.YBottomMost; } - cb.PdfDocument.NewPage(); OnStatusChanged("StepSection converted to PDF " + section.ShortPath, PromsPrinterStatusType.BuildStep); } + public static void DoFoldoutPage(PdfContentByte cb, string str, PdfLayer textLayer) + { + + cb.Circle(400, 100, 50); + PrintTextMessage(cb, "Foldout for: " + str, textLayer); + cb.PdfDocument.NewPage(); // Temporary for foldout/16bit-32bit page alignment + } + public static void DoFoldoutPage(PdfContentByte cb, string str, PdfLayer textLayer, VlnSvgPageHelper myPageHelper) + { + if (_MyFoldoutSection == null) return; + SectionInfo saveSect = myPageHelper.MySection; + myPageHelper.MySection = _MyFoldoutSection; + myPageHelper.OnFoldoutPage = true; + if (_MyFoldoutReader != null) + { + bool doimport2 = true; + PdfImportedPage fgPage = null; + try + { + fgPage = cb.PdfWriter.GetImportedPage(_MyFoldoutReader,1); + } + catch (Exception ex) + { + Console.WriteLine(ex); + doimport2 = false; + } + if (doimport2) AddImportedPageToLayer(cb.PdfWriter.DirectContent, textLayer, fgPage, 0, 0); + } + //PrintTextMessage(cb, "Foldout for: " + str, textLayer); + cb.PdfDocument.NewPage(); // Temporary for foldout/16bit-32bit page alignment + myPageHelper.MySection = saveSect; + myPageHelper.OnFoldoutPage = false; + } } }