Convert Word DOC/DOCX to PDF Programmatically in Java

Convert Word to PDF in Java

Word to PDF conversion is commonly used before the documents are shared. Various online Word to PDF converters are available that allow you to convert single or a limited number of Word documents. However, with emerging MS Word automation and report generation solutions, automated Word to PDF conversion has become an essential part of the systems. Furthermore, the batch conversion of DOC/DOCX to PDF needs to be done automatically to minimize the time and efforts. Keeping an eye on such scenarios, I’ll show you how to automate the process of converting Word (DOC/DOCX) documents to PDF programmatically in Java.

Word to PDF Conversion Scenarios

You’ll learn about the following Word (DOC/DOCX) to PDF conversions in this article.

  • Convert a Word document to PDF in Java.
  • Convert selected pages of a Word DOC/DOCX to PDF in Java.
  • Convert Word to PDF with a specific PDF Standard such as PDF 1.5, PDF/A-1a, etc.
  • Convert Word to PDF with image/text compression in Java.
  • Convert Word to PDF with the customized JPEG quality for images in Java.

Java Word API for Word to PDF Conversion

For converting Word documents to PDF, we’ll use Aspose.Words for Java which is a powerful Word automation API for working with popular Word document formats. You can either download Aspose.Words for Java or install it in your Maven-based application using the following configurations.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

Dependency

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>20.1</version>
    <classifier>jdk17</classifier>
</dependency>

Convert Word (DOC/DOCX) to PDF in Java

In order to convert a Word document to PDF, Aspose.Words for Java provides save() method of the Document class. You can simply load the Word document and call this method by specifying the output file name with the “.pdf” extension.

The following code sample shows how to convert a Word DOC to PDF in Java.

Word Document

DOC DOCX to PDF in Java

PDF Document

DOC/DOCX to PDF

Convert Selected Pages of Word DOC/DOCX to PDF in Java

In case you want to convert only selective pages of Word to PDF, You can do it using the PdfSaveOptions class. You can either convert first N pages or a range of pages by specifying the starting page’s index.

The following code sample shows how to convert selected pages of Word DOC/DOCX to PDF in Java.

Convert Word DOC/DOCX to Particular PDF Standard in Java

There exist various PDF standards a PDF document may compliant with, such as PDF/A-1a, PDF 1.5, etc. In case you want to convert Word document to a specific PDF standard, you can specify it using PdfCompliance.

The following code sample shows how to convert Word DOCX to PDF with a particular PDF standard in Java.

Convert Word to PDF with Text or Image Compression in Java

You can also reduce the size of the resultant PDF document by compressing the text or image in the Word document. You can apply the following compressions in Word to PDF conversion using Aspose.Words for Java.

Text Compression Options

Aspose.Words for Java provides PdfTextCompression class with the following text compression options:

  • None: No text compression.
  • Flate: Flate (ZIP) compression.

Image Compression

The image compression options are available in the PdfImageCompression class.

  • Auto: The most appropriate compression for every image is selected automatically.
  • Jpeg: Images are converted to JPEG format (does not support transparency).

The following code sample shows how to convert Word DOCX to PDF by applying text and image compression in Java.

Convert Word to PDF with JPEG Quality in Java

You can also customize and control the JPEG quality in Word to PDF conversion. The PdfSaveOptions.setJpegQuality is used to set JPEG quality which can be from 0 (worst quality with maximum compression) to 100 (best quality with minimum compression).

The following code sample shows how to specify JPEG quality while converting Word DOCX to PDF in Java.

Try Aspose.Words for Java for Free

You can get a free temporary license to try and use Aspose.Words for Java.

Posted in Aspose.Words Product Family | Tagged , , , | Leave a comment

Read, Add, Update or Remove Slide Notes in PowerPoint Presentations using C#

read add update and remove slide notes in PowerPoint using C# .NET

Slide notes in the PowerPoint presentations are used to add references for the presenter to recall the important points during the presentation. These notes can be added to every slide of a PowerPoint presentation. This article also covers some important aspects of dealing with slide notes in presentations programmatically.

