B2019-152: landscape page numbers for print all/merge
This commit is contained in:
@@ -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<string, List<int>> 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<int> 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 <page> and <of> numbers
|
||||
{
|
||||
bool landscape = false;
|
||||
if (LandscapePages != null && LandscapePages.Contains(currentPageNumber - 1)) landscape = true;
|
||||
string outputpageof = _pageof.Replace("<page>", mergedPageNumber.ToString()).Replace("<of>", 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.
|
||||
|
Reference in New Issue
Block a user