Logic for putting a blank page in the PDF if the procedure prints duplex foldouts

This commit is contained in:
John Jenko 2013-08-29 13:16:59 +00:00
parent 2336a70679
commit 518e3182b2
3 changed files with 93 additions and 7 deletions

View File

@ -85,6 +85,7 @@ namespace Volian.Print.Library
}
public class PromsPrinter
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public event PromsPrinterStatusEvent StatusChanged;
private void OnStatusChanged(object sender, PromsPrintStatusArgs args)
{
@ -148,7 +149,13 @@ namespace Volian.Print.Library
get { return _OriginalPageBreak; }
set { _OriginalPageBreak = value; }
}
public PromsPrinter(ItemInfo myItem, string rev, string watermark, bool debugOutput, bool origPgBrk, string backgroundFolder, bool openPDF, bool overWrite, ChangeBarDefinition cbd, String pdfFile)
private bool _InsertBlankPages;
public bool InsertBlankPages
{
get { return _InsertBlankPages; }
set { _InsertBlankPages = 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)
{
_MyItem = myItem;
_Rev = rev;
@ -160,6 +167,7 @@ namespace Volian.Print.Library
_MyChangeBarDefinition = cbd;
_PDFFile = pdfFile;
_OriginalPageBreak = origPgBrk;
_InsertBlankPages = insertBlankPages;
}
public string Print(string pdfFolder)
{
@ -280,6 +288,11 @@ namespace Volian.Print.Library
//private static PdfReader _MyFoldoutReader = null;
//private static SectionInfo _MyFoldoutSection = null;
private static List<PdfReader> _MyFoldoutReader = null;
public static List<PdfReader> MyFoldoutReader
{
get { return PromsPrinter._MyFoldoutReader; }
set { PromsPrinter._MyFoldoutReader = value; }
}
private static List<SectionInfo> _MyFoldoutSection = null;
private string Print(ProcedureInfo myProcedure, string pdfFolder)
{
@ -360,6 +373,7 @@ namespace Volian.Print.Library
if (cb == null) return null;
OnStatusChanged("Before NewPage", PromsPrinterStatusType.Before);
cb.PdfDocument.NewPage(); // Start of print
//_MyLog.InfoFormat("NewPage 1 {0}", cb.PdfWriter.CurrentPageNumber);
OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage);
if (myProcedure.Sections == null)
{
@ -461,6 +475,15 @@ namespace Volian.Print.Library
ItemInfo firstStep = mySection.Steps[0];
if (firstStep.FoldoutIndex() > -1)
DoFoldoutPage(cb, "Beginning of Step Section", _TextLayer, _MyHelper, firstStep.FoldoutIndex());
else if (!_MyHelper.CreatingFoldoutPage && _MyFoldoutReader.Count > 0 && InsertBlankPages)
{
// only insert a blank page if this section does not have a foldout (but the procedure as a whole does)
// and the checkbox on the print dialog to add blank pages is checked
_MyHelper.OnBlankPage = true;
cb.PdfDocument.Add(new iTextSharp.text.Table(1));
cb.PdfDocument.NewPage();
//_MyLog.InfoFormat("NewPage Begin Step Sect blank {0}", cb.PdfWriter.CurrentPageNumber);
}
}
CreateStepPdf(mySection, cb);
}
@ -475,6 +498,7 @@ namespace Volian.Print.Library
{
PrintTextMessage(cb, "No Proms Output", _TextLayer);
cb.PdfDocument.NewPage(); // only have 16bit pages left (for DebugMode)
//_MyLog.InfoFormat("NewPage 2 {0}", cb.PdfWriter.CurrentPageNumber);
DebugPagination.WriteLine("{0:D6},'{1}'",
_MyHelper.MyPdfContentByte.PdfWriter.CurrentPageNumber, "No PROMS Output");
}
@ -547,6 +571,15 @@ namespace Volian.Print.Library
OnStatusChanged("Read MSWord", PromsPrinterStatusType.ReadMSWord);
if (doimport2)
{
if (cb.PdfWriter.CurrentPageNumber > 1 && _MyFoldoutReader.Count > 0 && InsertBlankPages)
{
// only insert a blank page if this section does not have a foldout (but the procedure as a whole does)
// and the checkbox on the print dialog to add blank pages is checked
_MyHelper.OnBlankPage = true;
cb.PdfDocument.Add(new iTextSharp.text.Table(1));
cb.PdfDocument.NewPage();
//_MyLog.InfoFormat("NewPage 3 blank {0}", cb.PdfWriter.CurrentPageNumber);
}
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);
@ -578,6 +611,7 @@ namespace Volian.Print.Library
else
_MyHelper.IsLandscape = false;
cb.PdfDocument.NewPage(); // Word Document
//_MyLog.InfoFormat("NewPage 3 {0}", cb.PdfWriter.CurrentPageNumber);
// if this document style has another style that is for pages other than first, we need to
// reset the document style off of this section AND reset docstyle values used.
@ -591,6 +625,7 @@ namespace Volian.Print.Library
catch (Exception ex)
{
cb.PdfDocument.NewPage(); // can we put out 'error on page'?
_MyLog.InfoFormat("NewPage error on page {0}", cb.PdfWriter.CurrentPageNumber);
}
}
private void GenerateTOC(SectionInfo tocSection, ProcedureInfo myProcedure, PdfContentByte cb, PdfLayer textLayer)
@ -606,6 +641,7 @@ namespace Volian.Print.Library
AddSectionToTOC(tocSection, procItem, tOfC, cb, yTopMargin, 0);
if (textLayer != null) cb.EndLayer();
cb.PdfDocument.NewPage();
//_MyLog.InfoFormat("NewPage 4 {0}", cb.PdfWriter.CurrentPageNumber);
_NoBreakYOffset = 0;
}
float lastyLocation = 0;
@ -677,6 +713,7 @@ namespace Volian.Print.Library
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 = 0;
retval = Rtf2Pdf.TextAt(cb, myparagraphn, leftMargin + secNumPos + indentOffset, yPageStart - yLocation, width * 1.3F, height, "", yBottomMargin);
}
@ -810,6 +847,7 @@ namespace Volian.Print.Library
if (sp == SectionConfig.SectionPagination.Separate)
{
cb.PdfDocument.NewPage(); // end of step section
//_MyLog.InfoFormat("NewPage 6 {0}", cb.PdfWriter.CurrentPageNumber);
_NoBreakYOffset = 0;
yPageStart = yTopMargin;
}
@ -836,6 +874,7 @@ namespace Volian.Print.Library
cb.Circle(400, 100, 50);
PrintTextMessage(cb, "Foldout for: " + str, textLayer);
cb.PdfDocument.NewPage(); // Temporary for foldout/16bit-32bit page alignment
//_MyLog.InfoFormat("NewPage 7 {0}", cb.PdfWriter.CurrentPageNumber);
}
public static void DoFoldoutPage(PdfContentByte cb, string str, PdfLayer textLayer, VlnSvgPageHelper myPageHelper, int foldoutindx)
{
@ -848,7 +887,7 @@ namespace Volian.Print.Library
bool doimport2 = true;
PdfImportedPage fgPage = null;
try
{
{ // read saved foldout page
fgPage = cb.PdfWriter.GetImportedPage(_MyFoldoutReader[foldoutindx],1);
}
catch (Exception ex)
@ -857,14 +896,16 @@ namespace Volian.Print.Library
doimport2 = false;
}
if (doimport2)
{
{// put the saved foldout page into the PDF
AddImportedPageToLayer(cb.PdfWriter.DirectContent, textLayer, fgPage, 0, 0);
DebugPagination.WriteLine("{0:D6},'{1}',{2}",
myPageHelper.MyPdfContentByte.PdfWriter.CurrentPageNumber, "Foldout", 1);
}
}
//_MyLog.InfoFormat("DoFoldoutPage {0}", cb.PdfWriter.CurrentPageNumber);
//PrintTextMessage(cb, "Foldout for: " + str, textLayer);
cb.PdfDocument.NewPage(); // Temporary for foldout/16bit-32bit page alignment
//_MyLog.InfoFormat("NewPage 8 {0}", cb.PdfWriter.CurrentPageNumber);
myPageHelper.MySection = saveSect;
myPageHelper.OnFoldoutPage = false;
}

