C2023-024 Fix Duplicate Print Issue

This commit is contained in:
Paul Larsen 2023-12-27 11:45:43 -05:00
parent 3ad6dea425
commit 041e28b61b

View File

@ -682,12 +682,35 @@ namespace Volian.Print.Library
// Console.WriteLine("To {0}.{1} Page: {2}",LastWordSection.DisplayNumber,LastWordSection.DisplayText,_PageCountOfWordSection);
// 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;
iTextSharp.text.Document document = new iTextSharp.text.Document(rect);
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));
// PDFA1B does not allow layers, so this is disabled for now
// If enabled, CreateLayers will need to be skipped.
@ -721,6 +744,21 @@ namespace Volian.Print.Library
MyContentByte = writer.DirectContent;
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)
//{
// 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)
{
ProfileTimer.Pop(profileDepth);
@ -2298,7 +2336,7 @@ namespace Volian.Print.Library
else SupInfoPdfPage.Clear();
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
PdfContentByte cb = OpenDoc(SupInfoPdfName, pageSize);
PdfContentByte cb = OpenDoc(ref SupInfoPdfName, pageSize);
if (cb == null) return;
VlnSvgPageHelper myPageHelper = new VlnSvgPageHelper(vlnParagraph.MyItemInfo as SectionInfo, this, null, 0);
cb.PdfWriter.PageEvent = myPageHelper;
@ -2960,3 +2998,4 @@ namespace Volian.Print.Library
// }
//}
}