Some test text!

Search
Hamburger Icon

Core / Guides / Convert any printable document

Convert to PDF with virtual printer on Server/Desktop

To convert of different file types to PDF Documents acting as a virtual printer.

Only available on Microsoft Windows systems
// Start with a PDFDoc (the conversion destination)
PDFDoc doc = new PDFDoc();

// perform the conversion with no optional parameters
Convert.ToPdf(doc, filename);

PDF Converter (SVG, XPS, TIFF, JPG, RTF, TXT, More)
Full sample code which shows how to convert any printable document (e.g. Word, HTML, RTF, MS Office, DXF, DWG, etc) to PDF

About converting to PDF

The pdftron.PDF.Convert.ToPdf method (ToPdf for short, and relatedly, ToXod or ToXps), converts multiple file formats to the requested file output format. It supports several input formats like docx, xlsx, rtf, txt, html, pub, etc.

Formats that require external applications for conversion use the Printer class and the PDFNet printer to be installed. This is only supported on Windows platforms. Document formats in this category include RTF (MS Word or Wordpad), TXT (Notepad or Wordpad), DOC and DOCX (MS Word), PPT and PPTX (MS PowerPoint), XLS and XLSX (MS Excel), OpenOffice documents, HTML and MHT (Internet Explorer), PUB (MS Publisher), MSG (MS Outlook).

In order to convert these file formats the ToPdf method uses the PDFNet printer to request a print job, and the print output (in XPS) will be used for the actual conversion process.

It is important to keep in mind that in order to use the PDFNet printer, there must be an application installed on the machine, which will send print jobs to the PDFNet printer. The PDFNet printer works like any other printer; in order to print a document, an application must send printing jobs to the printer first, the PDFNet printer cannot open documents by itself.

For example: Printing a text file requires a text file viewer to perform a printing task. In Windows, this is normally notepad.exe.

ToPdf automates this process. It issues the print command on a document, and expects that an installed application will process the command. If the application does not support printing of the opened document, then the Convert.ToPdf method will fail.

Note: It is important to understand that in a 64-bit operating system, the 64-bit PDFNet printer driver must be installed. Installing the 32-bit PDFNet printer in a 64-bit operating system will not work. To install the 64-bit PDFNet printer driver, use the 64-bit version of PDFNet.dll and invoke the following method in a .NET application:

if (!Convert.Printer.IsInstalled())
{
  Convert.Printer.Install();
}

MS Office short-cut

If Microsoft Office 2007 SP2 or later is installed, ToPdf method will take advantage of Microsoft Office’s OLE interop automation library to convert Microsoft Office documents to PDF or XPS formats. Using Microsoft Office guarantees high quality PDF or XPS output files.

The PDFNet printer will not be used when a document can be converted using the available Microsoft Office’s interop libraries. However; the converter will use the PDFNet printer if an earlier version of Microsoft Office is installed - any versions prior to 2007 SP2. This is because the SaveAsPDFandXPS extension is not available in the older versions of Microsoft Office.

Special cases

Converting documents using Apryse, inside a Windows service, or an ASP.NET application requires some changes to the default settings that are used. Please read further to understand this better.

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales