async Task CreateDocumentImages(C1WordDocument word) { // add first image paragraph Font font = new Font("Segoe UI Light", 16, RtfFontStyle.Italic); word.AddParagraph(Strings.ImageFirstParagraph, font, Colors.DarkGray, RtfHorizontalAlignment.Left); var paragraph = (RtfParagraph)word.Current; paragraph.BottomBorderColor = Colors.Gray; paragraph.BottomBorderStyle = RtfBorderStyle.Single; paragraph.BottomBorderWidth = 1f; word.AddParagraph(string.Empty); // calculate page rect (discounting margins) Rect rcPage = WordUtils.PageRectangle(word); InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream(); #if !true // load image into C1 bitmap var wb = new C1.Xaml.Bitmap.C1Bitmap(); var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///WordSamplesLib/Assets/pic.jpg")); await wb.LoadAsync(file); #else // load image into writeable bitmap WriteableBitmap wb = new WriteableBitmap(880, 660); var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///WordSamplesLib/Assets/pic.jpg")); wb.SetSource(await file.OpenReadAsync()); #endif // add image without scaling by center word.AddPicture(wb, RtfHorizontalAlignment.Center); word.LineBreak(); word.AddParagraph(string.Empty); // add first image paragraph font = new Font("Segoe UI Light", 12, RtfFontStyle.Regular); word.AddParagraph(Strings.ImageSecondParagraph, font, Colors.DeepSkyBlue, RtfHorizontalAlignment.Left); paragraph = (RtfParagraph)word.Current; paragraph.BottomBorderColor = Colors.BlueViolet; paragraph.BottomBorderStyle = RtfBorderStyle.Dotted; paragraph.BottomBorderWidth = 2f; word.AddParagraph(string.Empty); // add image with scaling by right word.AddPicture(wb, RtfHorizontalAlignment.Right); var picture = (RtfPicture)word.Current; picture.Height = 33; picture.Width = 44; }
private void _btMetafile_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Extended metafile (*.emf)|*.emf|Windows metafile (*.wmf)|*.wmf|All files (*.*)|*.*"; dlg.FilterIndex = 1; dlg.RestoreDirectory = true; if (dlg.ShowDialog() != DialogResult.OK) { return; } // create document C1WordDocument c1Word = new C1WordDocument(); c1Word.Info.Title = "Convert metafile to RTF example"; _statusBar.Text = "Creating document..."; Image img; string ext = Path.GetExtension(dlg.FileName); if (ext == ".wmf" || ext == ".emf") { img = Metafile.FromFile(dlg.FileName); } else { throw new FormatException("Not metafile."); } c1Word.DrawMetafile((Metafile)img); c1Word.PageBreak(); c1Word.AddPicture(img, RtfHorizontalAlignment.Left); c1Word.LineBreak(); Font font = new Font("Arial", 10, FontStyle.Regular); c1Word.AddParagraph(dlg.FileName, font, Color.Black); _statusBar.Text = "Saving document..."; string fileName = GetFileName(c1Word, "metafile.rtf"); c1Word.Save(fileName); Process.Start(fileName); _statusBar.Text = "Ready."; }
private void _tbPicture_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Gif (*.gif)|*.gif|Png (*.png)|*.png|Jpeg (*.jpg)|*.jpg|Bitmap (*.bmp)|*.bmp|Windows metafile (*.wmf)|*.wmf|All files (*.*)|*.*"; dlg.FilterIndex = 6; dlg.RestoreDirectory = true; if (dlg.ShowDialog() != DialogResult.OK) { return; } // create document C1WordDocument c1Word = new C1WordDocument(); c1Word.Info.Title = "Show any picture sample"; _statusBar.Text = "Creating document..."; Font font = new Font("Arial", 14, FontStyle.Bold); c1Word.AddParagraph("Picture:", font, Color.Chocolate); Image img; string ext = Path.GetExtension(dlg.FileName); if (ext == ".wmf" || ext == ".emf") { img = Metafile.FromFile(dlg.FileName); } else { img = new Bitmap(dlg.FileName); } c1Word.AddPicture(img, RtfHorizontalAlignment.Left); c1Word.LineBreak(); font = new Font("Arial", 10, FontStyle.Regular); c1Word.AddParagraph(dlg.FileName, font, Color.Blue); _statusBar.Text = "Saving document..."; string fileName = GetFileName(c1Word, "picture.rtf"); c1Word.Save(fileName); Process.Start(fileName); _statusBar.Text = "Ready."; }
private void _btComplex_Click(object sender, System.EventArgs e) { // create document C1WordDocument c1Word = new C1WordDocument(); c1Word.Info.Title = "Complex sample"; _statusBar.Text = "Creating document..."; // add title c1Word.AddParagraph(c1Word.Info.Title, new Font("Tahoma", 24, FontStyle.Italic), Color.BlueViolet); // add image c1Word.AddParagraph("picture:", new Font("Courier New", 9, FontStyle.Regular), Color.Black); Bitmap img = new Bitmap(GetManifestResource("picture.jpg")); c1Word.AddPicture(img, RtfHorizontalAlignment.Center); // add table c1Word.LineBreak(); int rows = 7; int cols = 2; RtfTable table = new RtfTable(rows, cols); table.BottomBorderStyle = table.LeftBorderStyle = table.RightBorderStyle = table.TopBorderStyle = RtfBorderStyle.Single; table.BottomBorderWidth = table.LeftBorderWidth = table.RightBorderWidth = table.TopBorderWidth = 1; c1Word.Add(table); for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { var cell = table.Rows[row].Cells[col]; cell.BottomBorderStyle = cell.LeftBorderStyle = cell.RightBorderStyle = cell.TopBorderStyle = RtfBorderStyle.Single; cell.BottomBorderWidth = cell.LeftBorderWidth = cell.RightBorderWidth = cell.TopBorderWidth = 1; RtfParagraph paragraph = new RtfParagraph(); paragraph.Content.Add(new RtfString(string.Format("table cell {0}:{1}.", row, col))); cell.Content.Add(paragraph); } } // add graphics c1Word.LineBreak(); c1Word.DrawLine(Pens.Green, 200, 90, 400, 90); var rc = new RectangleF(150, 170, 90, 40); using (Pen pen = new Pen(Brushes.Blue, 5.0f)) { c1Word.DrawRectangle(pen, rc); } c1Word.FillRectangle(Color.Gold, rc); c1Word.ShapeFillOpacity(50); c1Word.ShapeRotation(25); rc = new RectangleF(300, 120, 80, 80); c1Word.DrawEllipse(Pens.Red, rc); c1Word.FillEllipse(Color.Pink, rc); c1Word.ShapeFillOpacity(70); _statusBar.Text = "Saving document..."; string fileName = GetFileName(c1Word, "complex.rtf"); c1Word.Save(fileName); Process.Start(fileName); _statusBar.Text = "Ready."; }