Syncfusion 2019 Volume 1 (version 17.1) release introduces exciting new features and improvements aimed at making document processing easier with its file-format libraries. Syncfusion’s file format libraries allow users to create, read, edit, and convert Excel, PDF, Word, and PowerPoint files in .NET applications without the need of Microsoft Office or Adobe dependencies.
In this blog, we will describe in detail the newly added features and enhancements.
ZUGFeRD is an electronic billing data format for exchanging invoices. It consists of two parts: a pictorial or textual representation of the invoice for human reading and machine-readable structured data. Therefore, it helps to automate the reading and processing of invoices. The machine-readable structured data in XML format is attached to the PDF/A-3 document. The Syncfusion PDF Library now supports creating ZUGFeRD PDF invoice documents.
The following code example illustrates how to create a ZUGFeRD PDF invoice using Syncfusion PDF Library.
//Create ZUGfeRD invoice PDF PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A3B); document.ZugferdConformanceLevel = ZugferdConformanceLevel.Basic; //Creates an PDF attachment. //Important Note: XML name must be as “ZUGFeRD-invoice.xml” PdfAttachment attachment = new PdfAttachment("ZUGFeRD-invoice.xml","../../Data/ZUGFeRD-invoice.xml"); attachment.Relationship = PdfAttachmentRelationship.Alternative; attachment.ModificationDate = DateTime.Now; attachment.Description = "ZUGFeRD-invoice"; attachment.MimeType = "application/xml"; document.Attachments.Add(attachment); // save and close the document. document.Save("Zugferd.pdf"); document.Close(true);
For more information on creating ZUGFeRD PDF invoices, please refer to our documentation page—Generating ZUGFeRD invoice.
Syncfusion PDF Library already supports creating PDF/A-1b-conforming documents. In addition, you can create PDF document from scratch with conformance of PDF/A-2b (ISO 19005-2) and PDF/A-3b (ISO 19005-3), now.
To learn more about PDF conformance, please refer to our documentation page—PDF Conformance.
Syncfusion PDF Library already supports creating and filling XFA form fields in the .NET Framework. Now, that support extends to the .NET core platform, as well. Using this, you can create rich-looking XFA forms and fill any XFA documents in .NET Core and Xamarin applications.
The following code example shows how to fill XFA form fields in an existing PDF document.
//Load the PDF file with XFA form as stream. FileStream file1 = new FileStream(dataPath + "xfaTemplate.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); PdfLoadedXfaDocument ldoc = new PdfLoadedXfaDocument(inputPdfFileStream); //Loaded the existing XFA form. PdfLoadedXfaForm lform = ldoc.XfaForm; //Fill the XFA form fields. (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["title[0]"] as PdfLoadedXfaComboBoxField).SelectedIndex = 0; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["fn[0]"] as PdfLoadedXfaTextBoxField).Text = "Simons"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["ln[0]"] as PdfLoadedXfaTextBoxField).Text = "Bistro"; MemoryStream ms = new MemoryStream(); //save and close the document. ldoc.Save(ms); ldoc.Close();
To find further information about XFA creation and filling, please check our documentation page—Working with XFA.
Syncfusion PDF Library let’s you retrieve annotation review status and comments from the reviewed PDF document.
//Load the existing PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf"); //Get the existing PDF page. PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage; //Get the annotation. PdfLoadedTextMarkupAnnotation loadedMarkup = loadedPage.Annotations[0] as PdfLoadedTextMarkupAnnotation; //Get the review history collection for the annotation. PdfLoadedPopupAnnotationCollection reviewCollection = loadedMarkup.ReviewHistory; //Get the annotation state. PdfAnnotationState state = reviewCollection[0].State; //Get the annotation state model. PdfAnnotationStateModel model = reviewCollection[0].StateModel; //Get the comments of the annotation. PdfLoadedPopupAnnotationCollection commentsCollection = loadedMarkup.Comments; //Get the review history of the comment. PdfLoadedPopupAnnotationCollection reviewCollection1 = commentsCollection[0].ReviewHistory; //Close the PDF document. loadedDocument.Close(true);
FDF (Forms Data Format)/XFDF (XML based FDF) is a format for representing forms and annotations data. Annotations and their comments can be exported or imported from PDF documents. It will be easier for users to manipulate the annotations in a separate file or format. We have added support for importing and exporting annotation data to XFDF/FDF format.
The following is a code example for exporting annotations to FDF and XFDF format.
//Load an existing PDF document. PdfLoadedDocument document = new PdfLoadedDocument(@"..\..\Data\Annotations.pdf"); //Export annotation to FDF format. document.ExportAnnotations(@"Annotations.fdf", AnnotationDataFormat.Fdf); //Close the PDF document. document.Close(true);
The following is a code example for importing annotations to FDF format data:
//Load an existing PDF document. PdfLoadedDocument document = new PdfLoadedDocument(@"EmptyTemplate.pdf"); //Import annotation data from FDF/XFDF file. document.ImportAnnotations(@"Annotations.fdf", AnnotationDataFormat.Fdf); //Save and close the document. document.Save(@"Annotations.pdf"); document.Close(true);
The Syncfusion Excel Library (XlsIO) now supports converting an Excel chart to an image in .NET Core and Xamarin applications. All 2D and 3D charts can be converted, along with their elements such as chart titles, axis titles, data labels, and legends. The charts can be converted to JPEG and PNG.
The following C# example shows how to convert an Excel chart to an image.
//Create Excel engine using (ExcelEngine excelEngine = new ExcelEngine()) { //Instantiate the application and Excel renderer objects. IApplication application = excelEngine.Excel; application.XlsIORenderer = new XlsIORenderer(); application.XlsIORenderer.ChartRenderingOptions.ImageFormat = ExportImageFormat.Png; //Open an Excel file with chart. IWorkbook workbook = application.Workbooks.Open(File.OpenRead("Sample.xlsx")); IWorksheet worksheet = workbook.Worksheets[0]; IChart chart = worksheet.Charts[0]; //Create the memory stream for saving chart image. Stream stream = new FileStream("chart.png", FileMode.Create, FileAccess.ReadWrite); //Convert chart to image. chart.SaveAsImage(stream); stream.Dispose(); }
The Syncfusion Excel (XlsIO) Library now provides the following improvements in Excel-to-PDF conversion:
The following code example illustrates how to convert an Excel file to PDF
using (ExcelEngine engine = new ExcelEngine()) { IApplication application = engine.Excel; application.DefaultVersion = ExcelVersion.Excel2016; //Initialize the Excel renderer class to convert Excel charts with PDF conversion. XlsIORenderer renderer = new XlsIORenderer(); Stream fileStream = File.OpenRead("Sample.xlsx"); IWorkbook workbook = application.Workbooks.Open(fileStream); Stream stream = File.Create("output.pdf"); PdfDocument pdf = renderer.ConvertToPDF(workbook); pdf.Save(stream); pdf.Close(); stream.Dispose(); }
To know more about Excel-to-PDF conversion, please refer to our documentation pages—Excel-to-PDF conversion and convert Excel-to-PDF with conformance level.
Syncfusion Excel Library has the support to apply formatting to Excel tables using built-in table styles. From this release, you can create your own table style and apply it to Excel tables, too.
The following code example illustrates how to create a new table style and apply it.
//Create Excel engine instance. using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; //Open an existing Excel file with data. IWorkbook workbook = application.Workbooks.Open(File.Open("Sample.xlsx", FileMode.Open)); IWorksheet worksheet = workbook.Worksheets[0]; //Create style for table number format. IStyle style = workbook.Styles.Add("CurrencyFormat"); style.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* \" - \"??_);_(@_)"; worksheet["B2:E8"].CellStyleName = "CurrencyFormat"; //Create table instance. IListObject table = worksheet.ListObjects.Create("Table1", worksheet["A1:E7"]); //Create and apply custom table style. ITableStyles tableStyles = workbook.TableStyles; ITableStyle tableStyle = tableStyles.Add("Table Style 1"); ITableStyleElements tableStyleElements = tableStyle.TableStyleElements; ITableStyleElement tableStyleElement = tableStyleElements.Add(ExcelTableStyleElementType.SecondColumnStripe); tableStyleElement.BackColorRGB = Color.FromArgb(217, 225, 242); ITableStyleElement tableStyleElement1 = tableStyleElements.Add(ExcelTableStyleElementType.FirstColumn); tableStyleElement1.FontColorRGB = Color.FromArgb(128, 128, 128); ITableStyleElement tableStyleElement2 = tableStyleElements.Add(ExcelTableStyleElementType.HeaderRow); tableStyleElement2.FontColor = ExcelKnownColors.White; tableStyleElement2.BackColorRGB = Color.FromArgb(0, 112, 192); ITableStyleElement tableStyleElement3 = tableStyleElements.Add(ExcelTableStyleElementType.TotalRow); tableStyleElement3.BackColorRGB = Color.FromArgb(0, 112, 192); tableStyleElement3.FontColor = ExcelKnownColors.White; table.TableStyleName = tableStyle.Name; table.ShowTotals = true; table.ShowFirstColumn = true; table.ShowTableStyleColumnStripes = true; table.ShowTableStyleRowStripes = true; table.Columns[0].TotalsRowLabel = "Total"; table.Columns[1].TotalsCalculation = ExcelTotalsCalculation.Sum; table.Columns[2].TotalsCalculation = ExcelTotalsCalculation.Sum; table.Columns[3].TotalsCalculation = ExcelTotalsCalculation.Sum; table.Columns[4].TotalsCalculation = ExcelTotalsCalculation.Sum; //Save the workbook. workbook.SaveAs("CustomTableStyle.xlsx"); }
Now, Syncfusion Excel Library supports applying formatting for unique and duplicate values in Excel worksheets through conditional formatting. This conditional formatting enhancement is supported with Excel-to-PDF conversion, as well.
using (ExcelEngine engine = new ExcelEngine()) { IApplication application = engine.Excel; IWorkbook workbook = application.Workbooks.Open("Sample.xlsx"); IWorksheet worksheet = workbook.Worksheets[0]; //conditional format to choose single range. IConditionalFormats conditionformat1 = worksheet.Range["C5:C50"].ConditionalFormats; IConditionalFormat condition1 = conditionformat1.AddCondition(); condition1.FormatType = ExcelCFType. Duplicate; condition1.BackColor = ExcelKnownColors.Light_pink; //Save as file in xlsx format workbook.SaveAs("xml.xlsx"); }
The Syncfusion Word (DocIO) library now provides the following improvements in Word-to-PDF conversion with .NET Core and Xamarin platforms:
The following code example illustrates how to convert a Word document to PDF with charts in ASP.NET Core and Xamarin platforms.
FileStream fileStream = new FileStream("Template.docx", FileMode.Open); //Loads an existing Word document. WordDocument wordDocument = new WordDocument(fileStream, FormatType.Docx); //Instantiates DocIORenderer instance for Word-to-PDF conversion. DocIORenderer renderer = new DocIORenderer(); //Set the chart-rendering options to export chart as PNG format image. renderer.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Png; //Converts Word document into PDF document. PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument); //Closes the instance of Word document object. wordDocument.Close(); //Releases the resources occupied by DocIORenderer instance. renderer.Dispose(); //Saves the PDF file. MemoryStream outputStream = new MemoryStream(); pdfDocument.Save(outputStream); //Closes the instance of PDF document object. pdfDocument.Close();
The charts in a Word document can be converted to JPEG or PNG images in .NET Core and Xamarin applications. All 2D and 3D charts can be converted along with their elements.
FileStream fileStream = new FileStream("Template.docx", FileMode.Open); //Loads an existing Word document. WordDocument wordDocument = new WordDocument(fileStream, FormatType.Docx); //Instantiates DocIORenderer instance for Word-to-PDF conversion. DocIORenderer renderer = new DocIORenderer(); //Sets chart-rendering options to export chart as PNG format image. renderer.Settings.ChartRenderingOptions.ImageFormat = ExportImageFormat.Png; //Converts chart to image and saves to stream. MemoryStream outputStream = new MemoryStream(); renderer.SaveChartAsImage((wordDocument.LastParagraph.ChildEntities[0] as WChart).OfficeChart, outputStream); //Closes the instance of Word document object. wordDocument.Close(); //Releases the resources occupied by DocIORenderer instance. renderer.Dispose();
The Syncfusion PowerPoint Library now supports the conversion of PowerPoint to PDF in .NET Core and Xamarin platforms with the following customization options:
To use PowerPoint-to-PDF conversion in your application, you can install the following NuGet packages from NuGet.org:
The following code describes how to convert a PowerPoint file to PDF.
//include these namespaces to perform PPTX-to-PDF conversion. using Syncfusion.Pdf; using Syncfusion.Presentation; using Syncfusion.PresentationToPdfConverter; using System.IO; //Loads the PowerPoint presentation into stream. using (FileStream fileStreamInput = new FileStream(@"Template.pptx", FileMode.Open, FileAccess.Read)) { //Open the existing PowerPoint presentation with loaded stream. using (IPresentation pptxDoc = Presentation.Open(fileStreamInput)) { //Create the MemoryStream to save the converted PDF. using (MemoryStream pdfStream = new MemoryStream()) { //Convert the PowerPoint document to a PDF document. using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { //Save the converted PDF document to MemoryStream. pdfDocument.Save(pdfStream); pdfStream.Position = 0; } //Create the output PDF file stream. using (FileStream fileStreamOutput = File.Create("Output.pdf")) { //Copy the converted PDF stream into created output PDF stream. pdfStream.CopyTo(fileStreamOutput); } } } }
From this release (v17.1) onwards, a PowerPoint slide can be converted to an image (JPEG or PNG) in .NET Core and Xamarin applications.
The following code shows how to convert a PowerPoint slide to an image.
//Namespaces to perform PPTX-to-Image conversion. using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; using System.IO; //Load the PowerPoint presentation into stream. using (FileStream fileStreamInput = new FileStream(@"Template.pptx", FileMode.Open, FileAccess.Read)) { //Open the existing PowerPoint presentation with stream. using (IPresentation pptxDoc = Presentation.Open(fileStreamInput)) { //Initialize the PresentationRenderer to perform image conversion. pptxDoc.PresentationRenderer = new PresentationRenderer(); //Convert PowerPoint slide to image as stream. using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) { //Reset the stream position. stream.Position = 0; //Create the output image file stream. using (FileStream fileStreamOutput = File.Create("Output.jpg")) { //Copy the converted image stream into created output stream. stream.CopyTo(fileStreamOutput); } } } }
You can refer to our documentation pages for more information: PowerPoint-to-PDF conversion and PowerPoint-to-image conversion.
We hope you’ll like these new features and enhancements included in the 2019 volume 1 release. If you’d like to play around with these new features yourself, please download the latest version from the license and downloads page. Or you can get our NuGet packages from NuGet.org.
If you are new to Syncfusion’s file format libraries, we highly recommend that you follow our user guide. To get started with a desired file format, please follow these links:
If you have any questions or require clarification on these features, please let us know in the comments below. You can also contact us through our support forum or Direct-Trac. We are happy to assist you!