View File

@ -92,9 +92,25 @@ namespace Volian.Print.Library
AddBookmarks(writer);
MyPageCounts.DrawTemplates();
}
private bool _OnBlankPage = false;
public bool OnBlankPage // used while inserting a blank page when printing a procedure with duplex foldouts
{
get { return _OnBlankPage; }
set { _OnBlankPage = value; }
}
private bool _AddBlankPagesForDuplexPrinting = false;
public bool AddBlankPagesForDuplexPrinting // Tells us if a the option to add a blank page is turn on (for procedures with duplex foldouts)
{
get { return _AddBlankPagesForDuplexPrinting; }
set { _AddBlankPagesForDuplexPrinting = value; }
}
public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document)
{
if (!OnFoldoutPage)
if (OnBlankPage)
{
OnBlankPage = false;
}
else if (!OnFoldoutPage)
{
if (DidFirstPageDocStyle) ResetDocStyleAndValues();
AddBookmarks(writer);

View File

@ -654,6 +654,7 @@ namespace Volian.Print.Library
string tmpstr = null;
SectionInfo si = SectionInfo.Get(MyItemInfo.ItemID);
cb.PdfDocument.NewPage();
//_MyLog.InfoFormat("NewPage 9 {0}", cb.PdfWriter.CurrentPageNumber);
MyPageHelper.MyPromsPrinter.CreateWordDocPdf(cb, si, ref tmp, ref tmpstr);
Processed = true;
return yPageStart;
@ -678,7 +679,8 @@ namespace Volian.Print.Library
case 1: // Break on High Level Step
OutputOtherPageSteps(cb, YTopMost, yPageStart, yTopMargin, yBottomMargin);
cb.PdfDocument.NewPage();
if(MyItemInfo.IsSection || (MyItemInfo.IsHigh && MyItemInfo.MyPrevious != null)) //do not reset for 1st step
//_MyLog.InfoFormat("NewPage 10 {0}", cb.PdfWriter.CurrentPageNumber);
if (MyItemInfo.IsSection || (MyItemInfo.IsHigh && MyItemInfo.MyPrevious != null)) //do not reset for 1st step
ResetDocStyleAndValues(ref yTopMargin, ref yBottomMargin);
DebugText.WriteLine("Paginate1");
if (MyItemInfo.IsSection)
@ -687,8 +689,17 @@ namespace Volian.Print.Library
MyPageHelper.PageBookmarks.Add(MyItemInfo, ((si.DisplayNumber ?? "") == "" ? "" : si.DisplayNumber + " - ") + si.DisplayText, null);
}
// Only do foldout page if not done for section break, i.e. check the there's a previous step.
if (MyItemInfo.MyPrevious != null && MyItemInfo.FoldoutIndex()>-1)
if (MyItemInfo.MyPrevious != null && MyItemInfo.FoldoutIndex() > -1)
PromsPrinter.DoFoldoutPage(cb, "HLS", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.FoldoutIndex());
else if (PromsPrinter.MyFoldoutReader.Count > 0 && MyPageHelper.MyPromsPrinter.InsertBlankPages)
{
// insert a blank page if this step section had a foldout associated and the checkbox
// on the print dialog, to add blank pages, is checked
MyPageHelper.OnBlankPage = true;
cb.PdfDocument.Add(new iTextSharp.text.Table(1));
cb.PdfDocument.NewPage();
//_MyLog.InfoFormat("NewPage 10 blank {0}", cb.PdfWriter.CurrentPageNumber);
}
yPageStart = yTopMargin + YTopMost;
DoCheckOffHeader(cb, MyItemInfo, yLocation, yTopMargin, yPageStart);
@ -737,10 +748,18 @@ namespace Volian.Print.Library
MyPageHelper.BottomMessage = new vlnText(cb, this, myMsg, myMsg, docstyle.Layout.LeftMargin + XOffsetBox + docstyle.Continue.Bottom.Margin ?? 0, msg_yLocation, docstyle.Continue.Bottom.Font);// MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font);
}
cb.PdfDocument.NewPage();
//_MyLog.InfoFormat("NewPage 11 {0}", cb.PdfWriter.CurrentPageNumber);
ResetDocStyleAndValues(ref yTopMargin, ref yBottomMargin);
DebugText.WriteLine("Paginate2");
if (MyItemInfo.MyHLS.FoldoutIndex()>-1)
if (MyItemInfo.MyHLS.FoldoutIndex() > -1)
PromsPrinter.DoFoldoutPage(cb, "Break within Step", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.MyHLS.FoldoutIndex()); // temporary foldout
else if (PromsPrinter.MyFoldoutReader.Count > 0 && MyPageHelper.MyPromsPrinter.InsertBlankPages)
{
MyPageHelper.OnBlankPage = true;
cb.PdfDocument.Add(new iTextSharp.text.Table(1));
cb.PdfDocument.NewPage();
_MyLog.InfoFormat("NewPage Break within step blank {0}", cb.PdfWriter.CurrentPageNumber);
}
// if there is a 'container vlnbox' around the HLS, flag that the drawn box must also break:
if (MyHighLevelParagraph != null && MyHighLevelParagraph.PartsContainer != null && MyHighLevelParagraph.PartsContainer.Count > 0)
@ -793,6 +812,7 @@ namespace Volian.Print.Library
{
OutputOtherPageSteps(cb, YTopMost, yPageStart, yTopMargin, yBottomMargin);
cb.PdfDocument.NewPage(); // HLS (7 lpi) breakif (MyItemInfo.IsSection)
//_MyLog.InfoFormat("NewPage 12 {0}", cb.PdfWriter.CurrentPageNumber);
ResetDocStyleAndValues(ref yTopMargin, ref yBottomMargin);
DebugText.WriteLine("Paginate3");
if (MyItemInfo.IsSection)
@ -802,6 +822,15 @@ namespace Volian.Print.Library
}
if (MyItemInfo.FoldoutIndex() > -1)
PromsPrinter.DoFoldoutPage(cb, "HLS (7 lpi) break", MyPageHelper.TextLayer, MyPageHelper, MyItemInfo.FoldoutIndex());
else if (PromsPrinter.MyFoldoutReader.Count > 0 && MyPageHelper.MyPromsPrinter.InsertBlankPages)
{
// insert a blank page if this step section had a foldout associated and the checkbox
// on the print dialog, to add blank pages, is checked
MyPageHelper.OnBlankPage = true;
cb.PdfDocument.Add(new iTextSharp.text.Table(1));
cb.PdfDocument.NewPage();
//_MyLog.InfoFormat("NewPage 12 lpi blank {0}", cb.PdfWriter.CurrentPageNumber);
}
// If "ContinueSectionHeader" (format flag) is true then print the section title with "(Continued)" appended to it
if (!MyItemInfo.IsSection && MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.ContinueSectionHeader)