Print Library, Svg Library, Utils Library, XYPlots
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
@@ -14,34 +13,15 @@ namespace Volian.Print.Library
|
||||
{
|
||||
public class MergedPdfProc
|
||||
{
|
||||
private string _Title;
|
||||
public string Title
|
||||
public string Title { get; // used for pdf outline
|
||||
set; }
|
||||
public int PageCount { get; set; }
|
||||
public string PdfFileName { get; set; }
|
||||
public bool FirstPageNoPageNum { get; set; } = false;
|
||||
public MergedPdfProc(string title, string pfname)
|
||||
{
|
||||
get { return _Title; } // used for pdf outline
|
||||
set { _Title = value; }
|
||||
}
|
||||
private int _PageCount; // number of pages in the particular pdf, to aid in determining total page count for merged pdf
|
||||
public int PageCount
|
||||
{
|
||||
get { return _PageCount; }
|
||||
set { _PageCount = value; }
|
||||
}
|
||||
private string _PdfFileName; // used for finding the procedure's pdf file to merge
|
||||
public string PdfFileName
|
||||
{
|
||||
get { return _PdfFileName; }
|
||||
set { _PdfFileName = value; }
|
||||
}
|
||||
private bool _FirstPageNoPageNum = false;
|
||||
public bool FirstPageNoPageNum
|
||||
{
|
||||
get { return _FirstPageNoPageNum; }
|
||||
set { _FirstPageNoPageNum = value; }
|
||||
}
|
||||
public MergedPdfProc(string title, string pfname)
|
||||
{
|
||||
_Title = title;
|
||||
_PdfFileName = pfname;
|
||||
Title = title;
|
||||
PdfFileName = pfname;
|
||||
}
|
||||
}
|
||||
// this class will manage the data & do subsequent merging of pdf files. It is used if the user
|
||||
@@ -49,25 +29,11 @@ namespace Volian.Print.Library
|
||||
public class MergedPdf
|
||||
{
|
||||
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private List<MergedPdfProc> _mergedPdfs = null; // This list has all procedure pdfs that will be included in the merged file.
|
||||
public List<MergedPdfProc> MergedPdfs
|
||||
{
|
||||
get { return _mergedPdfs; }
|
||||
set { _mergedPdfs = value; }
|
||||
}
|
||||
string _mergedFileName = null; // this is the name to be given the merged file
|
||||
public string MergedFileName
|
||||
{
|
||||
get { return _mergedFileName; }
|
||||
set { _mergedFileName = value; }
|
||||
}
|
||||
private string _folder; // this is folder to create the merged file in
|
||||
public string Folder
|
||||
{
|
||||
get { return _folder; }
|
||||
set { _folder = value; }
|
||||
}
|
||||
private DocVersionInfo _docVersionInfo;
|
||||
|
||||
public List<MergedPdfProc> MergedPdfs { get; set; } = null;
|
||||
public string MergedFileName { get; set; } = null;
|
||||
public string Folder { get; set; }
|
||||
private readonly DocVersionInfo _docVersionInfo;
|
||||
private string _pageof = null;
|
||||
private iTextSharp.text.Font _itextFont = null;
|
||||
private MergedPdfsPageNumCorner _corner;
|
||||
@@ -80,11 +46,11 @@ namespace Volian.Print.Library
|
||||
// the following constructs the class that contains data for merging a group of pdfs.
|
||||
public MergedPdf(string folder, DocVersionInfo dvi)
|
||||
{
|
||||
_folder = folder;
|
||||
Folder = folder;
|
||||
_docVersionInfo = dvi;
|
||||
}
|
||||
// the following merges the procedure pdfs into a single pdf
|
||||
public bool DoTheMerge(Dictionary<string, List<int>> MergedLandscapPages, bool generatePointListFile)
|
||||
public bool DoTheMerge(bool generatePointListFile)
|
||||
{
|
||||
if (MergedPdfs == null)
|
||||
{
|
||||
@@ -93,7 +59,7 @@ namespace Volian.Print.Library
|
||||
}
|
||||
iTextSharp.text.Document doc = new iTextSharp.text.Document();
|
||||
string slashReplace = _docVersionInfo.ActiveFormat.PlantFormat.FormatData.PrintData.SlashReplace ?? "_";
|
||||
MergedFileName = _folder + @"\" + _docVersionInfo.MyFolder.Name.Replace("/", slashReplace).Replace("\\", slashReplace) + ".pdf";
|
||||
MergedFileName = Folder + @"\" + _docVersionInfo.MyFolder.Name.Replace("/", slashReplace).Replace("\\", slashReplace) + ".pdf";
|
||||
MergedFileName = ItemInfo.StripRtfFormatting(MergedFileName);
|
||||
// C2021-063 file name of Alarm Point List file containing Serial Number, Title, and merged Page Number
|
||||
StreamWriter sw = null;
|
||||
@@ -109,12 +75,12 @@ namespace Volian.Print.Library
|
||||
{
|
||||
writer = PdfWriter.GetInstance(doc, new FileStream(MergedFileName, FileMode.Create));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("Could not create");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(MergedFileName + ".");
|
||||
sb.AppendLine($"{MergedFileName}.");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("If it is open, close and retry.");
|
||||
FlexibleMessageBox.Show(sb.ToString(), "Error on CreatePdf", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
@@ -136,7 +102,7 @@ namespace Volian.Print.Library
|
||||
// write Serial Number, Title, and Page Number in the Point List file
|
||||
sw.WriteLine("{0}\t{1}\t{2}", idxSerialNum++, mpp.Title, mergedPageNumber + 1);
|
||||
}
|
||||
string pdffilename = _folder + @"\" + mpp.PdfFileName;
|
||||
string pdffilename = $@"{Folder}\{mpp.PdfFileName}";
|
||||
if (!File.Exists(pdffilename))
|
||||
{
|
||||
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);
|
||||
@@ -154,7 +120,7 @@ namespace Volian.Print.Library
|
||||
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.
|
||||
{
|
||||
reader = new PdfReader(_folder + @"\" + mpp.PdfFileName);
|
||||
reader = new PdfReader($@"{Folder}\{mpp.PdfFileName}");
|
||||
int numPages = reader.NumberOfPages;
|
||||
int currentPageNumber = 0;
|
||||
PdfOutline outline = null;
|
||||
@@ -178,7 +144,7 @@ namespace Volian.Print.Library
|
||||
// if on the first page, add the pdfname & title as part of outline. If on remaining pages, just put out page number.
|
||||
// Later this may need expanded to put sections/steps/etc.
|
||||
if (currentPageNumber == 1)
|
||||
outline = new PdfOutline(canvas.RootOutline, dest, mpp.PdfFileName.Replace(".pdf", "") + " - " + mpp.Title, false);
|
||||
outline = new PdfOutline(canvas.RootOutline, dest, $"{mpp.PdfFileName.Replace(".pdf", "")} - {mpp.Title}", false);
|
||||
else
|
||||
new PdfOutline(outline, dest, "Page " + currentPageNumber.ToString(), false);
|
||||
canvas.AddTemplate(page, 0, 0); // adds the page to the combined pdf
|
||||
@@ -204,17 +170,13 @@ namespace Volian.Print.Library
|
||||
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;
|
||||
MergedPdfsPageNumCorner cnr = _corner; // C2021-047: Allow for setting of Merged Pdf Landscape Page Number Location
|
||||
// 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;
|
||||
cnr = _landcorner; // C2021-047: Allow for setting of Merged Pdf Landscape Page Number Location
|
||||
}
|
||||
Phrase ph = new Phrase();
|
||||
@@ -281,7 +243,7 @@ namespace Volian.Print.Library
|
||||
private bool GetPageOfInfo()
|
||||
{
|
||||
DocVersionConfig dvc = (DocVersionConfig) _docVersionInfo.MyConfig;
|
||||
MergedPdfsPageOf po = dvc.Print_MergedPdfsPageOf;
|
||||
_ = dvc.Print_MergedPdfsPageOf;
|
||||
string tmp = EnumDescConverter.GetEnumDescription((Enum)dvc.Print_MergedPdfsPageOf);
|
||||
if (tmp == "None") return false; // no page number, return false so no page number is put out.
|
||||
|
||||
@@ -297,7 +259,7 @@ namespace Volian.Print.Library
|
||||
famtmp = _docVersionInfo.ActiveFormat.PlantFormat.FormatData.Font.Family;
|
||||
}
|
||||
tmp = dvc.Print_MergedPdfsPageNumFontSize;
|
||||
float? tmpi=0;
|
||||
float? tmpi;
|
||||
if (tmp == null || tmp == "")
|
||||
{
|
||||
// use the default from the format from this working draft
|
||||
|
||||
Reference in New Issue
Block a user