C2023-024 Fix Duplicate Print Issue #192

Merged
cglavan merged 1 commits from C2023-024B into Development 2023-12-27 16:01:15 -05:00

View File

@ -682,12 +682,35 @@ namespace Volian.Print.Library
// Console.WriteLine("To {0}.{1} Page: {2}",LastWordSection.DisplayNumber,LastWordSection.DisplayText,_PageCountOfWordSection); // Console.WriteLine("To {0}.{1} Page: {2}",LastWordSection.DisplayNumber,LastWordSection.DisplayText,_PageCountOfWordSection);
// PreviousWordSection = LastWordSection; // PreviousWordSection = LastWordSection;
//} //}
private PdfContentByte OpenDoc(string outputFileName, iTextSharp.text.Rectangle rect) private PdfContentByte OpenDoc(ref string outputFileName, iTextSharp.text.Rectangle rect)
{
try
{ {
PdfWriter writer = null; PdfWriter writer = null;
iTextSharp.text.Document document = new iTextSharp.text.Document(rect); iTextSharp.text.Document document = new iTextSharp.text.Document(rect);
try try
{ {
if (File.Exists(outputFileName))
{
String tmpExt = System.IO.Path.GetExtension(outputFileName);
String tmpPTH = System.IO.Path.GetDirectoryName(outputFileName);
String tmpFN = System.IO.Path.GetFileName(outputFileName);
String tmpFNNoExt = System.IO.Path.GetFileNameWithoutExtension(outputFileName);
var files = new HashSet<string>(Directory.GetFiles(tmpPTH, "*.pdf"));
//string baseName = Path.Combine(scpath, "Screenshot_");
string filename;
int i = 0;
do
{
filename = tmpPTH + @"\" + tmpFNNoExt + "_" + ++i + ".pdf";
} while (files.Contains(filename));
outputFileName = filename;
}
writer = PdfWriter.GetInstance(document, new FileStream(outputFileName, FileMode.Create)); writer = PdfWriter.GetInstance(document, new FileStream(outputFileName, FileMode.Create));
// PDFA1B does not allow layers, so this is disabled for now // PDFA1B does not allow layers, so this is disabled for now
// If enabled, CreateLayers will need to be skipped. // If enabled, CreateLayers will need to be skipped.
@ -721,6 +744,21 @@ namespace Volian.Print.Library
MyContentByte = writer.DirectContent; MyContentByte = writer.DirectContent;
return MyContentByte; return MyContentByte;
} }
catch (Exception ex)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Error occured when creating Print PDF");
sb.AppendLine();
sb.AppendLine(outputFileName + ".");
sb.AppendLine();
sb.AppendLine("If it is open, close and retry.");
MessageBox.Show(sb.ToString(), "Error Creating PDF", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//MessageBox.Show("Could not create " + outputFileName + ". If it is open, close and retry.", "Error on CreatePdf");
return MyContentByte = null;
}
}
//private string CreateFileName(string procNumber, string sectNumber, string sectTitle) //private string CreateFileName(string procNumber, string sectNumber, string sectTitle)
//{ //{
// return FixFileName(procNumber + "_" + ((sectNumber ?? "") != "" ? sectNumber : sectTitle)); // return FixFileName(procNumber + "_" + ((sectNumber ?? "") != "" ? sectNumber : sectTitle));
@ -871,7 +909,7 @@ namespace Volian.Print.Library
} }
} }
} }
PdfContentByte cb = OpenDoc(outputFileName, rct); PdfContentByte cb = OpenDoc(ref outputFileName, rct);
if (cb == null) if (cb == null)
{ {
ProfileTimer.Pop(profileDepth); ProfileTimer.Pop(profileDepth);
@ -2298,7 +2336,7 @@ namespace Volian.Print.Library
else SupInfoPdfPage.Clear(); else SupInfoPdfPage.Clear();
string SupInfoPdfName = Volian.Base.Library.VlnSettings.TemporaryFolder + @"\SupInfo" + vlnParagraph.MyItemInfo.ItemID.ToString() + @".pdf"; string SupInfoPdfName = Volian.Base.Library.VlnSettings.TemporaryFolder + @"\SupInfo" + vlnParagraph.MyItemInfo.ItemID.ToString() + @".pdf";
iTextSharp.text.Rectangle pageSize = PDFPageSize.UsePaperSize(MyItem.ActiveFormat.PlantFormat.FormatData.PDFPageSize.PaperSize); // C2020-002 paper size is now set in the format files iTextSharp.text.Rectangle pageSize = PDFPageSize.UsePaperSize(MyItem.ActiveFormat.PlantFormat.FormatData.PDFPageSize.PaperSize); // C2020-002 paper size is now set in the format files
PdfContentByte cb = OpenDoc(SupInfoPdfName, pageSize); PdfContentByte cb = OpenDoc(ref SupInfoPdfName, pageSize);
if (cb == null) return; if (cb == null) return;
VlnSvgPageHelper myPageHelper = new VlnSvgPageHelper(vlnParagraph.MyItemInfo as SectionInfo, this, null, 0); VlnSvgPageHelper myPageHelper = new VlnSvgPageHelper(vlnParagraph.MyItemInfo as SectionInfo, this, null, 0);
cb.PdfWriter.PageEvent = myPageHelper; cb.PdfWriter.PageEvent = myPageHelper;
@ -2960,3 +2998,4 @@ namespace Volian.Print.Library
// } // }
//} //}
} }