What's new in 2018 Volume 4: File Format Libraries | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
what new file format 2018 volume 4

What’s new in 2018 Volume 4: File Format Libraries

Syncfusion is glad to share details about the updates in our file format libraries based on your valuable feedback. Our file format libraries allow users to create, edit, write, and convert ExcelPDFWord, and PowerPoint files in .NET Framework, .NET Core, Xamarin, and UWP applications without any Microsoft Office or Adobe dependencies.

In this blog, we’ll showcase the new features and enhancements included in the 2018 Volume 4 release of our file format libraries.

PDF

Draw text with OpenType fonts

OpenType is a cross-platform font format. It has an expanded character set, ligatures, glyph substitution, and layout features. The Syncfusion PDF library (Essential PDF) allows you to add text in PDF documents using OpenType fonts (OTF).

The following code example shows how to draw text in a PDF document using OTF.

//Create a new instance of PDF document class.
PdfDocument document = new PdfDocument();

//Add a new page to the document.
PdfPage page = document.Pages.Add();

//Text to draw.
string inputText = @"Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";

//Read the OTF font file from disk.
FileStream fontFileStream = new FileStream("NotoSerif-Black.otf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

//Create PDF font.
PdfFont font = new PdfTrueTypeFont(fontFileStream, 14);

//Draw the text.
page.Graphics.DrawString(inputText, font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height);

//Save the document.
document.Save("OpenTypeFont.pdf");

//Close the document.
document.Close(true);
PDF created with OpenType font
Using OTF in a PDF Document via the Syncfusion PDF Library

To learn more about drawing text in PDF documents, please refer to our Essential PDF documentation page, Drawing text in PDF.

Get certificate details from PDFs

Now you can retrieve or get certificate details like subject, issuer, valid from, valid to, and more from an existing PDF file. Using Essential PDF, we can re-sign a document based on the signature validity.

The following code example shows how to get certificate details to verify the document’s validity.

//Load the existing PDF document certificate.
PdfLoadedDocument ldoc = new PdfLoadedDocument(“Input.pdf”);

//Get the existing signature field.
PdfLoadedSignatureField field = ldoc.Form.Fields[0] as PdfLoadedSignatureField;

//Get the certificate details. 
var FromDate = field.Signature.Certificate.ValidFrom;
var ExpireDate = field.Signature.Certificate.ValidTo;

if (DateTime.Now > ExpireDate)
   {
      MessageBox.Show("Certificate was Expired.");
   }
else {
       MessageBox.Show("Certificate is Valid.");
   }
//Close the loaded document.
ldoc.Close(true);
PDF document certificate details
Retrieving PDF Document Certificate Details with Syncfusion PDF Library

Create PDF/A-1b document

Essential PDF already supported creating PDF/A-1b documents in .NET Framework platforms. Now, it is extended to be supported in Xamarin.Forms, .NET Core, and UWP.

The following code example shows how to create a PDF/A-1b-compliant document.

//Create a new PDF document.
PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A1B);

//Add a page.
PdfPage page = document.Pages.Add();

//Create font.
Stream arialFontStream = typeof(Conformance).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.arial.ttf");

PdfFont font = new PdfTrueTypeFont(arialFontStream, 14);

//Text to draw.
string text = @"Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";
                        
//Draw text.
page.Graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(0,0, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height));

MemoryStream stream = new MemoryStream();

//Save the PDF document.
document.Save(stream);

//Close the PDF document.
document.Close();
PDF-A1B creation in .NET Core and Xamarin
PDF/A-1b-Compliant Document Created with Syncfusion PDF Library

To learn more about PDF conformance, please refer to our PDF conformance documentation page.

Excel

Convert Excel to PDF in .NET Core and Xamarin

Previously, the Syncfusion Excel library (Essential XlsIO) supported Excel-to-PDF conversion only in .NET Framework applications. Now, we have added support for Excel-to-PDF conversion from .NET Standard 1.4 onwards. You can convert entire workbook or a particular worksheet to PDF. With this support, now XlsIO converts Excel documents into PDF in ASP.NET Core, and Xamarin platforms.

To use Excel-to-PDF conversion in your application, you can install the NuGet packages from NuGet.org:

The following code illustrates exporting an Excel file to PDF.

class Program
{
    static void Main(string[] args)
    {
      using (ExcelEngine excelEngine = new ExcelEngine())
      {
IApplication application = excelEngine.Excel;

//Open the file as a stream.
FileStream XlsIOStream = new FileStream("Template.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(XlsIOStream);

// Creates an instance of XlsIORenderer for Excel-to-PDF conversion.
XlsIORenderer renderer = new XlsIORenderer();

//Convert the workbook to PDF.
PdfDocument document = renderer.ConvertToPDF(workbook);

//Saving the PDF as a stream.
FileStream stream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite);
document.Save(stream);

stream.Dispose();
XlsIOStream.Dispose();
document.Close();
      }
    }
}

