This post includes a series of interesting support tickets answered throughout August and September along with a breaking change notice. It also includes a list of enhancements made to our Office-inspired product line. We hope you find the contents of this post interesting and of business value. Should you have any questions about this post, feel free to comment below.
Breaking Change
T1032641 - The PdfChoiceFormFieldFacade<T> class and its descendants were changed
https://supportcenter.devexpress.com/ticket/details/t1032641
With our most recent update (v21.1.6), the MultiSelect and Value properties were moved from the PdfChoiceFormFieldFacade<T> class to its descendants: PdfComboBoxFormFieldFacade and PdfListBoxFormFieldFacade. The latter class now includes a Values property that allows you to specify multiple values for a list box form field.
If you need to specify a single value for a list box form field, use the PdfListBoxFormFieldFacade.Values property in the following manner:
using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
pdfDocumentProcessor.LoadDocument("Documents//FormDemo.pdf");
PdfDocumentFacade documentFacade = pdfDocumentProcessor.DocumentFacade;
PdfAcroFormFacade acroForm = documentFacade.AcroForm;
PdfListBoxFormFieldFacade listField = acroForm.GetListBoxFormField("List");
listField.Values = new List<string>() { listField.Items[2].Value };
pdfDocumentProcessor.SaveDocument("Documents//Result.pdf");
}
Tips & Tricks
Word Processing Document API
-
T1019089 - How to use the Word Processing Document API to insert an image into the MVC Rich Text Editor
https://supportcenter.devexpress.com/ticket/details/t1019089
-
T1026292 - How to obtain custom document properties
https://supportcenter.devexpress.com/ticket/details/t1026292
The Document.CustomProperties property returns custom properties. To access an individual property, obtain the property’s name, and pass this name to the indexer. The following code sample retrieves all custom properties:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Linq;
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
// Load document
wordProcessor.LoadDocument("Document.docx");
// Access custom property collection
DocumentCustomProperties customProperties =
wordProcessor.Document.CustomProperties;
for (int i = 0; i <= customProperties.Count-1; i++)
{
// Get property name
string propertyName = customProperties.Names.ElementAt(i);
// Retrieve property by its name
var property = customProperties[propertyName];
// Your code here
}
}
T1025985 - How to display a Data Table below a chart
https://supportcenter.devexpress.com/ticket/details/t1025985
WinForms and WPF Rich Text Editors
Spreadsheet Document API
T1024059 - How to merge data from multiple worksheets into a single worksheet
https://supportcenter.devexpress.com/ticket/details/t1024059
Call the CellRange.CopyFrom method to copy data (e.g., text, numbers, and formula calculated values) from one worksheet to another. Use the GetDataRange method to retrieve a data range from a source worksheet.
using DevExpress.Spreadsheet;
using (var targetWorkbook = new Workbook())
{
// Specify copy options if needed
targetWorkbook.Options.Copy.KeepSourceThemeColors = true;
targetWorkbook.Options.Copy.KeepSourceThemeFonts = true;
var targetWorksheet = targetWorkbook.Worksheets[0];
using (var sourceWorkbook = new Workbook())
{
// Load source worksheet
sourceWorkbook.LoadDocument("merge.xlsx");
int topRowIndex = 0;
foreach (var sourceWorksheet in sourceWorkbook.Worksheets)
{
if (!sourceWorksheet.HasData)
continue;
// Retrieve data from source worksheet
var sourceRange = sourceWorksheet.GetDataRange();
// Define target worksheet area to paste data
int rightColumnIndex = sourceRange.ColumnCount - 1;
int bottomRowIndex = topRowIndex + sourceRange.RowCount - 1;
var targetRange = targetWorksheet.Range.FromLTRB(0, topRowIndex,
rightColumnIndex, bottomRowIndex );
// Copy data from one worksheet to another
targetRange.CopyFrom(sourceRange, PasteSpecial.Values | PasteSpecial.Formats);
topRowIndex += sourceRange.RowCount;
}
}
targetWorkbook.SaveDocument("result.xlsx");
}
WinForms and WPF Spreadsheet Controls
PDF Document API
-
T1025879 - How to add a stamp to a PDF file
https://supportcenter.devexpress.com/ticket/details/t1025879
You can use the PDF Graphics API to draw an image (stamp) on a page. The code sample below draws an image in the corner of the page:
using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor())
{
// Load document
documentProcessor.LoadDocument("Document.pdf");
// Create PDF graphics
using (PdfGraphics graph = documentProcessor.CreateGraphics())
{
// Draw image
graph.DrawImage(File.ReadAllBytes("Documents//stamp.png"),
new System.Drawing.PointF(500, 50));
// Add image to the page foreground
graph.AddToPageForeground(documentProcessor.Document.Pages[0]);
}
// Save the result
documentProcessor.SaveDocument("result.pdf");
}
Note: We are going to enhance annotation support in our upcoming major release (v21.2). Our new API will allow you to add interactive rubber stamp annotations.
Enhancements
Spreadsheet Document API and Spreadsheet Controls (for WinForms and WPF)
PDF Document API
New Example: Word Processing Document API
This new example demonstrates how to use the Layout API to execute the following page actions:
- Get page text
- Get page number and page count
- Search for text on a specific page
Use the RichEditDocumentServer.DocumentLayout property as an entry point to the Layout API.
Layout API - How to perform page-based operations
As always, if you’ve come across an interesting support ticket you’d like to share with the rest of the DevExpress developer community, please comment below and include the appropriate link.
Free DevExpress Products – Get Your Copy Today
The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the
DevExpress Support Center at your convenience. We’ll be happy to follow-up.