After reading this article, you will be able to:

  • read slide notes in PowerPoint presentation using C#,
  • add slide notes to a PowerPoint presentation in C#,
  • update notes in a particular slide of the PowerPoint presentation in C#, and
  • remove slide notes in a PowerPoint presentation using C#.

Working with Slide Notes using Aspose.Slides for .NET

In order to work with slide notes in PowerPoint, we’ll use Aspose.Slides for .NET – a powerful PowerPoint automation API that supports creating, updating, parsing and converting presentation documents. You can download the API or install it using the following options:

Using NuGet Package Manager

read or update slide notes in PowerPoint C# .NET

Using the Package Manager Console

PM> Install-Package Aspose.Slides.NET

Read Slide Notes from PowerPoint Presentation in C#

In order to access the slide notes in PowerPoint, Aspose.Slides for .NET provides INotesSlideManager interface. INotesSlideManager lets you access, read, add and update the slide notes. The following are the steps to read the slide notes from the PowerPoint presentation.

The following code sample shows how to read slide notes from a PowerPoint PPTX using C#.

Add Notes to a PowerPoint Slide in C#

The following are the steps to add notes to a particular slide in a PowerPoint presentation.

  • Load the PowerPoint presentation in the Presentation object.
  • Access the NotesSlideManager of particular slide.
  • Use the INotesSlide interface to add a new note.
  • Save the presentation using Presentation.Save(String, SaveFormat) method.

The following code sample shows how to add slide notes to a PowerPoint PPTX using C#.

Update Slide Notes in PowerPoint Presentation using C#

In order to update the notes in a particular presentation slide, you will access the NotesSlide in the same way you have done for reading the notes. Once you have got access to the slide notes, you can simply update the text using INotesSlide.NotesTextFrame.Text property. Once done, save the presentation file using the Presentation.Save(String, SaveFormat) method.

The following code sample shows how to update slide notes in a PowerPoint presentation using C#.

Remove Slide Notes in PowerPoint Presentation using C#

To remove the slide notes from a PowerPoint presentation, simply call INotesSlideManager.RemoveNotesSlide() method and save the presentation file. The following code sample shows how to remove slide notes from a PowerPoint presentation using C#.

Try Aspose.Slides for .NET for Free

You can try Aspose.Slides for .NET using a free temporary license.

Posted in Aspose.Slides Product Family | Tagged , , , | Leave a comment

Find and Replace Text in Excel Spreadsheets using C#

The Excel spreadsheets have minimized the efforts required to keep the huge data and perform complex calculations automatically. Excel automation was the next big achievement that has streamlined the way of creating Excel spreadsheets and performing a variety of operations on the data programmatically.

Finding and replacing text in Excel is one of the frequently performed operations in Excel automation. Therefore, in this article, I will show you how to find and replace a particular text in large Excel spreadsheets programmatically in C# with a few lines of code. Ultimately, you will learn how to:

  • Find and replace text in Excel Workbook in C#
  • Find and replace text in Excel Workbook using regular expression (Regex) in C#

API for Finding and Replacing Text in Excel Workbooks

Aspose.Cells for .NET is a powerful API that allows you to completely automate the process of creating, editing, parsing and converting the Excel spreadsheet programmatically. The API also provides easy ways of finding and replacing text based on the plain text as well as regular expressions (regex). You can either download the API or install it in your application via NuGet Package Manager or Package Manager Console.

NuGet Package Manager

Find and replace text with regex in Excel

Package Manager Console

PM> Install-Package Aspose.Cells

Find and Replace Text in Excel using C#

The following is the simple recipe to find and replace text in an Excel workbook using Aspose.Cells for .NET.

The following code sample shows how to find and replace text in Excel using C#.

Find and Replace Text with Regex in Excel using C#

You can also find and replace text that matches a particular pattern, such as Email IDs, SSN, etc. In order to do that, just set the ReplaceOptions.RegexKey property to true and call Workbook.Replace(String, String, ReplaceOptions) method.

The following code sample shows how to find and replace the text with regex in the Excel workbook.

Try Aspose.Cell for .NET for Free

