Install & Usage

Supported .NET versions

Target frameworkStatus
.NET 8.0Supported

The package currently targets .NET 8.0 specifically - a consuming project needs to target .NET 8.0 or later. It's a plain class library, so it works from any .NET language (C#, F#, VB.NET); examples below are shown in C#.

Install

Hytone-PDF is a standard NuGet package - no additional runtime dependencies, and no Microsoft Word or Office installation needed on the machine running it.

dotnet add package Hytone-PDF

Or via the Package Manager Console:

Install-Package Hytone-PDF

Or by editing your .csproj directly:

<PackageReference Include="Hytone-PDF" Version="*" />

On install, NuGet prompts you to accept the license (packed as LICENSE.txt).

Activate a license

Set your license key once at application startup:

using Hytone.Pdf;

HytonePdf.SetLicense("HYT1....");

Without a key, the library runs in evaluation mode - output is capped at 1 page and watermarked, with PDF merging disabled. See Purchase License for what a license unlocks.

using Hytone.Pdf.Licensing;

if (License.IsLicensed)
{
    Console.WriteLine($"Licensed to {License.Current.LicensedTo} ({License.Current.Type})");
}

Convert a document

Simplest form - load a document, convert it:

var doc = HytonePdf.LoadDocument("report.docx");
doc.Save("report.pdf");

LoadDocument returns a HytoneDocument - hold onto the reference and call Save whenever you're ready. Each instance is independent, so this is safe from a script, a CLI tool, or a server converting many documents at once from multiple threads.

For streams, or any source that isn't a file on disk, LoadDocument/Save both have stream overloads:

using var docxStream = File.OpenRead("report.docx");
using var pdfStream = File.Create("report.pdf");
HytonePdf.LoadDocument(docxStream).Save(pdfStream);

For a server/web-app caller that doesn't want to block a thread pool thread, LoadDocumentAsync/SaveAsync are available too (path and stream overloads, with CancellationToken support):

var doc = await HytonePdf.LoadDocumentAsync("report.docx");
await doc.SaveAsync("report.pdf");

Merge PDFs

The recommended way to combine documents: build up in-memory "parts" - HytoneDocument.ToPdfDocument() for a freshly-converted DOCX, HytonePdf.LoadPdf(...) for an existing PDF - then combine and Save once, no intermediate file or stream needed in between:

HytonePdfDocument cover = HytonePdf.LoadPdf("cover.pdf");
HytoneDocument chapter1 = HytonePdf.LoadDocument("chapter1.docx");
HytoneDocument chapter2 = HytonePdf.LoadDocument("chapter2.docx");

cover.Append(chapter1).Append(chapter2).Save("book.pdf");

Append chains fluently and accepts either a HytoneDocument (converts and appends in one call) or another HytonePdfDocument. Prefer a flat ordered list instead of chaining? MergePdfs has an overload for that too:

HytonePdf.MergePdfs(
    [HytonePdf.LoadPdf("cover.pdf"), chapter1.ToPdfDocument(), chapter2.ToPdfDocument()],
    "book.pdf");

For merging PDFs that are already files on disk with no conversion involved at all, the plain path/stream overloads are still there and remain the simplest option:

HytonePdf.MergePdfs(["part1.pdf", "part2.pdf"], "combined.pdf");

MergePdfs's path overload also handles the output path being one of its own inputs safely (a temp file under the hood, swapped in atomically once the merge succeeds) - the "grow an existing PDF in place" pattern:

HytonePdf.MergePdfs(["report.pdf", "chapter2_only.pdf"], "report.pdf");

Convert legacy .doc

Word 97-2003 binary (.doc) documents convert to .docx first - chain into LoadDocument to go straight to PDF:

HytonePdf.ConvertDocToDocx("legacy.doc", "legacy.docx");
HytonePdf.LoadDocument("legacy.docx").Save("legacy.pdf");

For streams, or any non-file source, use the stream overload instead:

using var docStream = File.OpenRead("legacy.doc");
using var docxStream = File.Create("legacy.docx");
HytonePdf.ConvertDocToDocx(docStream, docxStream);

Need help?

Email licenses@hytone-tools.com with any questions.