From 698da0999249b1a4843790f760b8886c409c9d1b Mon Sep 17 00:00:00 2001 From: Bimal Chandra Debnath Date: Fri, 30 Nov 2018 01:54:54 +0600 Subject: [PATCH] showing print message bugs fixed --- Tax Calculator/Form6_AssetAndLiabilities.cs | 15 +++-- Tax Calculator/MyPdfWriter.cs | 67 +++++++++++++-------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/Tax Calculator/Form6_AssetAndLiabilities.cs b/Tax Calculator/Form6_AssetAndLiabilities.cs index 28247b6..2f9147f 100644 --- a/Tax Calculator/Form6_AssetAndLiabilities.cs +++ b/Tax Calculator/Form6_AssetAndLiabilities.cs @@ -1114,19 +1114,18 @@ private void btBack_Click(object sender, EventArgs e) //pdf creating button. print button private void btPrint_Click(object sender, EventArgs e) - { - + { //taking all assets and liabilities info in a string UserInputs_AssetAndLiabilities(); MyPdfWriter myPdfWriter = new MyPdfWriter(); - - /* MessageBox.Show("PDF print functionality is available only on PRO Version.", //warnning message - "Notice", //window title - MessageBoxButtons.OK, - MessageBoxIcon.Exclamation); //For cross Warning icon - */ + + /* MessageBox.Show("PDF print functionality is available only on PRO Version.", //warnning message + "Notice", //window title + MessageBoxButtons.OK, + MessageBoxIcon.Exclamation); //For cross Warning icon + */ } } } diff --git a/Tax Calculator/MyPdfWriter.cs b/Tax Calculator/MyPdfWriter.cs index 74fd88b..e1727d9 100644 --- a/Tax Calculator/MyPdfWriter.cs +++ b/Tax Calculator/MyPdfWriter.cs @@ -22,38 +22,55 @@ public class MyPdfWriter public MyPdfWriter() { - + string file_name = ""; SaveFileDialog svg = new SaveFileDialog(); //show dialgue box to take a location with file name svg.ShowDialog(); //getting new pdf file location and file name given by user - // size = reader.GetPageSizeWithRotation(1); - try + // size = reader.GetPageSizeWithRotation(1); + + file_name = Path.GetFileName(svg.FileName); //getting file_name given by user + if (file_name.Length > 0) //checking user valid file_name input { - using (var outputPdfStream = new FileStream(svg.FileName + ".pdf", FileMode.Create, FileAccess.Write)) + try + { + using (var outputPdfStream = new FileStream(svg.FileName + ".pdf", FileMode.Create, FileAccess.Write)) + { + //open the reader + PdfReader reader = new PdfReader(oldFile); + + PdfStamper stamper = new PdfStamper(reader, outputPdfStream); + var pageSize = reader.GetPageSize(1); //getting page size by giving page number=1 + + pdfWrite_Form1(ref stamper, ref reader); //Personal_info form print + pdfWrite_Form2(ref stamper, ref reader); //salaries form print + pdfWrite_Form3(ref stamper, ref reader); //Investment-tax-credit form print + pdfWrite_Form5(ref stamper, ref reader); //statement-of-salary form print + pdfWrite_Form4(ref stamper, ref reader); //Expenses form print + pdfWrite_Form6(ref stamper, ref reader); //Asset and Liabilities form print + pdfWrite_Page8(ref stamper, ref reader); //last page of tex return form + stamper.Close(); + MessageBox.Show("Print successfully " + + "\n File Name : " + file_name + + "\n File location: " + svg.FileName.ToString() , // messages + "Congratulation", //window title + MessageBoxButtons.OK, + MessageBoxIcon.Information); //For cross Warning icon + } + } + catch //if file is opened { - //open the reader - PdfReader reader = new PdfReader(oldFile); - - PdfStamper stamper = new PdfStamper(reader, outputPdfStream); - var pageSize = reader.GetPageSize(1); //getting page size by giving page number=1 - - pdfWrite_Form1(ref stamper, ref reader); //Personal_info form print - pdfWrite_Form2(ref stamper, ref reader); //salaries form print - pdfWrite_Form3(ref stamper, ref reader); //Investment-tax-credit form print - pdfWrite_Form5(ref stamper, ref reader); //statement-of-salary form print - pdfWrite_Form4(ref stamper, ref reader); //Expenses form print - pdfWrite_Form6(ref stamper, ref reader); //Asset and Liabilities form print - pdfWrite_Page8(ref stamper, ref reader); //last page of tex return form - stamper.Close(); - MessageBox.Show("Print successfully"); + MessageBox.Show("Please close your pdf file first.\n Or try different file name", //warnning message + svg.FileName.ToString() + " is already open", //window title + MessageBoxButtons.OK, + MessageBoxIcon.Hand); //For cross Warning icon } } - catch - { - MessageBox.Show("Please close your pdf file first.\n Or try different file name", //warnning message - svg.FileName.ToString() + " is already open", //window title + // if invalid file name given + else + MessageBox.Show("Please give a proper file name", //warnning message + "Warning", //window title MessageBoxButtons.OK, - MessageBoxIcon.Hand); //For cross Warning icon - } + MessageBoxIcon.Warning); //For exclaimatory icon in trangle shape + } private void pdfWrite_Form1(ref PdfStamper stamper, ref PdfReader reader)