Get a free temporary license of Aspose.Cells for .NET and enjoy its powerful features.

Posted in Aspose.Cells Product Family | Tagged , , | Leave a comment

Create, Edit, Read and Convert SVG Files using C# – Aspose.SVG for .NET

C# SVG API, Create edit convert SVG files

Its time to announce the addition of a new API to our product line – Aspose.SVG for .NET. A .NET class library that lets you create, edit, read and convert SVG files programmatically using C# in .NET or .NET Core based applications. Let’s have a quick walk through the installation methods and salient features of the API.

Aspose.SVG for .NET – Installation

Aspose.SVG for .NET DLL can be downloaded from our Downloads section. On the other hand, you can install it via NuGet Package Manager or the Package Manager Console in Visual Studio.

NuGet Package Manager

C# .NET SVG API

Package Manager Console

PM> Install-Package Aspose.SVG

Let’s now have a glance at some salient features of the API to deal with SVG files.

Create a New SVG File using C#

Aspose.SVG for .NET lets you create an empty file having an SVG structure. Furthermore, you can also create an SVG file from a user-defined string. The API provides SVGDocument class to create SVG files and you can further use this object to fill the document with SVG elements. Once done, you can save the file using SVGDocument.Save() method. The following code samples show how to create an SVG file from scratch.

Create Empty SVG File in C#

Create SVG with User Defined String in C#

Edit SVG Files in C#

Aspose.SVG for .NET also allows you to edit the SVG files to update their content. The API’s Data Object Model efficiently maps the official specifications of SVG to access and edit SVG nodes and their elements. The following code sample shows how to edit an SVG file in C#.

Read SVG Files in C#

In case you would want to read an existing SVG file, you can load it using the SVGDocument class. Simply create a new object and initialize it with SVG file’s path as shown in the following code sample.

Convert SVG Files to Other Formats

You can also convert the SVG files to various other file formats. The supported conversions include:

  • SVG to PDF
  • SVG to XPS
  • SVG to Image (JPEG, PNG, BMP, GIF, TIFF)

The following code sample shows how to convert an SVG file to PDF in C#.

For code samples of SVG to XPS and SVG to image, please visit Converting SVG Files in C#.

You can evaluate the API’s features by downloading the examples project. For more details, consult the documentation of the API. In case you would have any questions or queries, feel free to let us know via our forum.

Posted in Aspose.SVG Product Family | Tagged , , , , | Leave a comment

Convert PowerPoint PPT or PPTX to PDF using C#

PowerPoint PPT PPTX to PDF

Are you looking for a reliable yet easy solution for converting PowerPoint PPT/PPTX to PDF? Do you want to accurately convert PowerPoint presentations to PDF with high quality? If yes then you are at the right place because, in this article, I am going to showcase a bunch of features to seamlessly convert PowerPoint PPT to PDF or PPTX to PDF programmatically in C#.

This article is composed of the following PowerPoint to PDF conversion features.

  • Convert PowerPoint (PPT or PPTX) to PDF in C#
  • Customized conversion of PPT or PPTX to PDF
  • Convert hidden slides in PPT or PPTX to PDF
  • Convert particular slides of PowerPoint presentation to PDF
  • Convert PowerPoint presentation to a password-protected PDF with desired access permissions

Prerequisite for PowerPoint to PDF Conversion in C#

Aspose.Slides for .NET is a powerful PowerPoint automation API to create, edit, parse and convert presentation documents and we’ll use this API throughout this article. You can install Aspose.Slides for .NET using one of the following ways in Visual Studio.

Installing via NuGet Package Manager

Installing via Package Manager Console

PM> Install-Package Aspose.Slides.NET

Convert PowerPoint PPT or PPTX to PDF in C#

The following are the simple steps to convert a PowerPoint presentation to PDF using Aspose.Slides for .NET.

The following code sample shows how to convert a PowerPoint PPT to PDF in C#.

Convert PPT or PPTX to PDF with Custom Options in C#

You can also customize PowerPoint to PDF conversion by defining different options such as Jpeg quality, text compression level, the behavior of metafiles and etc. You can set these options using the PdfOptions class.

