Turn off the landscape mode setting in words section after we finish printing them.

This commit is contained in:
John Jenko 2014-04-15 19:57:23 +00:00
parent 9573bb4b7b
commit 59e8e7c6dc

View File

@ -505,6 +505,11 @@ namespace Volian.Print.Library
if (mySection.IsAutoTOCSection)
GenerateTOC(mySection, myProcedure, cb, _TextLayer);
// is this the right place for PlaceKeeper?
// I think we need to check if the actual PlaceKeeper section has the PlaceKeeper flag set (for auto generation)
// users can turn this off and edit the section manaully in 16-bit.
//else if (mySection.IsPlacekeeperSection)
// GeneratePlaceKeeper(mySection, myProcedure, cb, _TextLayer);
else
{
if (mySection.IsStepSection)
@ -631,9 +636,9 @@ namespace Volian.Print.Library
}
float yoff = 0;
if (_MyHelper.DidFirstPageDocStyle) yoff = origYoff - (float)mySection.MyDocStyle.Layout.TopMargin;
AddImportedPageToLayer(cb.PdfWriter.DirectContent, _MSWordLayer, fgPage, (float)(mySection.MyDocStyle.Layout.MSWordXAdj??0), (float)(mySection.MyDocStyle.Layout.MSWordYAdj??0)+yoff);
if(DebugPagination.IsOpen) DebugPagination.WriteLine("{0:D6},'{1}',{2}",
_MyHelper.MyPdfContentByte.PdfWriter.CurrentPageNumber, mySection.ShortPath,pageNumber);
AddImportedPageToLayer(cb.PdfWriter.DirectContent, _MSWordLayer, fgPage, (float)(mySection.MyDocStyle.Layout.MSWordXAdj ?? 0), (float)(mySection.MyDocStyle.Layout.MSWordYAdj ?? 0) + yoff);
if (DebugPagination.IsOpen) DebugPagination.WriteLine("{0:D6},'{1}',{2}",
_MyHelper.MyPdfContentByte.PdfWriter.CurrentPageNumber, mySection.ShortPath, pageNumber);
}
if (ii == sectPageCount - 1)
@ -667,7 +672,7 @@ namespace Volian.Print.Library
_MyHelper.DidFirstPageDocStyle = true;
//DebugPagination.WriteLine("CreateWordDocPdf");
if ((mySection.MyDocStyle.StructureStyle.Where & E_DocStyleUse.UseOnFirstPage) > 0)
_MyHelper.MySection = mySection; // this resets the docstyle/pagestyle if pagehelper
_MyHelper.MySection = mySection; // this resets the docstyle/pagestyle in pagehelper
OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage);
}
}
@ -676,6 +681,10 @@ namespace Volian.Print.Library
cb.PdfDocument.NewPage(); // can we put out 'error on page'?
_MyLog.InfoFormat("NewPage error on page {0}", cb.PdfWriter.CurrentPageNumber);
}
finally
{
_MyHelper.IsLandscape = false; // reset landscape mode to false
}
}
private void GenerateTOC(SectionInfo tocSection, ProcedureInfo myProcedure, PdfContentByte cb, PdfLayer textLayer)
{
@ -693,6 +702,22 @@ namespace Volian.Print.Library
//_MyLog.InfoFormat("NewPage 4 {0}", cb.PdfWriter.CurrentPageNumber);
_NoBreakYOffset = 0;
}
//private void GeneratePlaceKeeper(SectionInfo pkSection, ProcedureInfo myProcedure, PdfContentByte cb, PdfLayer textLayer)
//{
// iTextSharp.text.pdf.PdfWriter writer = cb.PdfWriter;
// float _PointsPerPage = 792;
// float yTopMargin = _PointsPerPage - (float)pkSection.MyDocStyle.Layout.TopMargin;
// float yBottomMargin = Math.Max(0, yTopMargin - (float)pkSection.MyDocStyle.Layout.PageLength); // - 2 * vlnPrintObject.SixLinesPerInch);
// if (textLayer != null) cb.BeginLayer(textLayer);
// PlacekeeperData pkdata = pkSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.PlacekeeperData;
// ItemInfo procItem = ItemInfo.Get(myProcedure.ItemID);
// lastyLocation = 0;
// AddSectionToPK(pkSection, procItem, pkdata, cb, yTopMargin, 0);
// if (textLayer != null) cb.EndLayer();
// cb.PdfDocument.NewPage();
// //_MyLog.InfoFormat("NewPage 4 {0}", cb.PdfWriter.CurrentPageNumber);
// _NoBreakYOffset = 0;
//}
float lastyLocation = 0;
private string GetRtfToC(string txt, TableOfContentsData tOfCData)
{
@ -849,6 +874,158 @@ namespace Volian.Print.Library
_MyHelper.MyPdfContentByte.AddTemplate(tmp, leftMargin + secPagePos, (yPageStartAdj - yLocation) - height / 2);
}
//private string GetRtfPlacekeeper(string txt, PlacekeeperData pkCData)
//{
// StringBuilder _RtfSB = new StringBuilder();
// Volian.Controls.Library.DisplayText pktxt = new Volian.Controls.Library.DisplayText(txt, pkCData.Font, false);
// System.Drawing.Font myFont = pktxt.TextFont.WindowsFont;
// _RtfSB.Append(vlnPrintObject.AddFontTable(myFont));
// _RtfSB.Append(pktxt.StartText);
// _RtfSB.Append("}");
// return _RtfSB.ToString();
//}
//private float AddSectionToPK(SectionInfo pkSection, ItemInfo ii, PlacekeeperData pkData, PdfContentByte cb, float yPageStart, float yLocation)
//{
// SectionConfig pkSC = pkSection.MyConfig as SectionConfig;
// if (pkSC.Section_Placekeeper != "Y") return yLocation; // automatic generation of Placekeeper turned off
// float xAdjNumber = -6 + 1.2F;
// float xAdjTitle = .8F + 1.2F;
// float xAdjTitleIndent = -6 + 2.4F;
// float yadj = 0.5F; // tweak to get 16 & 32 bit output to match.
// float yPageStartAdj = yPageStart - yadj;
// float leftMargin = (float)pkSection.MyDocStyle.Layout.LeftMargin;
// //float secNumPos = (float)tOfC.TofCSecNumPos + xAdjNumber;
// //float secTitlePos = (float)tOfC.TofCSecTitlePos + xAdjTitle;
// //float secPagePos = (float)tOfC.TofCPageNumPos + xAdjNumber;
// //float height = tOfC.Font.WindowsFont.Size * 1.5F;
// if (ii.Sections != null)
// {
// foreach (SectionInfo mySection in ii.Sections)
// {
// SectionConfig sc = mySection.MyConfig as SectionConfig;
// if (mySection.ItemID != pkSection.ItemID && sc != null && sc.Section_Placekeeper == "Y")
// {
// // Look at each step in the section and build a Placekeeper for those steps that are marked
// // need to do the section number, section title & page number. Page number
// // has to be put on at end after number of page is known, so use a Template.
// //string tmptxt = mySection.MyContent.Number == null || mySection.MyContent.Number == "" ? " " : mySection.MyContent.Number;
// //string rtfText = GetRtfPlacekeeper(tmptxt, pkData);//GetRtfToC(tmptxt, tOfC);
// //Paragraph myparagraphn = vlnPrintObject.RtfToParagraph(rtfText);
// float width = 0;
// //foreach (Chunk chkt in myparagraphn.Chunks)
// // width += chkt.GetWidthPoint();
// float numwidth = width;
// float yBottomMargin = yPageStart - (float)pkSection.MyDocStyle.Layout.PageLength + (2 * vlnPrintObject.SixLinesPerInch);
// Rtf2Pdf.Offset = new PointF(0, 2.5F);
// //// for indenting of subsections, count up tree. Only start indenting
// //// at third level, i.e. not indent on 1.0 and 1.1, but indent on 1.1.1:
// //int level = 0;
// //ItemInfo iilvl = mySection as ItemInfo;
// //while (!iilvl.IsProcedure)
// //{
// // level++;
// // iilvl = iilvl.MyParent;
// //}
// //// check what level the plant wants the auto ToC indented:
// //int tofCNumLevels = pkSection.ActiveFormat.PlantFormat.FormatData.SectData.AccSectionData.TableOfContentsData.TofCNumLevels ?? 0;
// //if (tofCNumLevels > 0 && level > tofCNumLevels) return yLocation;
// //level = level <= 2 ? 0 : level - 2; // no indenting until third level
// //float indentOffset = (level * (secTitlePos - secNumPos));
// // if the starting column of text would be in 'middle of' the number, just put it
// // a few spaces after the number. The '18' below represents 3 chars.
// //float adjSecTitlePos = secTitlePos + indentOffset + (level * 6);
// //if (secNumPos + numwidth + indentOffset > secTitlePos + indentOffset)
// // adjSecTitlePos = secNumPos + numwidth + 18 - xAdjTitleIndent + indentOffset;
// //rtfText = GetRtfToC(mySection.MyContent.Text, tOfC);
// //Paragraph myparagrapht = vlnPrintObject.RtfToParagraph(rtfText);
// //width = secPagePos - adjSecTitlePos - 6;
// //float retval = Rtf2Pdf.TextAt(cb, myparagrapht, leftMargin + adjSecTitlePos, yPageStart - yLocation, width, height, "", yBottomMargin);
// //float ttlRetval = retval;
// //if (retval == 0)
// //{
// // cb.PdfDocument.NewPage();
// // //_MyLog.InfoFormat("NewPage 5 {0}", cb.PdfWriter.CurrentPageNumber);
// // yLocation = lastyLocation = 0;
// // retval = Rtf2Pdf.TextAt(cb, myparagrapht, leftMargin + adjSecTitlePos, yPageStart - yLocation, width, height, "", yBottomMargin);
// // ttlRetval = retval;
// //}
// //retval = Rtf2Pdf.TextAt(cb, myparagraphn, leftMargin + secNumPos + indentOffset, yPageStart - yLocation, width * 1.3F, height, "", yBottomMargin);
// //if (retval == 0) // do a newpage, it couldn't fit on current page.
// //{
// // cb.PdfDocument.NewPage();
// // //_MyLog.InfoFormat("NewPage 5 {0}", cb.PdfWriter.CurrentPageNumber);
// // yLocation = lastyLocation = 0;
// // retval = Rtf2Pdf.TextAt(cb, myparagraphn, leftMargin + secNumPos + indentOffset, yPageStart - yLocation, width * 1.3F, height, "", yBottomMargin);
// //}
// //retval = Math.Min(retval, ttlRetval);
// //float lSpace = (tOfC.TofCLineSpacing == 2) ? 2 * vlnPrintObject.SixLinesPerInch : vlnPrintObject.SixLinesPerInch;
// //if (lastyLocation != 0 && ((lastyLocation - retval) > lSpace))
// // yLocation += (lastyLocation - retval - lSpace);
// //lastyLocation = retval;
// //// check that the page number should be in the TOC (some BGE sections do not have the page number)
// //if (!((mySection.MyDocStyle.StructureStyle.Style & E_DocStructStyle.DontNumberInTOC) == E_DocStructStyle.DontNumberInTOC))
// //{
// // // add a template for the page number:
// // // if the space character is not null & is not a space, the we've got to put out
// // // these between the section title & the page number
// // if (tOfC.TofCSpaceChar != null && tOfC.TofCSpaceChar != "" && tOfC.TofCSpaceChar != " ")
// // {
// // width = 0;
// // foreach (Chunk chkt in myparagrapht.Chunks)
// // width += chkt.GetWidthPoint();
// // float startSpace = leftMargin + adjSecTitlePos + width;
// // float endSpace = leftMargin + secPagePos;
// // float numSpace = endSpace - startSpace;
// // string spaceStr = "";
// // rtfText = GetRtfToC(tOfC.TofCSpaceChar, tOfC);
// // Paragraph tmpmyparagraph = vlnPrintObject.RtfToParagraph(rtfText);
// // float spacchrwid = 0;
// // foreach (Chunk chkt in tmpmyparagraph.Chunks)
// // spacchrwid += chkt.GetWidthPoint();
// // while (numSpace > 0)
// // {
// // spaceStr = spaceStr + tOfC.TofCSpaceChar;
// // numSpace -= spacchrwid;
// // }
// // rtfText = GetRtfToC(spaceStr, tOfC);
// // Paragraph myparagraphs = vlnPrintObject.RtfToParagraph(rtfText);
// // retval = Rtf2Pdf.TextAt(cb, myparagraphs, startSpace, yPageStart - yLocation, endSpace - startSpace, height, "", yBottomMargin);
// // }
// // // if in the pre-table of content list, just put the page number out as text.
// // // otherwise, add a template _MyHelper.MyTOCPageCounts
// // string key = "TOC" + mySection.ItemID.ToString();
// // if (mySection.IsAutoTOCSection || _MyHelper.MyTOCPageNums.ContainsKey(key))
// // {
// // string pnum = _MyHelper.MyTOCPageNums.ContainsKey(key) ? _MyHelper.MyTOCPageNums[key].ToString() : (_MyHelper.CurrentTOCPageNumber + 1).ToString();
// // rtfText = GetRtfToC(pnum, tOfC);
// // Paragraph myparagraphp = vlnPrintObject.RtfToParagraph(rtfText);
// // width = pnum.Length * 6;
// // retval = Rtf2Pdf.TextAt(cb, myparagraphp, leftMargin + secPagePos, yPageStart - yLocation, width, height, "", yBottomMargin);
// // }
// // else
// // AddTemplateTOCPageCounts(tOfC, yLocation, yPageStartAdj, leftMargin, secPagePos, height, mySection);
// //}
// yLocation += vlnPrintObject.SixLinesPerInch;
// }
// //yLocation = AddSectionToTOC(tocSection, mySection, tOfC, cb, yPageStart, yLocation);
// }
// }
// return yLocation;
//}
//private void AddTemplatePKPageCounts(TableOfContentsData tOfC, float yLocation, float yPageStartAdj, float leftMargin, float secPagePos, float height, SectionInfo mySection)
//{
// string key = "PK" + mySection.ItemID.ToString();
// PdfTemplate tmp = _MyHelper.MyTOCPageCounts.AddToTemplateList(key, _MyHelper.MyPdfWriter, "{TOCPAGE}", tOfC.Font.WindowsFont, Element.ALIGN_LEFT, PrintOverride.TextColor);
// _MyHelper.MyPdfContentByte.AddTemplate(tmp, leftMargin + secPagePos, (yPageStartAdj - yLocation) - height / 2);
//}
private static void PrintTextMessage(PdfContentByte cb, string message, PdfLayer textLayer)
{
if (textLayer != null) cb.BeginLayer(textLayer);