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; }
//////////////////////////////////////////////////////////////////// // 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; }