The following code sample shows how to convert PowerPoint to PDF with custom options in C#.

Convert Hidden Slides of PowerPoint Presentation to PDF in C#

The PowerPoint presentations may also contain hidden slides. By default, hidden slides are not included in PPT/PPTX to PDF conversion. In case you want to convert a presentation including hidden slides, you can specify it using PdfOptions.ShowHiddenSlides property.

The following code sample shows how to convert a PowerPoint PPTX to PDF including hidden slides in C#.

Convert Selected Slides of PowerPoint PPT/PPTX to PDF in C#

Instead of converting the whole presentation, you can also convert the selected slides of the presentation to PDF. For this, you can define the integer array containing the slide numbers and then pass that array to the Save(String,Int32[], SaveFormat.Pdf) method.

The following code sample shows how to convert selected slides of PowerPoint PPT/PPTX to PDF in C#.

Convert PowerPoint PPT/PPTX to a Password-protected PDF with Access Permissions

PDF format supports setting the password and access permissions to protect the document. In case you want to apply such a protection mechanism while converting PowerPoint to PDF, you can do it using PdfOptions class.

The following code sample shows how to set a password and specify access permissions while converting PowerPoint PPTX to PDF in C#.

Try Aspose.Slides for .NET for Free

You can try and use Aspose.Slides for .NET for free by requesting a temporary license.

Posted in Aspose.Slides Product Family | Tagged , , | Leave a comment

Convert PowerPoint PPT/PPTX to JPG Images in C#

Convert PowerPoint to Image

There could be various scenarios when you need to convert PowerPoint (PPT or PPTX) slides to JPG images. For example, you may need to slide show the PPT/PPTX presentation in read-only mode within your application or you may want to generate the thumbnail for every slide of the PowerPoint presentation and etc. In order to automate PowerPoint to JPG conversion, I’ll show you how to convert PPT/PPTX slides to JPG images programmatically in C# .NET.

Converting PPT/PPTX to JPG Images in C#

In order to convert PPT/PPTX to JPG images, we’ll use Aspose.Slides for .NET which is a complete .NET package for PowerPoint automation. The API provides high-quality conversion of PowerPoint presentations to various file formats including JPG.

You can either download and reference the API’s DLL or install the package using NuGet Package Manager or Package Manager Console.

Using NuGet Package Manager

Using the Package Manager Console

PM> Install-Package Aspose.Slides

Convert PowerPoint PPT to JPG in C#

The following are the steps to convert PPT to JPG using Aspose.Slides for .NET.

The following code sample shows how to convert PPT to JPG images in C#.

PowerPoint Presentation

PowerPoint to JPG Images in C#

Converted JPG Images

PPT PPTX to JPG images in C#

Convert PowerPoint PPTX to JPG with Customized Dimensions in C#

You may also customize the dimensions of the JPG images as per your requirements. The following code sample shows how to define ScaleX and ScaleY values while converting PPTX to JPG in C#.

Get a Free Temporary License for Aspose.Slides for .NET

You can get a free temporary license for Aspose.Slides for .NET to avoid the trial limitations.

See Also

Posted in Aspose.Slides Product Family | Tagged , , , , | Leave a comment

ASP.NET PDF Creator – Create PDF Files Programmatically in ASP.NET Core

Generate PDF Files Programmatically in ASP.NET Core

PDF (Portable Document Format) is a well known and widely used format to display or view digital documents without worrying about the compatible software, operating system, or hardware. Creating PDF files programmatically is quite useful for generating documents such as reports, resumes, invoices, etc. online within the web applications. So in this article, I’ll show you how to create PDF files programmatically in ASP.NET Core web application using C#.

Create PDF Files Programmatically in ASP.NET Core

In order to create PDF files programmatically, we’ll develop a PDF Creator in the ASP.NET Core web application. This PDF Creator will be based on a WYSIWYG HTML editor to create the content and Aspose.PDF for .NET to generate the PDF based on that content. So let’s begin creating our PDF Creator application in ASP.NET Core by following the below steps.

  • Create a new ASP.NET Core Web Application in Visual Studio.
