private static void DrawLetterGreeting(CustomerInformation customer) { // Save graphics state Contents.SaveGraphicsState(); // Set coordinate Contents.Translate(1.3, 14); // Define constants const Double Width = 18; const Double Height = 8; const Double FontSize = 10; // Create text box object with no first line indent TextBox headMessage = new TextBox(Width, 0); // add text to the text box headMessage.AddText(ArialNormal, FontSize, "Dear " + customer.GetName() + ",\n\n"); headMessage.AddText(ArialNormal, FontSize, Properties.Settings.Default.SimpleLetterGreatingEng + Environment.NewLine); headMessage.AddText(SimHei, FontSize, Properties.Settings.Default.SimpleLetterGreatingChn + Environment.NewLine); // Draw the text box Double PosY = Height; Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.Left, headMessage); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw example of a text box //////////////////////////////////////////////////////////////////// private static void DrawCustomerNameAddress(CustomerInformation customer) { // save graphics state Contents.SaveGraphicsState(); // set coordinate Contents.Translate(1.3, 16.2); // Define constants const Double Width = 18; const Double Height = 8; const Double FontSize = 10; // Create text box object with no first line indent TextBox customerContact = new TextBox(Width, 0); // add text to the text box customerContact.AddText(ArialNormal, FontSize, customer.GetName() + "\n"); customerContact.AddText(ArialNormal, FontSize, customer.GetAddress()[0] + "\n"); customerContact.AddText(ArialNormal, FontSize, customer.GetAddress()[1] + "\n"); customerContact.AddText(ArialNormal, FontSize, customer.GetAddress()[2] + "\n"); // Draw the text box Double PosY = Height; Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.Left, customerContact); // restore graphics state Contents.RestoreGraphicsState(); return; }
private void button1_Click(object sender, EventArgs e) { List <string> warningMessages = throughOutCheck(); if (warningMessages.Count > 0) { if (!doesUserWantToProceed(warningMessages)) { return; // if user decide to take another look, then return } } List <Account> accountList = new List <Account>(); for (int i = 0; i < MAX_ACCOUNTS_SUPPORTED; i++) { if (accountCheckBoxes[i].Checked) { string accountType = accountTypeComboBoxes[i].Text; string ccyCode = accountCcyComboBoxes[i].Text; string longNumber = "100001401" + accountLongNumberTextBoxes[i].Text; string shortNumber = ""; if (accountShortNumberTextBoxes[i].Text != "") { shortNumber = "9000" + accountShortNumberTextBoxes[i].Text; } accountList.Add(new Account(accountType, ccyCode, longNumber, shortNumber)); } } CustomerInformation customer; if (addressInclusionCheckBox.Checked) { customer = new CustomerInformation(customerNameTextBox.Text, addressLineTextBox1.Text, addressLineTextBox2.Text, addressLineTextBox3.Text); } else { customer = new CustomerInformation(customerNameTextBox.Text); } BranchInfo branch = new BranchInfo((Branch)(Properties.Settings.Default.DefaultBranchIndex)); bool inclEmail = emailInclusionCheckBox.Checked; string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + customer.GetName() + ".pdf"; Pdf_Generation_Class.GenerateWelcomeLetterSimple(fileName, customer, accountList, branch, inclEmail); if (openFileCheckBox.Checked) { System.Diagnostics.Process.Start(fileName); } }
//////////////////////////////////////////////////////////////////// // Create article's example test PDF document //////////////////////////////////////////////////////////////////// public static void GenerateWelcomeLetterSimple(String FileName, CustomerInformation customer, List <Account> accountList, BranchInfo branch, bool inclEmail, Boolean Debug = false) { // Create an empty pdf document in A4 and measured in cm bool landscape = false; document = new PdfDocument(PaperType.A4, landscape, UnitOfMeasure.cm, FileName); // Set debug tag document.Debug = Debug; // Write Pdf info PdfInfo Info = PdfInfo.CreatePdfInfo(document); Info.Title("Welcome Letter - Bank of China"); Info.Author("Bank of China " + branch.GetAddress()[0]); Info.Keywords("Account, Bank of China, Remittance"); Info.Subject("Remittance information for Bank of China accounts"); // define font resources DefineFontResources(); // Add first page, also the only page for simple welcome letter Page = new PdfPage(document); // Add contents to page Contents = new PdfContents(Page); // Add graphices and text contents to the contents object DrawTitle(); if (customer.HasAddress()) { DrawCustomerNameAddress(customer); } DrawBranchNameAddress(branch, inclEmail); DrawLetterGreeting(customer); DrawBankInformation(customer); DrawAccountInformationForm(accountList); DrawLetterBody(); DrawGroupContact(); // Create pdf file document.CreateFile(); // exit return; }
//////////////////////////////////////////////////////////////////// // Draw example of order form //////////////////////////////////////////////////////////////////// private static void DrawBankInformation(CustomerInformation customer) { // Define constants to make the code readable const Double LEFT = 6.3; const Double TOP = 19.5; const Double BOTTOM = 17.3; const Double RIGHT = 6.3 + 15.39; const Double FONT_SIZE = 10; const Double MARGIN_HOR = 0.04; const Double MARGIN_VER = 0.04; // preset content string[,] content = new string[, ] { { "BSB Number: ", "980200" }, { "Swift Code: ", "BKCHAU2AXXX" }, { "Bank Name: ", "Bank of China (Australia) Ltd" } }; // column widths Double colWidthTitle = ArialNormal.TextWidth(FONT_SIZE, "Account Name: ") + 2.0 * MARGIN_HOR; Double colWidthDetail = ArialNormal.TextWidth(FONT_SIZE, "A very very very long name example and may be longer") + 2.0 * MARGIN_HOR; // define table PdfTable Table = new PdfTable(Page, Contents, ArialNormal, FONT_SIZE); Table.TableArea = new PdfRectangle(LEFT, BOTTOM, RIGHT, TOP); Table.SetColumnWidth(new Double[] { colWidthTitle, colWidthDetail }); // define borders Table.Borders.ClearAllBorders(); // margin PdfRectangle Margin = new PdfRectangle(MARGIN_HOR, MARGIN_VER); // default header style Table.DefaultHeaderStyle.Margin = Margin; Table.DefaultHeaderStyle.BackgroundColor = Color.White; Table.DefaultHeaderStyle.Alignment = ContentAlignment.MiddleLeft; // table heading Table.Header[0].Value = "Account Name: "; Table.Header[1].Value = customer.GetName().ToUpper(); // account type style Table.DefaultCellStyle.Margin = Margin; // loop for all items for (int i = 0; i < content.GetLength(0); i++) { for (int j = 0; j < content.GetLength(1); j++) { Table.Cell[j].Value = content[i, j]; } Table.DrawRow(); } Table.Close(); // save graphics state Contents.SaveGraphicsState(); // restore graphics state Contents.RestoreGraphicsState(); return; }