Using New Volian.Print.Library

This commit is contained in:
Rich 2010-05-19 14:54:55 +00:00
parent 72e8f937f2
commit 4e85f82557

View File

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