---
title: "HTML to PDF: set title and author in C#"
url: https://recursiveai.org/onepdf-html/cookbook/set-pdf-metadata-when-converting-html/
description: "Set the PDF document title and author as you convert HTML in C#. Override HTML metadata with HtmlToPdfOptions without changing the visible heading."
version: "1.0.0"
---

# HTML to PDF: set title and author in C#

**OnePdf.Html** is a free, open-source .NET library from Recursive AI that converts PDF to HTML and HTML to PDF. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePdf.Html.Render) · [GitHub](https://github.com/recursive-ai-oss/onepdf-html-csharp) · [Docs](https://recursiveai.org/onepdf-html/docs/) · [Download example (.zip)](https://recursiveai.org/onepdf-html/cookbook/set-pdf-metadata-when-converting-html/set-pdf-metadata-when-converting-html.zip)

Set PDF properties with `Title` and `Author`.

```shell
dotnet add package RecursiveAI.OnePdf.Html.Render
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OnePdf.Html.Render;

var options = new HtmlToPdfOptions
{
    Title = "Quarterly results",
    Author = "Finance team",
};
var pdf = HtmlToPdf.ConvertFile(
    "report.html", "results.pdf", options);
Console.WriteLine($"results.pdf: {pdf.Title}");
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onepdf-html/cookbook/set-pdf-metadata-when-converting-html/set-pdf-metadata-when-converting-html.zip) and `dotnet run`.

The program writes `results.pdf` and prints the PDF title:

```text
results.pdf: Quarterly results
```

The download includes `report.html`. To run the snippet in your own project, save this file beside `Program.cs`:

```html
<!doctype html>
<html lang="en">
<title>Internal draft</title>
<meta name="author" content="Draft owner">
<h1>Sales report</h1>
<p>April sales increased.</p>
```

In the PDF’s document properties, **Title** is **Quarterly results** and **Author** is **Finance team**. The text on the page still starts with “Sales report.” If the input file can’t be read, `ConvertFile` throws `HtmlToPdfException` instead of writing a PDF.

## Variations

**Keep the HTML title and add a subject and keywords.** Replace everything after the `using` line with:

```csharp
var options = new HtmlToPdfOptions
{
    Author = "Finance team",
    Subject = "Sales results",
    Keywords = "sales, quarterly results",
};
HtmlToPdf.ConvertFile("report.html", "sales.pdf", options);
```

`sales.pdf` keeps **Internal draft** as its title and gets **Finance team** as its author, **Sales results** as its subject and **sales, quarterly results** as its keywords.

## Related recipes

- [Set paper size and margins for HTML to PDF](https://recursiveai.org/onepdf-html/cookbook/set-page-size-and-margins-for-html-to-pdf/)
- [Batch convert HTML files to PDF](https://recursiveai.org/onepdf-html/cookbook/convert-folder-of-html-files-to-pdf/)

## The short answer

Pass `Title` and `Author` in `HtmlToPdfOptions` when you call `HtmlToPdf.ConvertFile`. The converter writes those values into the PDF document properties, in place of the ones it would have taken from `<title>` and `<meta name="author">`. This is useful when a shared HTML template carries a draft title but each PDF needs the title and author set by the application that produces it.

## Does HTML-to-PDF conversion copy the title and author automatically?

Yes, if those fields aren’t set in the options. The converter reads the HTML title and the author meta tag. You can override the author but leave `Title` unset to reuse the title from the template. The same pattern works for `Subject` (the HTML description meta tag), `Keywords` (the keywords meta tag) and `Language` (the root element’s `lang`). See the [metadata options](https://recursiveai.org/onepdf-html/docs/html-to-pdf/#links-outline-metadata-and-tags).

Metadata and page content serve different purposes. `<h1>Sales report</h1>` is rendered on the page, but it isn’t the `<title>` field the converter reads for metadata. Setting `Title` in C# doesn’t change that heading. To change both what readers see and what the document properties show, update the heading in the HTML and set the title explicitly or supply it in `<title>`.

## How can I check the title and author of the PDF?

Open `results.pdf` in a viewer that shows document properties and look for Title and Author. Check the properties rather than the filename: the sample writes `results.pdf`, but the title is “Quarterly results.” The `HtmlToPdfResult.Title` property also lets your application report the title after writing the file, as the example does.

## Can I set the PDF creation date when converting HTML?

Yes. Supply a `DateTimeOffset` in `CreationDate` if the PDF needs an explicit date. If you leave that option unset, the converter doesn’t write a creation date; it doesn’t use the time of conversion. That lets you choose a date from the business record that the PDF represents, rather than the date a batch happened to run.
