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

This commit is contained in:
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;
}