MuPDF.NET Office#

Enhance MuPDF.NET capability with Office document support.

  • Enables Office document handling, including doc, docx, ppt, pptx, xls, xlsx, hwp, hwpx.

  • Supports text and table extraction, document conversion and more.

  • Includes everything from MuPDF.NET

To enquire about obtaining a commercial license, then use this contact page.

Trial license keys are available for evaluation purposes. Please fill out the form on this page to obtain a trial key.

Office file support#

In addition to the standard file types supported by MuPDF.NET, MuPDF.NET Office supports:

DOC/DOCX

XLS/XLSX

PPT/PPTX

HWP/HWPX

../_images/icon-docx.svg ../_images/icon-xlsx.svg ../_images/icon-pptx.svg ../_images/icon-hangul.svg

Usage#

Installation#

Install via Nuget with:

dotnet add package MuPDF.NET.Office

Loading an Office document#

Import MuPDF.NET Office and you can then reference Office documents directly, e.g.:

using MuPDF.NET;
using MuPDF.NET.Office;

MuPDFOffice.Unlock();
byte[]? pdf = MuPDFOffice.ToPdf("report.docx");
Document doc = Document.Open(pdf, "pdf");

Note

All standard MuPDF.NET functionality is exposed as expected - MuPDF.NET Office handles the extended Office file types

From then on you can work with document pages just as you would do normally, but with respect to the restrictions.

Restrictions#

MuPDF.NET Office functionality is restricted without a license key as follows:

Only the first 3 pages of any document will be available.

To unlock full functionality you should obtain a trial key.

Trial keys#

To obtain a license key please fill out the form on this page. You will then have the trial key emailed to the address you submitted.

Using a key#

Initialize MuPDF.NET Office with a key as follows:

using MuPDF.NET.Office;
MuPDFOffice.Unlock(my_key);
// MuPDF.NET has now been extended with MuPDF.NET Office features.

This will allow you to evaluate the product for a limited time. If you want to use MuPDF.NET Office after this time you should then enquire about obtaining a commercial license.

Converting#

Office document to PDF#

Use the MuPDFOffice.ToPdf() method to convert an Office document to PDF, e.g.:

using MuPDF.NET.Office;
MuPDFOffice.Unlock(my_key);

MuPDFOffice.ToPdf("input.docx", outputPath: "output.pdf")

If you require a byte representation of the PDF data, you can use the MuPDFOffice.ToPdf() without specifying an output file, e.g.:

using MuPDF.NET.Office;
MuPDFOffice.Unlock(my_key);

var pdfdata = MuPDFOffice.ToPdf("input.docx");

Office document to Images#

In order to convert an Office document to images, you should iterate the document pages, convert to Pixmap and save, e.g.:

using MuPDF.NET;
using MuPDF.NET.Office;

var doc = Document.Open("input.docx");

for (int i = 0; i < doc.PageCount; i++)
{
    var page = doc[i];
    var pix = page.GetPixmap(dpi: 200);
    pix.Save($"page-{i+1}.png");
}

doc.Close();

Office document to Markdown#

Use the MuPDFOffice.ToMarkdown() method to convert an Office document to Markdown, e.g.:

using MuPDF.NET.Office;
MuPDFOffice.Unlock(my_key);

MuPDFOffice.ToMarkdown("input.docx", "output.md");

If you require a string representation of the Markdown data, you can use the MuPDFOffice.ToMarkdown() method without specifying an output file.

Office document to JSON#

Use the MuPDFOffice.ToJson() method to convert an Office document to JSON, e.g.:

using MuPDF.NET.Office;
MuPDFOffice.Unlock(my_key);

MuPDFOffice.ToJson("input.docx", "output.json");

If you require a string representation of the JSON data, you can use the MuPDFOffice.ToJson() method without specifying an output file.

API#

MuPDFOffice.Unlock(string? keyString = null, string? fontPath = null, bool? fontPathAuto = null) → int#

Unlocks the MuPDF.NET Office functionality with the provided key.

Parameters:
  • keyString (string?) – the license key for MuPDF.NET Office.

  • fontPath (string?) – identify specific font directories.

  • fontPathAuto (bool?) – whether to append system font directories.

Returns:

key flags as int. 0 if no key (restricted, 3 pages). MuPDFOffice.KeyFlagVolumeLicense (1) = volume license. MuPDFOffice.KeyFlagDisableSo (2) = SmartOffice disabled. The return can be ignored. Invalid keys throw exceptions.

Grants access to the full functionality of MuPDF.NET Office. For a free trial key please visit: https://mupdf.com/mupdf-dotnet/office/try/.

MuPDFOffice.ToPdf(string inputPath, string? outputPath = null) → byte[] | null#

Reads the input file and converts its contents into PDF format.

Parameters:
  • inputPath (string) – the input file path.

  • outputPath (string?) – the path to the output file. If null (the default), the method returns the PDF content as byte[].

Returns:

byte[] of the PDF content or null if outputPath is specified.

MuPDFOffice.ToMarkdown(string inputPath, string? outputPath = null) → string | null#

Reads the input file and outputs the text of its pages in Markdown format.

Parameters:
  • inputPath (string) – the input file path.

  • outputPath (string) – the path to the output file. If null, the method returns the content as a string.

Returns:

string of the Markdown representation or null if outputPath is specified.

MuPDFOffice.ToJson(string inputPath, string? outputPath = null) → string | null#

Reads the input file and outputs the text of its pages in JSON format.

Parameters:
  • inputPath (string) – the input file path.

  • outputPath (string) – the path to the output file. If null, the method returns the content as a string.

Returns:

string of the JSON representation or null if outputPath is specified.

MuPDFOffice.GetFontPath() → IReadOnlyList<string>#

Retrieves the list of font paths currently recognized by MuPDF.NET Office.

Returns:

an array IReadOnlyList<string> representing the font paths.