public Card(String name, String path, System.Drawing.KnownColor borderColor, String sideText) { CardName = name; Path = path; BorderColor = borderColor; SideText = sideText; }
private void myImportListButton_Click(object sender, RoutedEventArgs e) { // Browse out to the TXT file Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".txt"; // Default file extension dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension dlg.CheckFileExists = true; // Show open file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { myFilterText.Text = ""; ApplyFilter(); mySelectedVcards.Items.Clear(); // Open document string filename = dlg.FileName; StreamReader reader = new StreamReader(filename); string card = reader.ReadLine(); string sideText = ""; while (card != null) { System.Drawing.KnownColor border = KnownColor.Black; if (card.Contains("<SIDETEXT>")) { int indexOfSideText = card.IndexOf("<SIDETEXT>"); int iEndOfBracket = indexOfSideText + 10; int closingSideText = card.IndexOf("</SIDETEXT>", indexOfSideText); sideText = card.Substring(iEndOfBracket, closingSideText - iEndOfBracket); } if (card.Contains("BORDER:")) { int indexOfBorder = card.IndexOf("BORDER:"); int iEndOfBorder = indexOfBorder + 7; int spaceAfterBorder = card.IndexOf(" ", indexOfBorder); if (spaceAfterBorder != -1) { string borderColor = card.Substring(iEndOfBorder, spaceAfterBorder - iEndOfBorder); card = card.Substring(0, indexOfBorder - 1); border = (KnownColor)System.Enum.Parse(typeof(System.Drawing.KnownColor), borderColor, true); } } AddHolodeckCard(card, border, sideText); card = reader.ReadLine(); } } }
private void myOptionsButton_Click(object sender, RoutedEventArgs e) { OptionsDialog dlg = new OptionsDialog(AlternateColor, HorizontalSpacing, BackgroundMatchesFirstCard, StartNumberingAt, ShowCardNumbers); dlg.ShowDialog(); if (dlg.DialogResult == true) { AlternateColor = dlg.AlternateColor; BackgroundMatchesFirstCard = dlg.BackgroundMatchesFirstColor; StartNumberingAt = dlg.StartNumberingAt; HorizontalSpacing = dlg.HorizontalSpacing; ShowCardNumbers = dlg.ShowNumbers; myMoveWhiteBorderRightButton.Content = "Add " + AlternateColor; } }
//#endif //#if WPF // XColor(WpfColor color) // : this(color.A, color.R, color.G, color.B) // { } //#endif //#if GDI XColor(System.Drawing.KnownColor knownColor) : this(System.Drawing.Color.FromKnownColor(knownColor)) { }
private void myWriteButton_Click(object sender, RoutedEventArgs e) { String fileName = SaveFileDialog(); if (String.IsNullOrWhiteSpace(fileName)) { return; } System.Drawing.KnownColor backColorToUse = System.Drawing.KnownColor.White; int iCardNum = StartNumberingAt; foreach (var item in mySelectedVcards.Items) { (item as Card).CardNumber = iCardNum; if (BackgroundMatchesFirstCard) { backColorToUse = (item as Card).BorderColor; } iCardNum++; } iTextSharp.text.BaseColor backColorToDraw = new iTextSharp.text.BaseColor(WhiteBorderConverter.GetCompatibleColor(backColorToUse)); //new iTextSharp.text.BaseColor(System.Drawing.Color.FromKnownColor(backColorToUse)); PageEventHandler.PrintingBlackBorder = (backColorToUse == KnownColor.Black); PageEventHandler.BackColor = backColorToDraw; PageEventHandler.UsingCubeFeatures = (myCubeFeaturesCheckbox.IsChecked == true); using (WaitDlg dlg = new WaitDlg()) { Document sizeDoc = new Document(PageSize.LETTER); iTextSharp.text.Rectangle backgroundRect = new iTextSharp.text.Rectangle(sizeDoc.PageSize); Document document; if (BackgroundMatchesFirstCard) { backgroundRect.BackgroundColor = backColorToDraw; document = new Document(backgroundRect); } else { document = new Document(PageSize.LETTER); } PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create)); myEvents = new PageEventHandler(); writer.PageEvent = myEvents; //document.SetMargins(0, 0, 10, 0); // WORKING! document.SetMargins(document.LeftMargin, document.RightMargin, 25, 25); //document.SetMargins(0.0f, 0.0f, 0.0f, 0.0f); document.SetMargins(document.LeftMargin, document.RightMargin, 15, 10); // step 3: we open the document document.Open(); //iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph(); PdfPTable table = new pdf.PdfPTable(3); table.SpacingBefore = 0; table.SpacingAfter = 10; //table.TotalWidth = 175.5f * 3.0f + 30f; table.TotalWidth = 179.0f * 3.0f + 20f; table.LockedWidth = true; table.AbsoluteWidths[0] = 179.0f + (float)HorizontalSpacing; table.AbsoluteWidths[1] = 179.0f + (float)HorizontalSpacing; table.AbsoluteWidths[2] = 179.0f + (float)HorizontalSpacing; List <Card> smallCards = GetSelectedCards(true, false); List <Card> bigCards = GetSelectedCards(false, true); WriteCards(bigCards, table, document, backColorToUse); WriteCards(smallCards, table, document, backColorToUse); PdfPCell emptyCell = new PdfPCell(); emptyCell.BackgroundColor = backColorToDraw; emptyCell.BorderColor = backColorToDraw; table.AddCell(emptyCell); table.AddCell(emptyCell); table.AddCell(emptyCell); foreach (var row in table.Rows) { //pdf.PdfPCell cell = row.GetCells()[0]; //float top = row.GetCells()[0].Bottom; //iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(-30,top, 50, top+3); //document.Add(rect); } document.Add(table); document.Close(); } MessageBox.Show("PDF Generation Complete!"); }