diff --git a/PROMS/VEPROMS User Interface/DlgPrintProcedure.cs b/PROMS/VEPROMS User Interface/DlgPrintProcedure.cs index d27b1844..a895a16f 100644 --- a/PROMS/VEPROMS User Interface/DlgPrintProcedure.cs +++ b/PROMS/VEPROMS User Interface/DlgPrintProcedure.cs @@ -676,7 +676,7 @@ namespace VEPROMS // RHM 20120925 Overlay the bottom of the dialog so that cancel button is covered. frmPDFStatusForm frmStatus = new frmPDFStatusForm(MyProcedure, RevNumAndDate, pw.ToString(), cbxDebug.Checked, cbxOrPgBrk.Checked, cbxOpenAfterCreate2.Checked, cbxOverwritePDF2.Checked, myPDFPath, cbd, txbPDFName.Text, new Point(Left, Bottom - 50), - swtbtnBlankPgsForDuplex.Value, _AllProcedures || Automatic, Prefix, SaveLinks, RemoveTrailingHardReturnsAndManualPageBreaks, swtbtnPROMSVersion.Value, true, tbBlankPage.Text);//C2018-009 print PROMS version + swtbtnBlankPgsForDuplex.Value, _AllProcedures || Automatic, Prefix, SaveLinks, RemoveTrailingHardReturnsAndManualPageBreaks, swtbtnPROMSVersion.Value, true, tbBlankPage.Text, _MergedPfd);//C2018-009 print PROMS version frmStatus.CloseWhenDone = true; Application.DoEvents(); frmStatus.CancelStop = true; @@ -704,7 +704,7 @@ namespace VEPROMS // B2016-249 Output Procedure to folder associated with Parent Child frmPDFStatusForm frmStatus = new frmPDFStatusForm(MyProcedure, RevNumAndDate, pw.ToString(), cbxDebug.Checked, cbxOrPgBrk.Checked, cbxOpenAfterCreate2.Checked, cbxOverwritePDF2.Checked, GetMultiunitPDFPath(), cbd, txbPDFName.Text, new Point(Left, Bottom - 50), - swtbtnBlankPgsForDuplex.Value, _AllProcedures || Automatic, Prefix, SaveLinks, RemoveTrailingHardReturnsAndManualPageBreaks, swtbtnPROMSVersion.Value, true, tbBlankPage.Text);//C2018-009 print PROMS version + swtbtnBlankPgsForDuplex.Value, _AllProcedures || Automatic, Prefix, SaveLinks, RemoveTrailingHardReturnsAndManualPageBreaks, swtbtnPROMSVersion.Value, true, tbBlankPage.Text, _MergedPfd);//C2018-009 print PROMS version frmStatus.CloseWhenDone = true; Application.DoEvents(); frmStatus.CancelStop = true; @@ -735,7 +735,7 @@ namespace VEPROMS // B2016-249 Output Procedure to folder associated with Parent Child frmPDFStatusForm frmStatus = new frmPDFStatusForm(MyProcedure, RevNumAndDate, pw.ToString(), cbxDebug.Checked, cbxOrPgBrk.Checked, cbxOpenAfterCreate2.Checked, cbxOverwritePDF2.Checked, GetMultiunitPDFPath(), cbd, txbPDFName.Text, - new Point(Left, Bottom - 50), swtbtnBlankPgsForDuplex.Value, _AllProcedures || Automatic, Prefix, SaveLinks, RemoveTrailingHardReturnsAndManualPageBreaks, swtbtnPROMSVersion.Value, true, tbBlankPage.Text);//C2018-009 print PROMS version + new Point(Left, Bottom - 50), swtbtnBlankPgsForDuplex.Value, _AllProcedures || Automatic, Prefix, SaveLinks, RemoveTrailingHardReturnsAndManualPageBreaks, swtbtnPROMSVersion.Value, true, tbBlankPage.Text, _MergedPfd);//C2018-009 print PROMS version frmStatus.CloseWhenDone = true; Application.DoEvents(); frmStatus.CancelStop = true; @@ -852,7 +852,7 @@ namespace VEPROMS // B2018-124 use text of watermark form drop down list instead of enum value frmPDFStatusForm frmStatus = new frmPDFStatusForm(MyProcedure, RevNumAndDate, waterMarkText, cbxDebug.Checked, cbxOrPgBrk.Checked, cbxOpenAfterCreate2.Checked, cbxOverwritePDF2.Checked, GetMultiunitPDFPath(), cbd, txbPDFName.Text, new Point(Left, Bottom - 50), - swtbtnBlankPgsForDuplex.Value, _AllProcedures || Automatic, Prefix, SaveLinks, RemoveTrailingHardReturnsAndManualPageBreaks, swtbtnPROMSVersion.Value, false, tbBlankPage.Text); //C2018-009 print PROMS version + swtbtnBlankPgsForDuplex.Value, _AllProcedures || Automatic, Prefix, SaveLinks, RemoveTrailingHardReturnsAndManualPageBreaks, swtbtnPROMSVersion.Value, false, tbBlankPage.Text, _MergedPfd); //C2018-009 print PROMS version frmStatus.MakePlaceKeeper = swtbtnGeneratePlacekeeper.Value; frmStatus.MakeContinuousActionSummary = cbxGenerateConActSum.Checked; if (Automatic && cbxGenerateConActSum.Checked) @@ -1140,9 +1140,11 @@ namespace VEPROMS { DateTime dtStart = DateTime.Now; _MergedPfd = new MergedPdf(PDFPath, _DocVersionInfo); + PromsPrinter.MergedLandscapePages = null; // B2019-152: MergedLandscapePages has data set when creating separate pdfs (DoCreatePDF) DoCreatePDF(); // create indivitual pdfs if (_MergedPdfPath != null && _MergedPdfPath != PDFPath) PDFPath = _MergedPfd.Folder = _MergedPdfPath; - if (!_MergedPfd.DoTheMerge()) return; // merge them together. + + if (!_MergedPfd.DoTheMerge(PromsPrinter.MergedLandscapePages)) return; // merge them together. // if the property to show the file after printing is set (on the version dialog), display it. Otherwise do a dialog to let user know it's done if (_DocVersionConfig.Print_MergedPdfsViewAfter) { diff --git a/PROMS/VEPROMS User Interface/frmPDFStatusForm.cs b/PROMS/VEPROMS User Interface/frmPDFStatusForm.cs index e257aaaf..fe75fe35 100644 --- a/PROMS/VEPROMS User Interface/frmPDFStatusForm.cs +++ b/PROMS/VEPROMS User Interface/frmPDFStatusForm.cs @@ -81,7 +81,7 @@ namespace VEPROMS get { return _DidAll; } set { _DidAll = value; } } - public frmPDFStatusForm(ItemInfo myItem, string rev, string watermark, bool debugOutput, bool origPgBrk, bool openPDF, bool overWrite, string pdfPath, ChangeBarDefinition cbd,string pdfFile, Point newLocation,bool insertBlankPages, bool allOrAuto, string prefix, bool saveLinks, bool removeTrailingHardReturnsAndManualPageBreaks, bool showPROMSVer, bool didAll, string blankPageText) + public frmPDFStatusForm(ItemInfo myItem, string rev, string watermark, bool debugOutput, bool origPgBrk, bool openPDF, bool overWrite, string pdfPath, ChangeBarDefinition cbd, string pdfFile, Point newLocation, bool insertBlankPages, bool allOrAuto, string prefix, bool saveLinks, bool removeTrailingHardReturnsAndManualPageBreaks, bool showPROMSVer, bool didAll, string blankPageText, MergedPdf mergedPdf) { Prefix = prefix; OpenPDF = openPDF; @@ -90,7 +90,7 @@ namespace VEPROMS // if the version number of PROMS is 1.0, then we are running a Demo version. // When running a Demo version, force a "Sample" watermark when printing. // B2020-022 append a ".pdf" extension if the file name does on have one. - MyPromsPrinter = new PromsPrinter(myItem, rev, (VlnSettings.ReleaseMode.Equals("DEMO")) ? "Sample" : watermark, debugOutput, origPgBrk, pdfPath + @"\Compare", false, overWrite, cbd, (pdfFile.ToUpper().EndsWith(".PDF"))?pdfFile:pdfFile+".pdf", insertBlankPages, allOrAuto,Prefix,saveLinks,removeTrailingHardReturnsAndManualPageBreaks, blankPageText, DidAll); + MyPromsPrinter = new PromsPrinter(myItem, rev, (VlnSettings.ReleaseMode.Equals("DEMO")) ? "Sample" : watermark, debugOutput, origPgBrk, pdfPath + @"\Compare", false, overWrite, cbd, (pdfFile.ToUpper().EndsWith(".PDF"))?pdfFile:pdfFile+".pdf", insertBlankPages, allOrAuto,Prefix,saveLinks,removeTrailingHardReturnsAndManualPageBreaks, blankPageText, DidAll, mergedPdf); MyPromsPrinter.PromsVersion = (showPROMSVer) ? AboutVEPROMS.PROMSVersion : ""; //C2018-009 print PROMS version PDFPath = pdfPath; this.Text = "Creating PDF of " + myItem.DisplayNumber; diff --git a/PROMS/Volian.Print.Library/MergedPdf.cs b/PROMS/Volian.Print.Library/MergedPdf.cs index d549ba4c..5c39110b 100644 --- a/PROMS/Volian.Print.Library/MergedPdf.cs +++ b/PROMS/Volian.Print.Library/MergedPdf.cs @@ -74,7 +74,7 @@ namespace Volian.Print.Library _docVersionInfo = dvi; } // the following merges the procedure pdfs into a single pdf - public bool DoTheMerge() + public bool DoTheMerge(Dictionary> MergedLandscapPages) { if (MergedPdfs == null) { @@ -117,6 +117,15 @@ namespace Volian.Print.Library FlexibleMessageBox.Show("Error in finding pdf files to merge. Cannot print with date/time as part of pdf name. Or check that individual pdfs were generated.", "Error on CreatePdf", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } + // B2019-152: The MergedLandscapePages Dictionary contains page numbers for pdfs that need to be landscaped. These are + // added on 'endpages' when printing is done. + List LandscapePages = null; // List of landscaped pages for a pdf + if (PromsPrinter.MergedLandscapePages != null) + { + string fname = mpp.PdfFileName.Substring(0, mpp.PdfFileName.IndexOf(".pdf")); + if (PromsPrinter.MergedLandscapePages.ContainsKey(fname)) + LandscapePages = PromsPrinter.MergedLandscapePages[fname]; + } PdfReader reader = null; try // B2019-041: added a try/catch for when a corrupt pdf was created for a procedure, just skip & add message to error log. { @@ -134,8 +143,10 @@ namespace Volian.Print.Library PdfImportedPage page = writer.GetImportedPage(reader, currentPageNumber); // gets a page that is 'ready' to be written to combined pdf if (doPageNum) // get the string & fill in with and numbers { + bool landscape = false; + if (LandscapePages != null && LandscapePages.Contains(currentPageNumber - 1)) landscape = true; string outputpageof = _pageof.Replace("", mergedPageNumber.ToString()).Replace("", totalPages.ToString()); - AddPageNumberToPage(page, canvas, outputpageof); + AddPageNumberToPage(page, canvas, outputpageof, landscape); } PdfDestination dest = new PdfDestination(PdfDestination.FIT); // if on the first page, add the pdfname & title as part of outline. If on remaining pages, just put out page number. @@ -158,36 +169,78 @@ namespace Volian.Print.Library } // this method adds the page number to the page before it is merged in. It determines the position from the properties // that were set on the doc version properties dialog (these values were set as local class variables from GetPageOfInfo) - private void AddPageNumberToPage(PdfImportedPage page, PdfContentByte cb, string outputpage) + private void AddPageNumberToPage(PdfImportedPage page, PdfContentByte cb, string outputpage, bool landscape) { float pgright = page.BoundingBox.Right; float pgleft = page.BoundingBox.Left; float pgtop = page.BoundingBox.Top; float pgbot = page.BoundingBox.Bottom; + // B2019-152: Landscape page numbers when merging + if (landscape) + { + pgright = page.BoundingBox.Top; + pgleft = page.BoundingBox.Bottom; + pgtop = page.BoundingBox.Right; + pgbot = page.BoundingBox.Left; + } Phrase ph = new Phrase(); Chunk chk = new Chunk(outputpage, _itextFont); ph.Add(chk); Paragraph pg = new Paragraph(ph); ColumnText columnText = new ColumnText(cb); + cb.SaveState(); switch (_corner) { case MergedPdfsPageNumCorner.TopRight: columnText.Alignment = Element.ALIGN_RIGHT; - columnText.SetSimpleColumn(0, pgtop - _yloc, pgright - _xloc, 0); + if (landscape) // B2019-152: landscape page numbers + { + System.Drawing.Drawing2D.Matrix myMatrix1 = new System.Drawing.Drawing2D.Matrix(0, 1, -1, 0, cb.PdfDocument.PageSize.Height, 0); + cb.Transform(myMatrix1); + columnText.SetSimpleColumn(0, pgright - _yloc, pgright - _xloc, 0); + } + else + columnText.SetSimpleColumn(0, pgtop - _yloc, pgright - _xloc, 0); break; case MergedPdfsPageNumCorner.BottomRight: columnText.Alignment = Element.ALIGN_RIGHT; - columnText.SetSimpleColumn(0, _yloc, pgright - _xloc, 0); + if (landscape) // B2019-152: landscape page numbers + { + System.Drawing.Drawing2D.Matrix myMatrix2 = new System.Drawing.Drawing2D.Matrix(0, 1, -1, 0, cb.PdfDocument.PageSize.Width, 0); + cb.Transform(myMatrix2); + columnText.SetSimpleColumn(0, _yloc, pgright - _xloc, 0); + } + else + columnText.SetSimpleColumn(0, _yloc, pgright - _xloc, 0); break; case MergedPdfsPageNumCorner.TopLeft: - columnText.SetSimpleColumn(_xloc, pgtop - _yloc, pgright, 0); // page alignment defaults to ALIGN_LEFT + if (landscape) // B2019-152: landscape page numbers + { + System.Drawing.Drawing2D.Matrix myMatrix3 = new System.Drawing.Drawing2D.Matrix(0, 1, -1, 0, cb.PdfDocument.PageSize.Height, 0); + cb.Transform(myMatrix3); + columnText.SetSimpleColumn(_xloc, pgright - _yloc, pgright - _xloc, 0); + } + else + { + columnText.SetSimpleColumn(_xloc, pgtop - _yloc, pgright, 0); // page alignment defaults to ALIGN_LEFT + } break; case MergedPdfsPageNumCorner.BottomLeft: - columnText.SetSimpleColumn(_xloc, _yloc, pgright, 0); // page alignment defaults to ALIGN_LEFT + if (landscape) // B2019-152: landscape page numbers + { + System.Drawing.Drawing2D.Matrix myMatrix4 = new System.Drawing.Drawing2D.Matrix(0, 1, -1, 0, cb.PdfDocument.PageSize.Width, 0); + cb.Transform(myMatrix4); + columnText.SetSimpleColumn(_xloc, _yloc, pgright - _xloc, 0); + } + else + { + columnText.SetSimpleColumn(_xloc, _yloc, pgright, 0); // page alignment defaults to ALIGN_LEFT + } break; } columnText.AddText(pg); columnText.Go(); + cb.RestoreState(); } // this method gets the format, font & location data from the doc version properties that are stored on the doc version's // config field. It saves them as local class variables to be used in other places in this class. diff --git a/PROMS/Volian.Print.Library/PromsPrinter.cs b/PROMS/Volian.Print.Library/PromsPrinter.cs index 4b17972a..110a233a 100644 --- a/PROMS/Volian.Print.Library/PromsPrinter.cs +++ b/PROMS/Volian.Print.Library/PromsPrinter.cs @@ -272,9 +272,14 @@ namespace Volian.Print.Library get { return _MergeNotIncluded; } set { _MergeNotIncluded = value; } } - + private MergedPdf _MergedPdf; + public MergedPdf MergedPdf + { + get { return _MergedPdf; } + set { _MergedPdf = value; } + } public PromsPrinter(ItemInfo myItem, string rev, string watermark, bool debugOutput, bool origPgBrk, string backgroundFolder, bool openPDF, bool overWrite, - ChangeBarDefinition cbd, String pdfFile, bool insertBlankPages, bool batchPrint, string prefix, bool saveLinks, bool removeTrailngHardReturnsAndManualPageBreaks, string blankPageText, bool didAll) + ChangeBarDefinition cbd, String pdfFile, bool insertBlankPages, bool batchPrint, string prefix, bool saveLinks, bool removeTrailngHardReturnsAndManualPageBreaks, string blankPageText, bool didAll, MergedPdf mergedPdf) { Prefix = prefix; // RHM20150506 Multiline ItemID TextBox _MyItem = myItem; @@ -295,6 +300,7 @@ namespace Volian.Print.Library _BlankPageText = blankPageText; _DidAll = didAll; _MergeNotIncluded = false; + _MergedPdf = mergedPdf; //_MyReaderHelper.LoadTree(myItem); } // Pass 1 PDF Name @@ -311,6 +317,9 @@ namespace Volian.Print.Library get { return _BeforePageNumber2Pdf; } set { _BeforePageNumber2Pdf = value; } } + // B2019-152: MergedLandscapePages is a dictionary whose key is the pdf file name & values are all of the page numbers + // in that pdf that should have landscaped page numbers. These are added when the page is finished (onEndPage) + public static Dictionary> MergedLandscapePages = null; public string Print(string pdfFolder, bool makePlacekeeper, bool makeContinuousActionSummary) { if (_MyItem is ProcedureInfo) @@ -1273,6 +1282,22 @@ namespace Volian.Print.Library } ProfileTimer.Pop(profileDepth); } + // B2019-152: AddMergedLandscapePage adds entries to the dictionary that keeps track of what pages in a pdf are landscape + // so that if merge is done, the pages that are landscaped can have landscaped page numbers placed on them + public static void AddMergedLandscapePage(VlnSvgPageHelper _MyHelper, string PDFFile) + { + string tmp = PDFFile.Substring(0,PDFFile.IndexOf(".pdf")); + if (MergedLandscapePages == null) MergedLandscapePages = new Dictionary>(); + if (MergedLandscapePages.ContainsKey(tmp)) + MergedLandscapePages[tmp].Add(_MyHelper.CurrentPageNumber); + else + { + // Create the list & add this to dictionary, pdf file with page list. + List children = new List(); + children.Add(_MyHelper.CurrentPageNumber); + MergedLandscapePages.Add(tmp, children); + } + } private void GenerateTOC(SectionInfo tocSection, ProcedureInfo myProcedure, PdfContentByte cb, PdfLayer textLayer) { iTextSharp.text.pdf.PdfWriter writer = cb.PdfWriter; diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index c87ec5a0..baf99a26 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -249,6 +249,8 @@ namespace Volian.Print.Library int profileDepth = ProfileTimer.Push(">>>> OnEndPage"); InitialsPrinted = false; MyPromsPrinter.OnStatusChanged(string.Format("Page {0}", CurrentPageNumber+1)); + // B2019-152: Landscape page merged page numbers + if (this.MySection != null && MySection.MyDocStyle.LandscapePageList) PromsPrinter.AddMergedLandscapePage(this, MyPromsPrinter.PDFFile); bool onBlankPage = OnBlankPage; if (OnBlankPage) {