For example, the following code converts an entire Excel file with renderer settings to PDF.

class Program
{
    static void Main(string[] args)
    {
      using (ExcelEngine excelEngine = new ExcelEngine())
      {
IApplication application = excelEngine.Excel;

//Open the file as a stream.
FileStream XlsIOStream = new FileStream("Template.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(XlsIOStream);

// Creates an instance of XlsIORenderer for Excel-to-PDF conversion.
XlsIORenderer renderer = new XlsIORenderer();

XlsIORendererSettings settings = new XlsIORendererSettings();
// Lay out the page using FitAllColumnsOnOnePage option.
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;

//Convert the workbook to PDF.
PdfDocument document = renderer.ConvertToPDF(workbook, settings);

//Saving the PDF as a stream.
FileStream stream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite);
document.Save(stream);

stream.Dispose();
XlsIOStream.Dispose();
        document.Close();
      }
    }
}

The following code illustrates exporting an Excel worksheet with renderer settings to PDF.

class Program
{
    static void Main(string[] args)
    {
      using (ExcelEngine excelEngine = new ExcelEngine())
      {
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;

//Open the file as a stream.
FileStream XlsIOStream = new FileStream("Template.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(XlsIOStream);
IWorksheet worksheet = workbook.Worksheets[0];

// Creates an instance of XlsIORenderer for Excel-to-PDF conversion.
XlsIORenderer renderer = new XlsIORenderer();

XlsIORendererSettings settings = new XlsIORendererSettings();
// Lay out the page using FitAllColumnsOnOnePage options.
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;

//Convert the workbook to PDF.
PdfDocument document = renderer.ConvertToPDF(worksheet, settings);

//Saving the PDF as a stream.
FileStream stream = new FileStream("Output.pdf", FileMode.Create, FileAccess.ReadWrite);
document.Save(stream);

stream.Dispose();
XlsIOStream.Dispose();
document.Close();
}
    }
}
Excel to PDF in .NET Core and Xamarin
Excel Workbook Converted to PDF via Syncfusion Excel and PDF Libraries

For more information, please refer to our Excel-to-PDF conversion documentation.

Word

Restart numbering in lists

The Syncfusion Word library (Essential DocIO) now allows numbering in lists to be restarted in Word documents while performing mail merge and merging multiple Word documents.

Restart list number when performing mail merge
Numbered Lists with Restarted Numbering in a Word Document

The following code example illustrates how to restart the list numberings in Word documents while performing mail merge and merging multiple Word documents.

FileStream fileStream = new FileStream("Template.docx", FileMode.Open);
//Loads an existing Word document.
WordDocument wordDocument = new WordDocument(fileStream, FormatType.Docx);
//Sets ImportOptions to restart the list numbering.
wordDocument.ImportOptions = ImportOptions.ListRestartNumbering;
//Creates the employee details as “IEnumerable” collection.
List employeeList = new List();
employeeList.Add(new Employee("101", "Nancy Davolio", "Seattle, WA, USA"));
employeeList.Add(new Employee("102", "Andrew Fuller", "Tacoma, WA, USA"));
employeeList.Add(new Employee("103", "Janet Leverling", "Kirkland, WA, USA"));
//Creates an instance of “MailMergeDataTable” by specifying mail merge group name and “IEnumerable” collection.
MailMergeDataTable dataTable = new MailMergeDataTable("Employees", employeeList);
//Performs mail merge.
wordDocument.MailMerge.ExecuteGroup(dataTable);
//Saves the Word document.
MemoryStream outputStream = new MemoryStream();
wordDocument.Save(outputStream, FormatType.Docx);
//Closes the instance of Word document object.
wordDocument.Close();

///
/// Represents a helper class to perform mail merge.
///
public class Employee { public string EmployeeID { get; set; } public string EmployeeName { get; set; } public string Location { get; set; } 
///
/// Represents a constructor to create value for merge fields.
//
public Employee(string employeeId, string employeeName, string location) { EmployeeID = employeeId; EmployeeName = employeeName; Location = location; } }

Update field enhancements

Essential DocIO now allows updating the AutoNum and Set fields in a Word document.

Hyphenation in Word-to-PDF and Word-to-image conversions

Essential DocIO now allows hyphenating text in a Word document while converting it to PDF or image formats.

hypenation support in Word to PDF conversion c#
Hyphenation in a Word Document converted to PDF

The following code example illustrates setting the hyphenation properties during Word-to-PDF conversion.

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();
//Reads the language dictionary for hyphenation.
FileStream dictionaryStream = new FileStream("hyph_en_US.dic", FileMode.Open);
//Adds the hyphenation dictionary of the specified language.
Hyphenator.Dictionaries.Add("en-US", dictionaryStream);
//Converts Word document to 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();

Track changes in Word-to-PDF conversion

Essential DocIO now allows showing revision marks in a generated PDF when converting Word documents with tracked changes or revisions.

Word-to-pdf with track changes
Tracked Changes Displayed in a Converted PDF Document

The following code example illustrates setting these properties during Word-to-PDF conversion.

FileStream fileStream = new FileStream("Template.docx", FileMode.Open);
//Loads an existing Word document.
WordDocument wordDocument = new WordDocument(fileStream, FormatType.Docx);
//Sets revision types to preserve track changes in Word-to-PDF conversion.
wordDocument.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Formatting | RevisionType.Insertions;
//Instantiates DocIORenderer instance for Word-to-PDF conversion.
DocIORenderer renderer = new DocIORenderer();
//Converts Word document into PDF document.
PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument);
//Closes the instance of the 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();