asp.net core generate pdf from html
  • Select Web Application (Model-View-Controller) from the templates.
asp.net core web application

Since this PDF Creator uses the WYSIWYG HTML editor to create the content for PDF documents, for the demonstration, I have used CKEditor’s Standard Package. You can feel free to choose your favorite HTML editor that could best serve your requirements. If you are good to go with the afore-mentioned editor then follow the below step for its integration, else skip it.

  • Download the CKEditor’s package, extract it and copy/paste the folder in wwwroot directory.
asp.net pdf creator
  • Open NuGet Package Manager and install the packages of Aspose.PDF and CKEditor.
Create PDF in ASP.NET Core
  • Open Views/Home/index.cshtml and replace the script with the following.
  • Open Controllers/HomeController.cs and replace the code with the following.
  • Build the application and run it in your favorite browser.

PDF Creator in ASP.NET Core – Demo

The following is the demonstration of how to create PDF files using ASP.NET PDF Creator we have just created.

Download Source Code

You can download the complete source code of the application from GitHub.

Get a Free License for Aspose.PDF for .NET

You can request a free temporary license of Aspose.PDF for .NET to avoid evaluation limitations.

Posted in Aspose.PDF Product Family | Tagged , , , , | Leave a comment

Aspose.Words for .NET 20.2 released

Despite the public holidays, this month was finished with good productivity, 57 improvements and fixes (with 4 Enterprise and 3 Priority Support issues among them) were included to this regular monthly release. Totally 105 issues were processed.

Loading PDF documents is now supported by Aspose.Words for .NET Standard. This is the first file format codec included as plugin in Aspose.Words. To make loading PDF documents work in your .NET Core application, you should add a reference to Aspose.Words.Pdf2Word.dll, or simply add NuGet reference to Aspose.Words. Loading PDF documents is as simple as loading a regular Word document.

Model/Conversions Team delivered several new features.
The most notable are:

  • Word 2019 version set by default. From now all the documents are loaded to the model following MS Word 2019 behavior.
  • FieldMergingArgsBase.FieldValue property has been made settable so that instead of setting Text the user can set FieldValue which takes formatting into account instead of simply replacing the field.
  • Supported dynamic insertion of documents and images from Base64-encoded bytes and dynamic checkbox value setting for LINQ Reporting Engine.

Rendering team managed to fix various rendering issues for DrawingML Charts, VML shapes, DrawingML text effects. Background image rendering has also been improved so that it is closer to MS Word output. The first release of 3D Effects Rendering through OpenGL is on the finale stage, Java team came up with a proposal to refine the code for auto-porting, so it was decided to postpone the release until the next month, using this time to improve the code.

Layout Team improved hyphenation zone processing, clipping of paragraph borders inside text boxes, implemented user notification when document is assembled with floating shapes nested in a text box to make the layout process more informative and predictable.

Posted in Aspose.Words Product Family | Tagged , , , , , , , , , | Leave a comment

ASP.NET Excel Viewer – View Excel Files in ASP.NET MVC using C#

ASP.NET Spreadsheet Viewer

Do you want to display Microsoft Excel worksheets within your web application? Are you looking for an ASP.NET MVC Excel Viewer? If yes, you have landed in an absolutely correct place. In this blog, you will learn how to create an Excel Viewer and display Excel worksheets in ASP.NET MVC applications using C#. After spending a few minutes and following some simple steps you will have your own Excel (XLS or XLSX) Viewer up and running. So let’s begin.

Features of ASP.NET MVC Excel Viewer

Our ASP.NET Excel Viewer will have the following features and you can enhance them as per your requirements.

  1. Browse and view Excel files.
  2. Load default Excel file on page load.
  3. Tabs to navigate between Excel worksheets.

Steps to Create Excel Viewer in ASP.NET MVC

The following are some easy steps to view Excel files in ASP.NET MVC.

1. Create a new ASP.NET MVC web application in Visual Studio.

ASP.NET MVC Web Application

2. Open NuGet Package Manager and install Aspose.Cells for .NET package.

View Excel files in ASP.NET MVC in browser

