public static string GetInformationAboutRichEditDocumentLayout(Document currentDocument, DocumentLayout currentDocumentLayout) { SubDocument subDocument = currentDocument.CaretPosition.BeginUpdateDocument(); DocumentPosition docPosition = subDocument.CreatePosition(currentDocument.CaretPosition.ToInt() == 0 ? 0 : currentDocument.CaretPosition.ToInt() - 1); ReadOnlyShapeCollection shapes = subDocument.Shapes.Get(subDocument.CreateRange(docPosition, 1)); ReadOnlyDocumentImageCollection images = subDocument.Images.Get(subDocument.CreateRange(docPosition, 1)); if (shapes.Count == 0 && images.Count == 0) { docPosition = subDocument.CreatePosition(currentDocument.CaretPosition.ToInt()); } string returnedInformation = ""; // get infromation about a current document element returnedInformation += GetInformationAboutCurrentDocumentElement(currentDocument, currentDocumentLayout, subDocument, docPosition); // collect information about CURRENT PAGE RangedLayoutElement layoutPosition = currentDocumentLayout.GetElement <RangedLayoutElement>(docPosition); if (layoutPosition != null) { int currentPageIndex = currentDocumentLayout.GetPageIndex(layoutPosition); returnedInformation += PageLayoutHelper.GetInformationAboutCurrentPage(currentDocumentLayout, currentDocumentLayout.GetPage(currentPageIndex), docPosition); } currentDocument.CaretPosition.EndUpdateDocument(subDocument); return(returnedInformation); }
static void Main() { #region #inlinepictures RichEditDocumentServer server = new RichEditDocumentServer(); server.LoadDocument("Texts\\InlinePictures.rtf", DocumentFormat.Rtf); Document doc = server.Document; // Insert an image from a file. DocumentRange rangeFound = doc.FindAll("Visual Studio Magazine", SearchOptions.CaseSensitive)[0]; DocumentPosition pos = doc.Paragraphs[doc.Paragraphs.Get(rangeFound.End).Index + 2].Range.Start; doc.Images.Insert(pos, DocumentImageSource.FromFile("Pictures\\ReadersChoice.png")); // Insert an image from a stream. pos = doc.Paragraphs[4].Range.Start; string imageToInsert = "information.png"; Assembly a = Assembly.GetExecutingAssembly(); Stream imageStream = a.GetManifestResourceStream("InlinePictures.Resources." + imageToInsert); doc.Images.Insert(pos, DocumentImageSource.FromStream(imageStream)); // Insert an image using its URI. string imageUri = "http://i.gyazo.com/798a2ed48a3535c6c8add0ea7a4fc4e6.png"; SubDocument docHeader = doc.Sections[0].BeginUpdateHeader(); docHeader.Images.Append(DocumentImageSource.FromUri(imageUri, server)); doc.Sections[0].EndUpdateHeader(docHeader); // Insert a barcode. DevExpress.BarCodes.BarCode barCode = new DevExpress.BarCodes.BarCode(); barCode.Symbology = DevExpress.BarCodes.Symbology.QRCode; barCode.CodeText = "http://www.devexpress.com"; barCode.CodeBinaryData = System.Text.Encoding.Default.GetBytes(barCode.CodeText); barCode.Module = 0.5; SubDocument docFooter = doc.Sections[0].BeginUpdateFooter(); docFooter.Images.Append(barCode.BarCodeImage); doc.Sections[0].EndUpdateFooter(docFooter); #endregion #inlinepictures #region #getimages // Scale down images in the document body. ReadOnlyDocumentImageCollection images = server.Document.Images.Get(doc.Range); for (int i = 0; i < images.Count; i++) { images[i].ScaleX /= 4; images[i].ScaleY /= 4; } #endregion #getimages // Save the resulting document. server.SaveDocument("InlinePictures.docx", DocumentFormat.OpenXml); Process.Start("InlinePictures.docx"); }
static void SaveImageToFile(Document document) { #region #SaveImageToFile document.LoadDocument("Documents//MovieRentals.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml); DocumentRange myRange = document.CreateRange(0, 100); ReadOnlyDocumentImageCollection images = document.Images.Get(myRange); if (images.Count > 0) { DevExpress.Office.Utils.OfficeImage myImage = images[0].Image; System.Drawing.Image image = myImage.NativeImage; string imageName = String.Format("Image_at_pos_{0}.png", images[0].Range.Start.ToInt()); image.Save(imageName); System.Diagnostics.Process.Start("explorer.exe", "/select," + imageName); } #endregion #SaveImageToFile }
static void SaveImageFromRange(Document document) { #region #SaveImageFromRange document.LoadDocument("Documents//Grimm.docx", DocumentFormat.OpenXml); DocumentRange docRange = document.Paragraphs[2].Range; ReadOnlyDocumentImageCollection docImageColl = document.Images.Get(docRange); if (docImageColl.Count > 0) { DevExpress.Office.Utils.OfficeImage myImage = docImageColl[0].Image; System.Drawing.Image image = myImage.NativeImage; string imageName = String.Format("Image_at_pos_{0}.png", docRange.Start.ToInt()); image.Save(imageName); System.Diagnostics.Process.Start("explorer.exe", "/select," + imageName); } #endregion #SaveImageFromRange }
static void ImageCollection(Document document) { #region #ImageCollection document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml); ReadOnlyDocumentImageCollection images = document.Images; // If the width of an image exceeds 50 millimeters, // the image is scaled proportionally to half its size. for (int i = 0; i < images.Count; i++) { if (images[i].Size.Width > DevExpress.Office.Utils.Units.MillimetersToDocumentsF(50)) { images[i].ScaleX /= 2; images[i].ScaleY /= 2; } } #endregion #ImageCollection }
private void btnScaleDown_Click(object sender, EventArgs e) { #region #scaledown richEditControl1.Document.Unit = DevExpress.Office.DocumentUnit.Millimeter; ReadOnlyDocumentImageCollection images = richEditControl1.Document.Images.Get(richEditControl1.Document.Range); for (int i = 0; i < images.Count; i++) { if (images[i].Size.Width > 50) { images[i].ScaleX /= 2; images[i].ScaleY /= 2; } } #endregion #scaledown }
private void btnSaveImage_Click(object sender, RoutedEventArgs e) { #region #saveimage ReadOnlyDocumentImageCollection imgs = richEditControl1.Document.Images.Get(richEditControl1.Document.Selection); if (imgs.Count > 0) { MemoryStream ms = new MemoryStream(imgs[0].Image.GetImageBytesSafe(OfficeImageFormat.Png)); SaveFileDialog sfdlg = new SaveFileDialog(); sfdlg.DefaultExt = ".png"; sfdlg.Filter = "PNG Image (*.png)|*.png"; if (sfdlg.ShowDialog() == true) { Stream fs = sfdlg.OpenFile(); ms.WriteTo(fs); fs.Close(); } ms.Close(); } #endregion #saveimage }