Word-to-PDF enhancements in ASP.NET Core and Xamarin platforms

Essential DocIO now provides the following features during Word-to-PDF conversion:

  • 30% improvement in conversion performance.
  • Improvements in text size calculation to paginate Word documents properly.
  • Preservation of rotated images.
  • Option to embed complete or subset font information for TrueType fonts.
  • PDF conformance levels PDF/A1B and PDF/X-1a:2001.
  • Preservation of complex script text.

The following code example illustrates how to set the font embedding and PDF conformance level options during Word-to-PDF conversion 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();
//Sets EmbedFonts property as true to embed fonts in resultant PDF.
renderer.Settings.EmbedFonts = true;
//Sets EmbedCompleteFonts property as true to embed complete font information in converted PDF.
renderer.Settings.EmbedCompleteFonts = true;
//Sets PDF conformance level PDF/A1B or PDF/X-1a:2001 for long-term archiving.
renderer.Settings.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1B;
//Sets AutoDetectComplexScript property as true to detect complex scripts automatically.
renderer.Settings.AutoDetectComplexScript = true;
//Converts Word document to 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();

PowerPoint

Connector

A connector is a line that links two shapes via their port positions which will automatically adjust its position when those shapes move. Each shape object has a different number of port points and that can be linked with a connector.

Connectors can be any of the following types and they are:

  • Straight
  • Elbow
  • Curved

The Syncfusion PowerPoint library (Essential Presentation) provides support to add, edit, remove, format, and convert all three types of connectors in PowerPoint files.

The following code example shows how to draw a connector between two shapes.

// Create a new PowerPoint file.
using (IPresentation ppDocument = Presentation.Create())
{

  // Add a slide to the PowerPoint file.
  ISlide slide = ppDocument.Slides.Add(SlideLayoutType.Blank);

  // Add a rectangle to the slide.
  IShape rectangle = slide.Shapes.AddShape(AutoShapeType.Rectangle, 200, 300, 100, 100);

  // Add an oval to the slide.
  IShape oval = slide.Shapes.AddShape(AutoShapeType.Oval, 400, 10, 100, 100);

  // Add a connector and connect the start and end shapes with specified port positions.
  IConnector connector = slide.Shapes.AddConnector(ConnectorType.Straight, rectangle, 0, oval, 4);

  // Save the presentation file.
  ppDocument.Save("Sample.pptx");
}
PowerPoint Presentation with Connectors between Shapes
PowerPoint Presentation with Connectors between Shapes

Shrink text on overflow

In a PowerPoint slide, if you add more text than a shape can hold, the text will overflow beyond the boundaries of the shape. By using a “shrink text on overflow” option, you can fit longer text within a shape. This option will reduce the font size and line spacing values of the text so that it fits within the shape. The Syncfusion PowerPoint library now provides support for shrinking text on overflow. The following screenshot shows how to enable this property in Microsoft PowerPoint.

Shrink Text on Overflow Option in PowerPoint
Enabling Shrink Text on Overflow Option in PowerPoint

The following code example shows how to enable the ShrinkTextOnOverFlow property for a text box using the Syncfusion PowerPoint library.

// Create a new PowerPoint file.
using (IPresentation ppDocument = Presentation.Create())
{

    // Add a slide to the PowerPoint file.
    ISlide slide = ppDocument.Slides.Add(SlideLayoutType.Blank);

    // Add a text box to the slide
   IShape textBox = slide.Shapes.AddTextBox(100, 100, 100, 100);

   //Add text to the text box. 
   textBox.TextBody.AddParagraph("AdventureWorks Database is a product sample for an online transaction processing database");

   //Set the property to shrink text on overflow. 
   textBox.TextBody.FitTextOption = FitTextOption.ShrinkTextOnOverFlow;

   // Save the PowerPoint file.
   ppDocument.Save("Sample.pptx");
}

Try it out

If you are an existing Syncfusion user, please download the latest version from the License & Downloads page and try the new features for yourself. Also, our NuGet packages are available on NuGet.org. If you aren’t a customer yet, you can try our 30-day free trial to check out these features.

If you are new to Syncfusion’s file format libraries, we highly recommend that you follow our user guide. In order to get started quickly with your 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!

If you liked this post, we think you will also enjoy the following:

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed