The Portable Document Format (PDF) is a file format to present documents, including text formatting and images, in a manner independent of the application software, hardware, and operating systems. Based on the PostScript language, each PDF file encapsulates a complete description of a fixed-layout flat document, including the text, fonts, vector graphics, raster images and other information needed to display it.
This post demonstrates the usage of the GroupDocs.Viewer APIs (GroupDocs.Viewer for .NET and GroupDocs.Viewer for Java) to render the supported file formats as PDF documents.
How to Render Using GroupDocs.Viewer
Both the viewer handlers (ViewerHtmlHandler,ViewerImageHandler) provide an overloaded method GetPdfFile() which accepts the document name as parameter and returns FileContainer. The File stream can be fetched from the Stream property of the FileContainer in order to save the resultant document on the disk.
The following code snippet shows the way to render a word document as PDF:
Java lovers can write the code like following:
Add Print Action while Rendering as PDF
A Print Action is an option to appear the print popup when open the PDF document in Adobe reader. The popup will appear like below screenshot:
The below given steps can be followed, in order to add print action in the resultant PDF document.
- Create/initialize PdfFileOptions object
- Set Transformations property of PdfFileOptions to Transformation.AddPrintAction
- Call htmlHandler.GetPdfFile method
The .NET code snippet will look like:
The Java code can be written as:
The complete ready to run code sample is available on GitHub.