This commit is contained in:
Kathy Ruffing 2012-06-08 13:22:56 +00:00
parent 09139f8595
commit 639895f46f

View File

@ -400,77 +400,7 @@ namespace Volian.Print.Library
CreateStepPdf(mySection, cb);
}
else
{
myPdfFile = BuildMSWordPDF(mySection);
try
{
readerWord = myPdfFile != null ? new PdfReader(myPdfFile) : null;
OnStatusChanged("Get Section", PromsPrinterStatusType.GetSection);
int sectPageCount = 0;
float locEndOfWordDoc = 0;
float pdfSize = 0;
using (PdfInfo myPdf = PdfInfo.Get(mySection))
{
sectPageCount = (int)(Math.Ceiling(myPdf.PageCount));
locEndOfWordDoc = (float)(myPdf.PageCount - (sectPageCount - 1)) * 100;
pdfSize = (float)myPdf.PageCount;
}
string tocKey = string.Format("TOC{0}", mySection.ItemID);
if (_MyHelper.MyTOCPageCounts.ContainsKey(tocKey))
{
PageCount pc = _MyHelper.MyTOCPageCounts[tocKey];
pc.Total = _MyHelper.CurrentPageNumber;
pc.DrawTemplates();
}
for (int ii = 0; ii < sectPageCount; ii++)
{
int pageNumber = 1 + ii;
if (((mySection.MyDocStyle.StructureStyle.Style ?? 0) & E_DocStructStyle.UseSectionFoldout) != 0)
DoFoldoutPage(cb, "Word Document", _TextLayer, _MyHelper);
if (readerWord != null)
{
bool doimport2 = true;
PdfImportedPage fgPage = null;
try
{
fgPage = cb.PdfWriter.GetImportedPage(readerWord, ii + 1);
}
catch (Exception ex)
{
Console.WriteLine(ex);
doimport2 = false;
}
OnStatusChanged("Read MSWord", PromsPrinterStatusType.ReadMSWord);
if (doimport2) AddImportedPageToLayer(cb.PdfWriter.DirectContent, _MSWordLayer, fgPage, 0, 0);
if (ii == sectPageCount - 1)
{
// if there's and end message, add it to the appropriate location on the last page of
// the word document:
if ((mySection.MyDocStyle.End.Message ?? "") != "")
{
float ylocation = cb.PdfDocument.PageSize.Height - ((float)mySection.MyDocStyle.Layout.TopMargin + locEndOfWordDoc * 72); // 72 - pts per inch.
iTextSharp.text.Font fnt = VolianPdf.GetFont(mySection.MyDocStyle.End.Font.WindowsFont);
fnt.Color = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Black));
iTextSharp.text.Paragraph para = new Paragraph(mySection.MyDocStyle.End.Message, fnt);
float wtpm = (float)mySection.MyDocStyle.Layout.PageWidth - (float)mySection.MyDocStyle.Layout.LeftMargin;
float centerpos = (float)mySection.MyDocStyle.Layout.LeftMargin + (wtpm - (mySection.MyDocStyle.End.Message.Length * mySection.MyDocStyle.End.Font.CharsToTwips)) / 2;
float yBottomMargin = Math.Max(0, (float)mySection.MyDocStyle.Layout.TopMargin - (float)mySection.MyDocStyle.Layout.PageLength - 2 * vlnPrintObject.SixLinesPerInch);
Rtf2Pdf.TextAt(cb, para, centerpos, ylocation + 6, 100, 12, "", yBottomMargin);
}
}
OnStatusChanged("Merge MSWord", PromsPrinterStatusType.MergeMSWord);
}
OnStatusChanged("Before NewPage", PromsPrinterStatusType.Before);
cb.PdfDocument.NewPage(); // Word Document
OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage);
}
}
catch (Exception ex)
{
cb.PdfDocument.NewPage(); // can we put out 'error on page'?
}
}
CreateWordDocPdf(cb, mySection, ref readerWord, ref myPdfFile);
}
}
if (_MyHelper.BackgroundFile != null)
@ -488,6 +418,80 @@ namespace Volian.Print.Library
return outputFileName;
}
public void CreateWordDocPdf(PdfContentByte cb, SectionInfo mySection, ref PdfReader readerWord, ref string myPdfFile)
{
_MyHelper.MySection = mySection;
myPdfFile = BuildMSWordPDF(mySection);
try
{
readerWord = myPdfFile != null ? new PdfReader(myPdfFile) : null;
OnStatusChanged("Get Section", PromsPrinterStatusType.GetSection);
int sectPageCount = 0;
float locEndOfWordDoc = 0;
float pdfSize = 0;
using (PdfInfo myPdf = PdfInfo.Get(mySection))
{
sectPageCount = (int)(Math.Ceiling(myPdf.PageCount));
locEndOfWordDoc = (float)(myPdf.PageCount - (sectPageCount - 1)) * 100;
pdfSize = (float)myPdf.PageCount;
}
string tocKey = string.Format("TOC{0}", mySection.ItemID);
if (_MyHelper.MyTOCPageCounts.ContainsKey(tocKey))
{
PageCount pc = _MyHelper.MyTOCPageCounts[tocKey];
pc.Total = _MyHelper.CurrentPageNumber;
pc.DrawTemplates();
}
for (int ii = 0; ii < sectPageCount; ii++)
{
int pageNumber = 1 + ii;
if (((mySection.MyDocStyle.StructureStyle.Style ?? 0) & E_DocStructStyle.UseSectionFoldout) != 0)
DoFoldoutPage(cb, "Word Document", _TextLayer, _MyHelper);
if (readerWord != null)
{
bool doimport2 = true;
PdfImportedPage fgPage = null;
try
{
fgPage = cb.PdfWriter.GetImportedPage(readerWord, ii + 1);
}
catch (Exception ex)
{
Console.WriteLine(ex);
doimport2 = false;
}
OnStatusChanged("Read MSWord", PromsPrinterStatusType.ReadMSWord);
if (doimport2) AddImportedPageToLayer(cb.PdfWriter.DirectContent, _MSWordLayer, fgPage, 0, 0);
if (ii == sectPageCount - 1)
{
// if there's and end message, add it to the appropriate location on the last page of
// the word document:
if ((mySection.MyDocStyle.End.Message ?? "") != "")
{
float ylocation = cb.PdfDocument.PageSize.Height - ((float)mySection.MyDocStyle.Layout.TopMargin + locEndOfWordDoc * 72); // 72 - pts per inch.
iTextSharp.text.Font fnt = VolianPdf.GetFont(mySection.MyDocStyle.End.Font.WindowsFont);
fnt.Color = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Black));
iTextSharp.text.Paragraph para = new Paragraph(mySection.MyDocStyle.End.Message, fnt);
float wtpm = (float)mySection.MyDocStyle.Layout.PageWidth - (float)mySection.MyDocStyle.Layout.LeftMargin;
float centerpos = (float)mySection.MyDocStyle.Layout.LeftMargin + (wtpm - (mySection.MyDocStyle.End.Message.Length * mySection.MyDocStyle.End.Font.CharsToTwips)) / 2;
float yBottomMargin = Math.Max(0, (float)mySection.MyDocStyle.Layout.TopMargin - (float)mySection.MyDocStyle.Layout.PageLength - 2 * vlnPrintObject.SixLinesPerInch);
Rtf2Pdf.TextAt(cb, para, centerpos, ylocation + 6, 100, 12, "", yBottomMargin);
}
}
OnStatusChanged("Merge MSWord", PromsPrinterStatusType.MergeMSWord);
}
OnStatusChanged("Before NewPage", PromsPrinterStatusType.Before);
cb.PdfDocument.NewPage(); // Word Document
OnStatusChanged("After NewPage", PromsPrinterStatusType.NewPage);
}
}
catch (Exception ex)
{
cb.PdfDocument.NewPage(); // can we put out 'error on page'?
}
}
private void GenerateTOC(SectionInfo tocSection, ProcedureInfo myProcedure, PdfContentByte cb, PdfLayer textLayer)
{
iTextSharp.text.pdf.PdfWriter writer = cb.PdfWriter;