3. Create a new folder “Documents” to keep the Excel files and a subfolder “Rendered” to save rendered images.

4. Create a new folder with the name “Helpers” in the root folder.

5. Create a new class with the name “Sheet” in the “Helpers” folder to store the Excel worksheets’ information.

6. Open the “HomeController” class and replace it’s code with the following. Make sure to replace the default Excel file’s name in Index action.

7. Open Views/Home/index.cshtml and replace its content with the following script.

8. Build the application and run it in your favorite browser.

View Excel Files in ASP.NET MVC Viewer – Demo

The default Excel file will be displayed when you’ll start the application for the first time.

Excel Viewer in ASP.NET

Open an Excel File

In order to open an Excel file, click the browse button and select the file from the list.

Browse Excel Files
Open Excel file in ASP.NET C#

Navigate Between Excel Worksheets using Tabs

All the worksheets in the Excel workbook will be displayed in the form of tabs. You can click the tabs to navigate between worksheets.

Display Excel Files in ASP.NET

Download Source Code

This application is open source and its source code is available on GitHub.

Get a Temporary License for Aspose.Cells for .NET

You can get the temporary license of Aspose.Cells for .NET API to avoid evaluation/trial limitations.

Posted in Aspose.Cells Product Family | Tagged , , , , , | Leave a comment

Convert HTML Files to PDF Programmatically using Java

PDF is the most widely used document format for exchanging digital information. The cross-platform compatibility, stable layout and security features of PDF format have made it quite famous. The conversion from other documents to PDF is highly in practice these days and HTML to PDF is one of the popular conversion scenarios for converting the content of the web pages to PDF documents.

The online HTML to PDF converters allow you to convert the single or multiple HTML pages to PDF documents. However, in case you want to perform this conversion programmatically or you need to do a batch conversion of HTML files to PDF, you’ll definitely look for some SDK or API. In this article, you’ll learn how easy it is to convert a single or batch of HTML documents to PDF programmatically in Java. The following scenarios will be addressed in the rest of the article.

  • Convert HTML document to PDF in Java
  • Convert HTML to password-protected PDF in Java
  • Convert HTML to PDF using URL in Java
  • Convert HTML content to single-page PDF in Java

Aspose.PDF for Java API for HTML to PDF Converter

Aspose.PDF for Java is a powerful Java class library to work with PDF documents. In addition to the other PDF manipulation features, Aspose.PDF for Java also provides high-quality HTML to PDF conversion features. You can download the API’s JAR file or install it using the following configurations in your Maven-based Java project.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

Dependency

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>19.12</version>
    <classifier>jdk17</classifier>
</dependency>

Convert HTML to PDF in Java

The following is the simple recipe to convert an HTML file to PDF using Aspose.PDF for Java.

  • Create an instance of the HtmlLoadOptions class.
  • Create an instance of Document class and initialize it with the HTML file’s path and HtmlLoadOptions object.
  • Call Document.save(String) method with the output PDF file’s name.

The following code sample shows how to convert an HTML document to PDF in Java.

Input HTML File

Converted PDF Document

Convert HTML to Password-Protected PDF in Java

Aspose.PDF for Java also lets you convert HTML file to encrypted PDF document. You can protect the resultant PDF document by specifying the user’s password, owner’s password, access permissions, and cryptographic algorithm in the Document.encrypt() method.

The following code sample shows how to convert HTML to an encrypted PDF in Java.

Output

Convert HTML to PDF using URL in Java

You can also convert the web page from the live URL to the PDF document. Below are the steps to achieve this:

  • Create and initialize the URL object.
  • Get the web page into the InputStream object.
  • Create the Document object and initialize it with InputStream and HtmlLoadOptions objects.
  • Save HTML stream as PDF using Document.save() method.

The following code sample shows how to convert HTML content from URL to PDF in Java.

Convert HTML to a Single Page PDF in Java

In case you want to convert the whole HTML content into a single page PDF document, you can set HtmlLoadOptions.setRenderToSinglePage(true) as shown in the following Java code sample.

Related Articles

Posted in Aspose.PDF Product Family | Tagged , , , , | Leave a comment