Using New Volian.Print.Library
This commit is contained in:
parent
72e8f937f2
commit
4e85f82557
@ -13,6 +13,7 @@ using LBWordLibrary;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using Volian.Controls.Library;
|
using Volian.Controls.Library;
|
||||||
|
using Volian.Print.Library;
|
||||||
|
|
||||||
namespace PrintMSWord
|
namespace PrintMSWord
|
||||||
{
|
{
|
||||||
@ -90,9 +91,9 @@ namespace PrintMSWord
|
|||||||
}
|
}
|
||||||
public string Print(string pdfFolder, Proms2010Print myProms2010Print, string myMSWordFile,System.Windows.Forms.Form myForm)
|
public string Print(string pdfFolder, Proms2010Print myProms2010Print, string myMSWordFile,System.Windows.Forms.Form myForm)
|
||||||
{
|
{
|
||||||
if(_MyItem is SectionInfo)
|
//if(_MyItem is SectionInfo)
|
||||||
return Print(_MyItem as SectionInfo, pdfFolder, myProms2010Print,myForm);
|
// return Print(_MyItem as SectionInfo, pdfFolder, myProms2010Print,myForm);
|
||||||
else if (_MyItem is ProcedureInfo)
|
if (_MyItem is ProcedureInfo)
|
||||||
return Print(_MyItem as ProcedureInfo, pdfFolder, myProms2010Print,myForm);
|
return Print(_MyItem as ProcedureInfo, pdfFolder, myProms2010Print,myForm);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -107,78 +108,78 @@ namespace PrintMSWord
|
|||||||
}
|
}
|
||||||
return MSWordFile;
|
return MSWordFile;
|
||||||
}
|
}
|
||||||
private string Print(SectionInfo mySection, string pdfFolder, Proms2010Print myProms2010Print, System.Windows.Forms.Form myForm)
|
//private string Print(SectionInfo mySection, string pdfFolder, Proms2010Print myProms2010Print, System.Windows.Forms.Form myForm)
|
||||||
{
|
//{
|
||||||
// Create an output file name
|
// // Create an output file name
|
||||||
string outputFileName = pdfFolder + "\\" + CreateFileName(mySection.MyProcedure.DisplayNumber, mySection.DisplayNumber, mySection.DisplayText);
|
// string outputFileName = pdfFolder + "\\" + CreateFileName(mySection.MyProcedure.DisplayNumber, mySection.DisplayNumber, mySection.DisplayText);
|
||||||
//Console.WriteLine("Section {0}", outputFileName);
|
// //Console.WriteLine("Section {0}", outputFileName);
|
||||||
Proms2010Procedure proc = myProms2010Print.GetProcedure(mySection.MyProcedure);
|
// Proms2010Procedure proc = myProms2010Print.GetProcedure(mySection.MyProcedure);
|
||||||
Proms2010Section sect = proc == null ? null : proc.GetSection(mySection);
|
// Proms2010Section sect = proc == null ? null : proc.GetSection(mySection);
|
||||||
// Create an MSWord Pdf
|
// // Create an MSWord Pdf
|
||||||
// Setup a pdf Document for printing
|
// // Setup a pdf Document for printing
|
||||||
PdfContentByte cb = OpenDoc(outputFileName);
|
// PdfContentByte cb = OpenDoc(outputFileName);
|
||||||
// Create Layers
|
// // Create Layers
|
||||||
CreateLayers(cb);
|
// CreateLayers(cb);
|
||||||
// Setup pdfPageEventHelper for the particular Section
|
// // Setup pdfPageEventHelper for the particular Section
|
||||||
// Try to grab a 16-bit version of the output as a background
|
// // Try to grab a 16-bit version of the output as a background
|
||||||
string procedureFileName = myProms2010Print.PROMS16_Folder + "\\" + CreateFileName(mySection.MyProcedure.DisplayNumber);
|
// string procedureFileName = myProms2010Print.PROMS16_Folder + "\\" + CreateFileName(mySection.MyProcedure.DisplayNumber);
|
||||||
FileInfo VEPromsFile = new FileInfo(procedureFileName);
|
// FileInfo VEPromsFile = new FileInfo(procedureFileName);
|
||||||
PdfReader reader16 = VEPromsFile.Exists ? new PdfReader(procedureFileName) : null;
|
// PdfReader reader16 = VEPromsFile.Exists ? new PdfReader(procedureFileName) : null;
|
||||||
// Loop through MSWord Pages
|
// // Loop through MSWord Pages
|
||||||
FormatInfo activeFormat = mySection.ActiveFormat;
|
// FormatInfo activeFormat = mySection.ActiveFormat;
|
||||||
DocStyle docStyle = GetDocStyle(activeFormat, (mySection.MyContent.Type ?? 10000));
|
// DocStyle docStyle = GetDocStyle(activeFormat, (mySection.MyContent.Type ?? 10000));
|
||||||
Svg mySvg = BuildSvg(mySection,activeFormat,docStyle);
|
// Svg mySvg = BuildSvg(mySection,activeFormat,docStyle);
|
||||||
cb.PdfWriter.PageEvent = new SvgPageHelper(mySvg,_PagelistLayer,_WatermarkLayer);
|
// cb.PdfWriter.PageEvent = new SvgPageHelper(mySvg,_PagelistLayer,_WatermarkLayer);
|
||||||
string myMSWordFile = BuildMSWordPDF(mySection,myForm);
|
// string myMSWordFile = BuildMSWordPDF(mySection,myForm);
|
||||||
PdfReader readerWord = myMSWordFile != null ? new PdfReader(myMSWordFile) : null;
|
// PdfReader readerWord = myMSWordFile != null ? new PdfReader(myMSWordFile) : null;
|
||||||
for (int ii = 0; ii < sect.PageCount; ii++)
|
// for (int ii = 0; ii < sect.PageCount; ii++)
|
||||||
{
|
// {
|
||||||
int pageNumber = 1 + ii + sect.StartingPage;
|
// int pageNumber = 1 + ii + sect.StartingPage;
|
||||||
cb.PdfDocument.NewPage();
|
// cb.PdfDocument.NewPage();
|
||||||
PdfImportedPage bgPage = cb.PdfWriter.GetImportedPage(reader16, pageNumber);
|
// PdfImportedPage bgPage = cb.PdfWriter.GetImportedPage(reader16, pageNumber);
|
||||||
AddImportedPageToLayer(cb.PdfWriter.DirectContentUnder, _BackgroundLayer, bgPage, 12, -9.7F);
|
// AddImportedPageToLayer(cb.PdfWriter.DirectContentUnder, _BackgroundLayer, bgPage, 12, -9.7F);
|
||||||
if (readerWord != null)
|
// if (readerWord != null)
|
||||||
{
|
// {
|
||||||
PdfImportedPage fgPage = cb.PdfWriter.GetImportedPage(readerWord, ii + 1);
|
// PdfImportedPage fgPage = cb.PdfWriter.GetImportedPage(readerWord, ii + 1);
|
||||||
AddImportedPageToLayer(cb.PdfWriter.DirectContentUnder, _MSWordLayer, fgPage, 0, 0);
|
// AddImportedPageToLayer(cb.PdfWriter.DirectContentUnder, _MSWordLayer, fgPage, 0, 0);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
CloseDocument(cb, outputFileName);
|
// CloseDocument(cb, outputFileName);
|
||||||
// Return the fileName;
|
// // Return the fileName;
|
||||||
return outputFileName;
|
// return outputFileName;
|
||||||
}
|
//}
|
||||||
private int _PLPage = 0;
|
//private int _PLPage = 0;
|
||||||
private int _PLOf = 0;
|
//private int _PLOf = 0;
|
||||||
private List<string> _MissingTokens = new List<string>();
|
//private List<string> _MissingTokens = new List<string>();
|
||||||
private string ReplacePageListToken(Match match)
|
//private string ReplacePageListToken(Match match)
|
||||||
{
|
//{
|
||||||
switch (match.Value)
|
// switch (match.Value)
|
||||||
{
|
// {
|
||||||
case "{PAGE}": // Current Page Number
|
// case "{PAGE}": // Current Page Number
|
||||||
string retval = _PLPage.ToString();
|
// string retval = _PLPage.ToString();
|
||||||
_PLPage++; // Increment Page Number
|
// _PLPage++; // Increment Page Number
|
||||||
return retval;
|
// return retval;
|
||||||
case "{OF}": // Total Page Count for this section
|
// case "{OF}": // Total Page Count for this section
|
||||||
return _PLOf.ToString();
|
// return _PLOf.ToString();
|
||||||
case "{REVDATE}": // Revision Date
|
// case "{REVDATE}": // Revision Date
|
||||||
return _RevDate;
|
// return _RevDate;
|
||||||
case "{REV}": // Revision Number
|
// case "{REV}": // Revision Number
|
||||||
return _Rev;
|
// return _Rev;
|
||||||
}
|
// }
|
||||||
if (!_MissingTokens.Contains(match.Value))
|
// if (!_MissingTokens.Contains(match.Value))
|
||||||
{
|
// {
|
||||||
_MissingTokens.Add(match.Value);
|
// _MissingTokens.Add(match.Value);
|
||||||
Console.WriteLine("\t\t\t\tcase \"{0}\": // Unhandled Token\r\n\t\t\t\t\treturn \"\";", match.Value);
|
// Console.WriteLine("\t\t\t\tcase \"{0}\": // Unhandled Token\r\n\t\t\t\t\treturn \"\";", match.Value);
|
||||||
}
|
// }
|
||||||
return "";
|
// return "";
|
||||||
}
|
//}
|
||||||
//private Regex regexReplaceTokens = new Regex(@"{[^{}]}");
|
////private Regex regexReplaceTokens = new Regex(@"{[^{}]}");
|
||||||
private string mySvg_ProcessText(object sender, SvgProcessTextArgs args)
|
//private string mySvg_ProcessText(object sender, SvgProcessTextArgs args)
|
||||||
{
|
//{
|
||||||
if (!args.MyText.Contains("{"))
|
// if (!args.MyText.Contains("{"))
|
||||||
return args.MyText;
|
// return args.MyText;
|
||||||
return regexFindToken.Replace(args.MyText, new MatchEvaluator(ReplacePageListToken));
|
// return regexFindToken.Replace(args.MyText, new MatchEvaluator(ReplacePageListToken));
|
||||||
}
|
//}
|
||||||
private static void AddImportedPageToLayer(PdfContentByte cb, PdfLayer layer, PdfImportedPage page, float xOff, float yOff)
|
private static void AddImportedPageToLayer(PdfContentByte cb, PdfLayer layer, PdfImportedPage page, float xOff, float yOff)
|
||||||
{
|
{
|
||||||
cb.BeginLayer(layer);
|
cb.BeginLayer(layer);
|
||||||
@ -232,6 +233,7 @@ namespace PrintMSWord
|
|||||||
return Regex.Replace(name, "[ .,]", "_") + ".pdf";
|
return Regex.Replace(name, "[ .,]", "_") + ".pdf";
|
||||||
}
|
}
|
||||||
int _StepPageNumber = 0;
|
int _StepPageNumber = 0;
|
||||||
|
private VlnSvgPageHelper _MyHelper = null;
|
||||||
private string Print(ProcedureInfo myProcedure, string pdfFolder, Proms2010Print myProms2010Print, System.Windows.Forms.Form myForm)
|
private string Print(ProcedureInfo myProcedure, string pdfFolder, Proms2010Print myProms2010Print, System.Windows.Forms.Form myForm)
|
||||||
{
|
{
|
||||||
OnStatusChanged("Print " + myProcedure.DisplayNumber, PromsPrinterStatusType.Start);
|
OnStatusChanged("Print " + myProcedure.DisplayNumber, PromsPrinterStatusType.Start);
|
||||||
@ -252,25 +254,27 @@ namespace PrintMSWord
|
|||||||
PdfReader reader16 = VEPromsFile.Exists ? new PdfReader(procedureFileName) : null;
|
PdfReader reader16 = VEPromsFile.Exists ? new PdfReader(procedureFileName) : null;
|
||||||
OnStatusChanged("OpenReader16", PromsPrinterStatusType.Open16);
|
OnStatusChanged("OpenReader16", PromsPrinterStatusType.Open16);
|
||||||
// Loop through MSWord Pages
|
// Loop through MSWord Pages
|
||||||
SvgPageHelper myHelper = null;
|
|
||||||
OnStatusChanged("Before NewPage", PromsPrinterStatusType.Before);
|
OnStatusChanged("Before NewPage", PromsPrinterStatusType.Before);
|
||||||
cb.PdfDocument.NewPage();
|
cb.PdfDocument.NewPage();
|
||||||
OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage);
|
OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage);
|
||||||
foreach (SectionInfo mySection in myProcedure.Sections)
|
foreach (SectionInfo mySection in myProcedure.Sections)
|
||||||
{
|
{
|
||||||
OnStatusChanged("Before BuildSvg", PromsPrinterStatusType.Before);
|
OnStatusChanged("Before BuildSvg", PromsPrinterStatusType.Before);
|
||||||
FormatInfo activeFormat = mySection.ActiveFormat;
|
//Svg mySvg = BuildSvg(mySection,activeFormat,docStyle);
|
||||||
DocStyle docStyle = GetDocStyle(activeFormat, (mySection.MyContent.Type ?? 10000));
|
|
||||||
Svg mySvg = BuildSvg(mySection,activeFormat,docStyle);
|
|
||||||
OnStatusChanged("After BuildSvg", PromsPrinterStatusType.BuildSVG);
|
OnStatusChanged("After BuildSvg", PromsPrinterStatusType.BuildSVG);
|
||||||
if (myHelper == null)
|
if (_MyHelper == null)
|
||||||
{
|
{
|
||||||
cb.PdfWriter.PageEvent = myHelper = new SvgPageHelper(mySvg, _PagelistLayer, _WatermarkLayer);
|
cb.PdfWriter.PageEvent = _MyHelper = new VlnSvgPageHelper(mySection);
|
||||||
|
_MyHelper.WatermarkLayer = _WatermarkLayer;
|
||||||
|
_MyHelper.PageListLayer = _PagelistLayer;
|
||||||
|
_MyHelper.Rev = _Rev;
|
||||||
|
_MyHelper.RevDate = _RevDate;
|
||||||
|
_MyHelper.Watermark = _Watermark;
|
||||||
OnStatusChanged("After Set PageEvent", PromsPrinterStatusType.SetPageEvent);
|
OnStatusChanged("After Set PageEvent", PromsPrinterStatusType.SetPageEvent);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myHelper.MySvg = mySvg;
|
_MyHelper.MySection = mySection;
|
||||||
OnStatusChanged("After Set Svg", PromsPrinterStatusType.SetSVG);
|
OnStatusChanged("After Set Svg", PromsPrinterStatusType.SetSVG);
|
||||||
}
|
}
|
||||||
string myMSWordFile = BuildMSWordPDF(mySection, myForm);
|
string myMSWordFile = BuildMSWordPDF(mySection, myForm);
|
||||||
@ -279,7 +283,7 @@ namespace PrintMSWord
|
|||||||
OnStatusChanged("Open MSWord", PromsPrinterStatusType.OpenMSWord);
|
OnStatusChanged("Open MSWord", PromsPrinterStatusType.OpenMSWord);
|
||||||
Proms2010Section sect = proc == null ? null : proc.GetSection(mySection);
|
Proms2010Section sect = proc == null ? null : proc.GetSection(mySection);
|
||||||
OnStatusChanged("Get Section", PromsPrinterStatusType.GetSection);
|
OnStatusChanged("Get Section", PromsPrinterStatusType.GetSection);
|
||||||
SetupPageNumbering(docStyle, sect.PageCount);
|
SetupPageNumbering(mySection.MyDocStyle, sect.PageCount);
|
||||||
for (int ii = 0; ii < sect.PageCount; ii++)
|
for (int ii = 0; ii < sect.PageCount; ii++)
|
||||||
{
|
{
|
||||||
int pageNumber = 1 + ii + sect.StartingPage;
|
int pageNumber = 1 + ii + sect.StartingPage;
|
||||||
@ -306,16 +310,25 @@ namespace PrintMSWord
|
|||||||
cb.PdfDocument.NewPage();
|
cb.PdfDocument.NewPage();
|
||||||
OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage);
|
OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage);
|
||||||
}
|
}
|
||||||
SavePageNumbering(docStyle);
|
SavePageNumbering(mySection.MyDocStyle);
|
||||||
}
|
}
|
||||||
CloseDocument(cb, outputFileName);
|
CloseDocument(cb, outputFileName);
|
||||||
// Return the fileName;
|
// Return the fileName;
|
||||||
return outputFileName;
|
return outputFileName;
|
||||||
}
|
}
|
||||||
|
private int PLPage
|
||||||
|
{
|
||||||
|
get { return _MyHelper.CurrentPageNumber; }
|
||||||
|
set { if (_MyHelper != null) _MyHelper.CurrentPageNumber = value; }
|
||||||
|
}
|
||||||
|
private int PLOf
|
||||||
|
{
|
||||||
|
get { return _MyHelper.CurrentPageOf; }
|
||||||
|
set { if(_MyHelper != null) _MyHelper.CurrentPageOf = value; }
|
||||||
|
}
|
||||||
private void SetupPageCount(ProcedureInfo myProcedure, Proms2010Procedure proc)
|
private void SetupPageCount(ProcedureInfo myProcedure, Proms2010Procedure proc)
|
||||||
{
|
{
|
||||||
_PLPage = 1;
|
PLPage = 1;
|
||||||
_PageNumber = new Dictionary<string, int>();
|
_PageNumber = new Dictionary<string, int>();
|
||||||
_PageNumber.Add("Procedure Steps", 1);
|
_PageNumber.Add("Procedure Steps", 1);
|
||||||
_PageCount = new Dictionary<string, int>();
|
_PageCount = new Dictionary<string, int>();
|
||||||
@ -330,7 +343,7 @@ namespace PrintMSWord
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
FormatInfo activeFormat = mySection.ActiveFormat;
|
FormatInfo activeFormat = mySection.ActiveFormat;
|
||||||
DocStyle docStyle = GetDocStyle(activeFormat, (mySection.MyContent.Type ?? 10000));
|
DocStyle docStyle = mySection.MyDocStyle;// GetDocStyle(activeFormat, (mySection.MyContent.Type ?? 10000));
|
||||||
int pageCount = Convert.ToInt32(Math.Ceiling(mySection.MyContent.MyEntry.MyDocument.DocumentConfig.Printing_Length));
|
int pageCount = Convert.ToInt32(Math.Ceiling(mySection.MyContent.MyEntry.MyDocument.DocumentConfig.Printing_Length));
|
||||||
switch (docStyle.IsStepSection ? E_NumberingSequence.WithSteps : docStyle.NumberingSequence ?? E_NumberingSequence.WithSteps)
|
switch (docStyle.IsStepSection ? E_NumberingSequence.WithSteps : docStyle.NumberingSequence ?? E_NumberingSequence.WithSteps)
|
||||||
{
|
{
|
||||||
@ -360,7 +373,7 @@ namespace PrintMSWord
|
|||||||
switch (docStyle.IsStepSection ? E_NumberingSequence.WithSteps : docStyle.NumberingSequence ?? E_NumberingSequence.WithSteps)
|
switch (docStyle.IsStepSection ? E_NumberingSequence.WithSteps : docStyle.NumberingSequence ?? E_NumberingSequence.WithSteps)
|
||||||
{
|
{
|
||||||
case E_NumberingSequence.WithSteps:
|
case E_NumberingSequence.WithSteps:
|
||||||
_PageNumber["Procedure Steps"] = _PLPage;
|
_PageNumber["Procedure Steps"] = PLPage;
|
||||||
break;
|
break;
|
||||||
case E_NumberingSequence.NoPageNum:
|
case E_NumberingSequence.NoPageNum:
|
||||||
case E_NumberingSequence.WithinEachDocStyle:
|
case E_NumberingSequence.WithinEachDocStyle:
|
||||||
@ -384,8 +397,8 @@ namespace PrintMSWord
|
|||||||
switch (docStyle.IsStepSection ? E_NumberingSequence.WithSteps : docStyle.NumberingSequence ?? E_NumberingSequence.WithSteps)
|
switch (docStyle.IsStepSection ? E_NumberingSequence.WithSteps : docStyle.NumberingSequence ?? E_NumberingSequence.WithSteps)
|
||||||
{
|
{
|
||||||
case E_NumberingSequence.WithSteps:
|
case E_NumberingSequence.WithSteps:
|
||||||
_PLPage = _PageNumber["Procedure Steps"];
|
PLPage = _PageNumber["Procedure Steps"];
|
||||||
_PLOf = _PageCount["Procedure Steps"];
|
PLOf = _PageCount["Procedure Steps"];
|
||||||
break;
|
break;
|
||||||
case E_NumberingSequence.NoPageNum:
|
case E_NumberingSequence.NoPageNum:
|
||||||
case E_NumberingSequence.WithinEachDocStyle:
|
case E_NumberingSequence.WithinEachDocStyle:
|
||||||
@ -398,199 +411,199 @@ namespace PrintMSWord
|
|||||||
case E_NumberingSequence.Like6_ButDoesntNeedSubsection:
|
case E_NumberingSequence.Like6_ButDoesntNeedSubsection:
|
||||||
case E_NumberingSequence.Like6_ButDoesntNeedSubsection1:
|
case E_NumberingSequence.Like6_ButDoesntNeedSubsection1:
|
||||||
default:
|
default:
|
||||||
_PLOf = pageCount;
|
PLOf = pageCount;
|
||||||
_PLPage = 1;
|
PLPage = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Console.WriteLine("'{0}','{1}',{2}",docStyle.Name, docStyle.NumberingSequence,_PLPage);
|
Console.WriteLine("'{0}','{1}',{2}",docStyle.Name, docStyle.NumberingSequence,PLPage);
|
||||||
}
|
|
||||||
private Svg BuildSvg(SectionInfo section,FormatInfo activeFormat,DocStyle docStyle)
|
|
||||||
{
|
|
||||||
Svg mySvg = null;
|
|
||||||
mySvg = SvgSerializer<Svg>.StringDeserialize(BuildMyText(activeFormat));
|
|
||||||
mySvg.ViewBox.Height = 1100;
|
|
||||||
mySvg.ViewBox.Width = 850;
|
|
||||||
mySvg.Height = new SvgMeasurement(11, E_MeasurementUnits.IN);
|
|
||||||
mySvg.Width = new SvgMeasurement(8.5F, E_MeasurementUnits.IN);
|
|
||||||
mySvg.LeftMargin = (float)docStyle.Layout.LeftMargin;
|
|
||||||
mySvg.TopMargin = 9.6F;
|
|
||||||
PageStyle pageStyle = docStyle.pagestyle;
|
|
||||||
AddPageListItems(mySvg, pageStyle, section);
|
|
||||||
//DocStyle docStyle = GetDocStyle(activeFormat, (section.MyContent.Type ?? 10000));
|
|
||||||
mySvg.ProcessText += new SvgProcessTextEvent(mySvg_ProcessText);
|
|
||||||
return mySvg;
|
|
||||||
}
|
}
|
||||||
|
//private Svg BuildSvg(SectionInfo section,FormatInfo activeFormat,DocStyle docStyle)
|
||||||
|
//{
|
||||||
|
// Svg mySvg = null;
|
||||||
|
// mySvg = SvgSerializer<Svg>.StringDeserialize(BuildMyText(activeFormat));
|
||||||
|
// mySvg.ViewBox.Height = 1100;
|
||||||
|
// mySvg.ViewBox.Width = 850;
|
||||||
|
// mySvg.Height = new SvgMeasurement(11, E_MeasurementUnits.IN);
|
||||||
|
// mySvg.Width = new SvgMeasurement(8.5F, E_MeasurementUnits.IN);
|
||||||
|
// mySvg.LeftMargin = (float)docStyle.Layout.LeftMargin;
|
||||||
|
// mySvg.TopMargin = 9.6F;
|
||||||
|
// PageStyle pageStyle = docStyle.pagestyle;
|
||||||
|
// AddPageListItems(mySvg, pageStyle, section);
|
||||||
|
// //DocStyle docStyle = GetDocStyle(activeFormat, (section.MyContent.Type ?? 10000));
|
||||||
|
// mySvg.ProcessText += new SvgProcessTextEvent(mySvg_ProcessText);
|
||||||
|
// return mySvg;
|
||||||
|
//}
|
||||||
private static Regex regexTextOnly = new Regex(@"^[^{}]*$");
|
private static Regex regexTextOnly = new Regex(@"^[^{}]*$");
|
||||||
private static Regex regexJustTokens = new Regex(@"^{([^{}\?]*}{)*[^{}\?]*}$");
|
//private static Regex regexJustTokens = new Regex(@"^{([^{}\?]*}{)*[^{}\?]*}$");
|
||||||
private static Regex regexConditional = new Regex(@"^{.*\?.*}$");
|
private static Regex regexConditional = new Regex(@"^{.*\?.*}$");
|
||||||
private static Regex regexFindToken = new Regex("{[^{}]*}");
|
//private static Regex regexFindToken = new Regex("{[^{}]*}");
|
||||||
private void AddPageListItems(Svg mySvg, PageStyle pageStyle, SectionInfo section)
|
//private void AddPageListItems(Svg mySvg, PageStyle pageStyle, SectionInfo section)
|
||||||
{
|
//{
|
||||||
SvgGroup svgGroup = new SvgGroup();
|
// SvgGroup svgGroup = new SvgGroup();
|
||||||
foreach (PageItem pageItem in pageStyle.PageItems)
|
// foreach (PageItem pageItem in pageStyle.PageItems)
|
||||||
{
|
// {
|
||||||
if (regexJustTokens.IsMatch(pageItem.Token))
|
// if (regexJustTokens.IsMatch(pageItem.Token))
|
||||||
{
|
// {
|
||||||
MatchCollection matches = regexFindToken.Matches(pageItem.Token);
|
// MatchCollection matches = regexFindToken.Matches(pageItem.Token);
|
||||||
foreach (Match match in matches)
|
// foreach (Match match in matches)
|
||||||
{
|
// {
|
||||||
string token = match.Value;
|
// string token = match.Value;
|
||||||
switch (match.Value)
|
// switch (match.Value)
|
||||||
{
|
// {
|
||||||
case "{HEADER1}":
|
// case "{HEADER1}":
|
||||||
case "{HEADER2}":
|
// case "{HEADER2}":
|
||||||
case "{HEADER3}":
|
// case "{HEADER3}":
|
||||||
case "{HEADER4}":
|
// case "{HEADER4}":
|
||||||
case "{HEADER5}":
|
// case "{HEADER5}":
|
||||||
case "{BOX1}":
|
// case "{BOX1}":
|
||||||
case "{BOX2}":
|
// case "{BOX2}":
|
||||||
case "{BOX3}":
|
// case "{BOX3}":
|
||||||
case "{BOX4}":
|
// case "{BOX4}":
|
||||||
case "{BOX5}":
|
// case "{BOX5}":
|
||||||
case "{BOX6}":
|
// case "{BOX6}":
|
||||||
case "{BOX7}":
|
// case "{BOX7}":
|
||||||
case "{BOX8}":
|
// case "{BOX8}":
|
||||||
svgGroup.Add(PageItemToSvgUse(pageItem, FirstAndLast(token)));
|
// svgGroup.Add(PageItemToSvgUse(pageItem, FirstAndLast(token)));
|
||||||
break;
|
// break;
|
||||||
case "{DRAFTPAGE}":
|
// case "{DRAFTPAGE}":
|
||||||
case "{REFERENCEPAGE}":
|
// case "{REFERENCEPAGE}":
|
||||||
case "{MASTERPAGE}":
|
// case "{MASTERPAGE}":
|
||||||
case "{SAMPLEPAGE}":
|
// case "{SAMPLEPAGE}":
|
||||||
mySvg.SetValidWaterMark(token, _Watermark);
|
// mySvg.SetValidWaterMark(token, _Watermark);
|
||||||
break;
|
// break;
|
||||||
case "{PROCTITLE}":
|
// case "{PROCTITLE}":
|
||||||
SplitTitle(svgGroup, pageItem, section.MyProcedure.DisplayText, (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength);
|
// SplitTitle(svgGroup, pageItem, section.MyProcedure.DisplayText, (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength);
|
||||||
break;
|
// break;
|
||||||
case "{EOPNUM}":
|
// case "{EOPNUM}":
|
||||||
svgGroup.Add(PageItemToSvgText(pageItem, section.MyProcedure.DisplayNumber));
|
// svgGroup.Add(PageItemToSvgText(pageItem, section.MyProcedure.DisplayNumber));
|
||||||
break;
|
// break;
|
||||||
case "{SECTIONLEVELTITLE}":
|
// case "{SECTIONLEVELTITLE}":
|
||||||
SplitTitle(svgGroup, pageItem, section.DisplayText, section.ActiveFormat.PlantFormat.FormatData.SectData.SectionTitleLength);
|
// SplitTitle(svgGroup, pageItem, section.DisplayText, section.ActiveFormat.PlantFormat.FormatData.SectData.SectionTitleLength);
|
||||||
svgGroup.Add(PageItemToSvgText(pageItem, section.DisplayText));
|
// svgGroup.Add(PageItemToSvgText(pageItem, section.DisplayText));
|
||||||
break;
|
// break;
|
||||||
case "{SECTIONLEVELNUMBER}":
|
// case "{SECTIONLEVELNUMBER}":
|
||||||
svgGroup.Add(PageItemToSvgText(pageItem, section.DisplayNumber));
|
// svgGroup.Add(PageItemToSvgText(pageItem, section.DisplayNumber));
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
Console.WriteLine("Token not processed {0}", token);
|
// Console.WriteLine("Token not processed {0}", token);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
svgGroup.Add(PageItemToSvgText(pageItem,pageItem.Token));
|
// svgGroup.Add(PageItemToSvgText(pageItem,pageItem.Token));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
mySvg.Add(svgGroup);
|
// mySvg.Add(svgGroup);
|
||||||
}
|
//}
|
||||||
|
|
||||||
private string FirstAndLast(string token)
|
//private string FirstAndLast(string token)
|
||||||
{
|
//{
|
||||||
// strip the curly braces and return the first and last character
|
// // strip the curly braces and return the first and last character
|
||||||
// For example Header1 becomes H1 and Box2 becomes B2
|
// // For example Header1 becomes H1 and Box2 becomes B2
|
||||||
return token.Substring(1, 1) + token.Substring(token.Length - 2, 1);
|
// return token.Substring(1, 1) + token.Substring(token.Length - 2, 1);
|
||||||
}
|
//}
|
||||||
private void SplitTitle(SvgGroup svgGroup, PageItem pageItem, string title, int? len)
|
//private void SplitTitle(SvgGroup svgGroup, PageItem pageItem, string title, int? len)
|
||||||
{
|
//{
|
||||||
// TODO: need to calculate len in either points or inches and use the font from the pageItem to determine the number of characters
|
// // TODO: need to calculate len in either points or inches and use the font from the pageItem to determine the number of characters
|
||||||
if(len == null || title.Length < len)
|
// if(len == null || title.Length < len)
|
||||||
{
|
// {
|
||||||
svgGroup.Add(PageItemToSvgText(pageItem, title));
|
// svgGroup.Add(PageItemToSvgText(pageItem, title));
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
// Otherwise determine how many line to split the text into
|
// // Otherwise determine how many line to split the text into
|
||||||
List<string> titleLines = SplitText(title,(int)len);
|
// List<string> titleLines = SplitText(title,(int)len);
|
||||||
// Move up 6 Points per line to find the starting point
|
// // Move up 6 Points per line to find the starting point
|
||||||
float yOffset = -6 * (titleLines.Count-1);
|
// float yOffset = -6 * (titleLines.Count-1);
|
||||||
foreach (string line in titleLines)
|
// foreach (string line in titleLines)
|
||||||
{
|
// {
|
||||||
svgGroup.Add(PageItemToSvgText(pageItem, line, yOffset));
|
// svgGroup.Add(PageItemToSvgText(pageItem, line, yOffset));
|
||||||
yOffset += 12;
|
// yOffset += 12;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
private List<string> SplitText(string title, int len)
|
//private List<string> SplitText(string title, int len)
|
||||||
{
|
//{
|
||||||
List<string> retval = new List<string>();
|
// List<string> retval = new List<string>();
|
||||||
int strlen = title.Length;
|
// int strlen = title.Length;
|
||||||
int start = 0;
|
// int start = 0;
|
||||||
while ((strlen - start) > len)
|
// while ((strlen - start) > len)
|
||||||
{
|
// {
|
||||||
int width = FindWidth(title, start, len);
|
// int width = FindWidth(title, start, len);
|
||||||
retval.Add(title.Substring(start, width));
|
// retval.Add(title.Substring(start, width));
|
||||||
start += width;
|
// start += width;
|
||||||
while (title[start] == ' ') start++;
|
// while (title[start] == ' ') start++;
|
||||||
}
|
// }
|
||||||
if (strlen - start > 0)
|
// if (strlen - start > 0)
|
||||||
retval.Add(title.Substring(start, strlen - start));
|
// retval.Add(title.Substring(start, strlen - start));
|
||||||
return retval;
|
// return retval;
|
||||||
}
|
//}
|
||||||
|
|
||||||
private int FindWidth(string title, int start, int len)
|
//private int FindWidth(string title, int start, int len)
|
||||||
{
|
//{
|
||||||
for (int ii = start + len; ii > start; ii--)
|
// for (int ii = start + len; ii > start; ii--)
|
||||||
{
|
// {
|
||||||
if (title[ii] == ' ')
|
// if (title[ii] == ' ')
|
||||||
{
|
// {
|
||||||
while (title[ii] == ' ') ii--;
|
// while (title[ii] == ' ') ii--;
|
||||||
if (ii > start)
|
// if (ii > start)
|
||||||
return 2 + ii - start;
|
// return 2 + ii - start;
|
||||||
return len;
|
// return len;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return len;
|
// return len;
|
||||||
}
|
//}
|
||||||
|
|
||||||
private string BuildMyText(FormatInfo activeFormat)
|
//private string BuildMyText(FormatInfo activeFormat)
|
||||||
{
|
//{
|
||||||
string sGenMac = activeFormat.GenMac;
|
// string sGenMac = activeFormat.GenMac;
|
||||||
if (!sGenMac.Contains("xmlns"))
|
// if (!sGenMac.Contains("xmlns"))
|
||||||
sGenMac = sGenMac.Replace("<svg ", "<svg xmlns='http://www.w3.org/2000/svg' ");
|
// sGenMac = sGenMac.Replace("<svg ", "<svg xmlns='http://www.w3.org/2000/svg' ");
|
||||||
XmlDocument xDocGenMac = new XmlDocument();
|
// XmlDocument xDocGenMac = new XmlDocument();
|
||||||
xDocGenMac.LoadXml(sGenMac); // Add xmlns if necessary
|
// xDocGenMac.LoadXml(sGenMac); // Add xmlns if necessary
|
||||||
Svg mySvg = new Svg();
|
// Svg mySvg = new Svg();
|
||||||
SvgDefine def = new SvgDefine();
|
// SvgDefine def = new SvgDefine();
|
||||||
mySvg.Add(def);
|
// mySvg.Add(def);
|
||||||
def.ID = "GenMac Templates";
|
// def.ID = "GenMac Templates";
|
||||||
string str = SvgSerializer<Svg>.StringSerialize(mySvg);
|
// string str = SvgSerializer<Svg>.StringSerialize(mySvg);
|
||||||
XmlDocument xDocPrintout = new XmlDocument();
|
// XmlDocument xDocPrintout = new XmlDocument();
|
||||||
xDocPrintout.LoadXml(str);
|
// xDocPrintout.LoadXml(str);
|
||||||
XmlNode xn = xDocPrintout.DocumentElement.ChildNodes[0];
|
// XmlNode xn = xDocPrintout.DocumentElement.ChildNodes[0];
|
||||||
xn.AppendChild(xDocPrintout.ImportNode(xDocGenMac.DocumentElement, true));
|
// xn.AppendChild(xDocPrintout.ImportNode(xDocGenMac.DocumentElement, true));
|
||||||
return xDocPrintout.OuterXml;
|
// return xDocPrintout.OuterXml;
|
||||||
}
|
//}
|
||||||
private DocStyle GetDocStyle(FormatInfo formatInfo, int type)
|
//private DocStyle GetDocStyle(FormatInfo formatInfo, int type)
|
||||||
{
|
//{
|
||||||
int i = type - 10000;
|
// int i = type - 10000;
|
||||||
return formatInfo.PlantFormat.DocStyles.DocStyleList[i];
|
// return formatInfo.PlantFormat.DocStyles.DocStyleList[i];
|
||||||
}
|
//}
|
||||||
private SvgPart PageItemToSvgUse(PageItem pageItem, string templateName)
|
//private SvgPart PageItemToSvgUse(PageItem pageItem, string templateName)
|
||||||
{
|
//{
|
||||||
SvgUse svgUse = new SvgUse();
|
// SvgUse svgUse = new SvgUse();
|
||||||
svgUse.UseID = templateName;
|
// svgUse.UseID = templateName;
|
||||||
svgUse.X = new SvgMeasurement((float)(pageItem.Col ?? 0), E_MeasurementUnits.PT);
|
// svgUse.X = new SvgMeasurement((float)(pageItem.Col ?? 0), E_MeasurementUnits.PT);
|
||||||
svgUse.Y = new SvgMeasurement((float)(pageItem.Row ?? 0), E_MeasurementUnits.PT);
|
// svgUse.Y = new SvgMeasurement((float)(pageItem.Row ?? 0), E_MeasurementUnits.PT);
|
||||||
return svgUse;
|
// return svgUse;
|
||||||
}
|
//}
|
||||||
private static SvgText PageItemToSvgText(PageItem pageItem, string text)
|
//private static SvgText PageItemToSvgText(PageItem pageItem, string text)
|
||||||
{
|
//{
|
||||||
SvgText svgText = new SvgText();
|
// SvgText svgText = new SvgText();
|
||||||
svgText.Text = text;
|
// svgText.Text = text;
|
||||||
E_Justify justify = pageItem.Justify ?? E_Justify.PSLeft;
|
// E_Justify justify = pageItem.Justify ?? E_Justify.PSLeft;
|
||||||
if ((justify & E_Justify.PSLeft) == E_Justify.PSLeft)
|
// if ((justify & E_Justify.PSLeft) == E_Justify.PSLeft)
|
||||||
svgText.Justify = SvgJustify.Left;
|
// svgText.Justify = SvgJustify.Left;
|
||||||
else if ((justify & E_Justify.PSRight) == E_Justify.PSRight)
|
// else if ((justify & E_Justify.PSRight) == E_Justify.PSRight)
|
||||||
svgText.Justify = SvgJustify.Right;
|
// svgText.Justify = SvgJustify.Right;
|
||||||
else
|
// else
|
||||||
svgText.Justify = SvgJustify.Center;
|
// svgText.Justify = SvgJustify.Center;
|
||||||
svgText.Font = pageItem.Font.WindowsFont;
|
// svgText.Font = pageItem.Font.WindowsFont;
|
||||||
svgText.X = new SvgMeasurement((float)(pageItem.Col ?? 0), E_MeasurementUnits.PT);
|
// svgText.X = new SvgMeasurement((float)(pageItem.Col ?? 0), E_MeasurementUnits.PT);
|
||||||
svgText.Y = new SvgMeasurement((float)(pageItem.Row ?? 0), E_MeasurementUnits.PT);
|
// svgText.Y = new SvgMeasurement((float)(pageItem.Row ?? 0), E_MeasurementUnits.PT);
|
||||||
if (svgText.Font.Underline && svgText.Text.EndsWith(" ")) svgText.Text = svgText.Text.Substring(0, svgText.Text.Length - 1) + "\xA0";// replace last space with a hardspace
|
// if (svgText.Font.Underline && svgText.Text.EndsWith(" ")) svgText.Text = svgText.Text.Substring(0, svgText.Text.Length - 1) + "\xA0";// replace last space with a hardspace
|
||||||
return svgText;
|
// return svgText;
|
||||||
}
|
//}
|
||||||
private SvgPart PageItemToSvgText(PageItem pageItem, string text, float yOffset)
|
private SvgPart PageItemToSvgText(PageItem pageItem, string text, float yOffset)
|
||||||
{
|
{
|
||||||
SvgText svgText = new SvgText();
|
SvgText svgText = new SvgText();
|
||||||
@ -623,6 +636,9 @@ namespace PrintMSWord
|
|||||||
}
|
}
|
||||||
public static string ToPDFReplaceROs(SectionInfo sect, bool openPdf, System.Windows.Forms.Form myForm )
|
public static string ToPDFReplaceROs(SectionInfo sect, bool openPdf, System.Windows.Forms.Form myForm )
|
||||||
{
|
{
|
||||||
|
string fileName = GetFileName(sect);
|
||||||
|
if (System.IO.File.Exists(@"C:\Temp\" + fileName + ".pdf"))
|
||||||
|
return @"C:\Temp\" + fileName + ".pdf";
|
||||||
int docStyleIndex = ((int)sect.MyContent.Type) % 10000;
|
int docStyleIndex = ((int)sect.MyContent.Type) % 10000;
|
||||||
DocStyle myDocStyle = sect.ActiveFormat.PlantFormat.DocStyles.DocStyleList[docStyleIndex];
|
DocStyle myDocStyle = sect.ActiveFormat.PlantFormat.DocStyles.DocStyleList[docStyleIndex];
|
||||||
PageStyle myPageStyle = myDocStyle.pagestyle;
|
PageStyle myPageStyle = myDocStyle.pagestyle;
|
||||||
@ -743,7 +759,7 @@ namespace PrintMSWord
|
|||||||
sel.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly;
|
sel.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly;
|
||||||
sel.ParagraphFormat.LineSpacing = 12;
|
sel.ParagraphFormat.LineSpacing = 12;
|
||||||
//Console.WriteLine("{0},{1}", sel.ParagraphFormat.LineSpacing, sel.ParagraphFormat.LineSpacingRule);
|
//Console.WriteLine("{0},{1}", sel.ParagraphFormat.LineSpacing, sel.ParagraphFormat.LineSpacingRule);
|
||||||
string fileName = sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber;
|
//string fileName = GetFileName(sect);
|
||||||
//MyApp.Visible = true;
|
//MyApp.Visible = true;
|
||||||
//MessageBox.Show("Ready to make PDF");
|
//MessageBox.Show("Ready to make PDF");
|
||||||
//MyApp.Visible = false;
|
//MyApp.Visible = false;
|
||||||
@ -755,6 +771,12 @@ namespace PrintMSWord
|
|||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetFileName(SectionInfo sect)
|
||||||
|
{
|
||||||
|
string fileName = "Doc " + sect.MyContent.MyEntry.DocID.ToString(); // +" " + (sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber);
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
private static RectangleF CreatePlot(string pngFile, string xyPlot, float resolution, System.Windows.Forms.Form myForm)
|
private static RectangleF CreatePlot(string pngFile, string xyPlot, float resolution, System.Windows.Forms.Form myForm)
|
||||||
{
|
{
|
||||||
RectangleF retval = new RectangleF(0, 0, 0, 0);
|
RectangleF retval = new RectangleF(0, 0, 0, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user