F# PDF Library (Full Tutorial)

This article was translated from English: Does it need improvement?
Translated
View the article in English

This tutorial will guide you through the steps of how to create and edit PDF files in F# using IronPDF. All you will need is Visual Studio installed and an F# project.

To see how to use IronPDF with C# see this guide.

To see how to use IronPDF with VB.NET see this guide.

Install the F# PDF Library

Install via NuGet Package Manager

In Visual Studio, right-click on your project solution explorer and select "Manage NuGet Packages...". From there simply search for IronPDF and install the latest version. Click OK to any dialog boxes that come up. This will work in any .NET Project.

Install via NuGet Package Manager Console

You may also choose to add IronPDF through the package manager console which can be done with this command:

Install-Package IronPdf

Install Directly in the .fsproj

Another option is to paste the following ItemGroup into your .fsproj file:

<ItemGroup>
  <PackageReference Include="IronPdf" Version="*" />
</ItemGroup>
<ItemGroup>
  <PackageReference Include="IronPdf" Version="*" />
</ItemGroup>
XML

Install via DLL

Alternatively, the IronPDF DLL can be downloaded and manually installed to the project or GAC from https://ironpdf.com/packages/IronPdf.zip

Remember to add this statement to the top of any .fs class file using IronPDF:

open IronPdf
open IronPdf
F#

Create a PDF from HTML with F

Begin by opening the IronPDF library within your namespace using open. After that, create a ChromePdfRenderer object and pass an HTML string into its RenderHtmlAsPdf method. If you already have an HTML file ready, you can pass the file path string as a parameter to RenderHtmlFileAsPdf.

HTML String to PDF in F

open IronPdf

let html = "<p>Hello World</p>"

// Initialize the PDF Renderer
let renderer = ChromePdfRenderer()

// Render HTML as PDF
let pdf = html |> renderer.RenderHtmlAsPdf

// Save the PDF document
pdf.SaveAs("document.pdf") |> ignore
open IronPdf

let html = "<p>Hello World</p>"

// Initialize the PDF Renderer
let renderer = ChromePdfRenderer()

// Render HTML as PDF
let pdf = html |> renderer.RenderHtmlAsPdf

// Save the PDF document
pdf.SaveAs("document.pdf") |> ignore
F#

HTML File to PDF in F

open IronPdf

let htmlFilePath = "C:/designs/html/layout.html"

// Initialize the PDF Renderer
let renderer = ChromePdfRenderer()

// Render HTML file as PDF
let pdf = htmlFilePath |> renderer.RenderHtmlFileAsPdf

// Save the PDF document
pdf.SaveAs("document.pdf") |> ignore
open IronPdf

let htmlFilePath = "C:/designs/html/layout.html"

// Initialize the PDF Renderer
let renderer = ChromePdfRenderer()

// Render HTML file as PDF
let pdf = htmlFilePath |> renderer.RenderHtmlFileAsPdf

// Save the PDF document
pdf.SaveAs("document.pdf") |> ignore
F#

Advanced IronPDF F# Template

Here is a more advanced example of creating a function that will format and style a PDF from a URL based on some rules and procedures:

open IronPdf

let CreateCompanyStandardDocument (url : string) =

    // Setup Render Options with desired settings
    let renderOptions = ChromePdfRenderOptions(
        CssMediaType = Rendering.PdfCssMediaType.Screen,
        EnableJavaScript = true,
        PrintHtmlBackgrounds = true,
        InputEncoding = System.Text.Encoding.UTF8,
        MarginTop = 0.39,
        MarginBottom = 0.38,
        MarginLeft = 0.39,
        MarginRight = 0.38
    )

    // Create Header Template for the PDF
    let companyStyleHeader = HtmlHeaderFooter()
    companyStyleHeader.HtmlFragment <- "<img src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'>"
    companyStyleHeader.DrawDividerLine <- true

    // Apply the header to the Render Options
    renderOptions.HtmlHeader <- companyStyleHeader

    // Initialize Renderer with customized options
    let renderer = ChromePdfRenderer(RenderingOptions = renderOptions)

    // Generate PDF from URL without additional styles
    let htmlPdfWithoutStyle = url |> renderer.RenderUrlAsPdf

    // Add the styled header to the PDF document
    htmlPdfWithoutStyle.AddHtmlHeaders companyStyleHeader |> ignore

    // Return the created PDF document
    htmlPdfWithoutStyle

let IronPdfUrlToPdf (url : string) =
    // Create a styled PDF document from the given URL
    let pdf = url |> CreateCompanyStandardDocument

    // Save the PDF document to the file system
    pdf.SaveAs("document.pdf") |> ignore

// Set your IronPDF License Key
IronPdf.License.LicenseKey <- "YOUR_LICENSE_KEY_HERE"

// Example usage: Convert the given URL to a PDF document
IronPdfUrlToPdf "https://ironpdf.com/"
open IronPdf

let CreateCompanyStandardDocument (url : string) =

    // Setup Render Options with desired settings
    let renderOptions = ChromePdfRenderOptions(
        CssMediaType = Rendering.PdfCssMediaType.Screen,
        EnableJavaScript = true,
        PrintHtmlBackgrounds = true,
        InputEncoding = System.Text.Encoding.UTF8,
        MarginTop = 0.39,
        MarginBottom = 0.38,
        MarginLeft = 0.39,
        MarginRight = 0.38
    )

    // Create Header Template for the PDF
    let companyStyleHeader = HtmlHeaderFooter()
    companyStyleHeader.HtmlFragment <- "<img src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'>"
    companyStyleHeader.DrawDividerLine <- true

    // Apply the header to the Render Options
    renderOptions.HtmlHeader <- companyStyleHeader

    // Initialize Renderer with customized options
    let renderer = ChromePdfRenderer(RenderingOptions = renderOptions)

    // Generate PDF from URL without additional styles
    let htmlPdfWithoutStyle = url |> renderer.RenderUrlAsPdf

    // Add the styled header to the PDF document
    htmlPdfWithoutStyle.AddHtmlHeaders companyStyleHeader |> ignore

    // Return the created PDF document
    htmlPdfWithoutStyle

let IronPdfUrlToPdf (url : string) =
    // Create a styled PDF document from the given URL
    let pdf = url |> CreateCompanyStandardDocument

    // Save the PDF document to the file system
    pdf.SaveAs("document.pdf") |> ignore

// Set your IronPDF License Key
IronPdf.License.LicenseKey <- "YOUR_LICENSE_KEY_HERE"

// Example usage: Convert the given URL to a PDF document
IronPdfUrlToPdf "https://ironpdf.com/"
F#

Preguntas Frecuentes

¿Cómo puedo generar un archivo PDF en F# usando una biblioteca?

Para generar un archivo PDF en F#, puedes usar la biblioteca IronPDF. Comienza instalando IronPDF a través de NuGet Package Manager, NuGet Package Manager Console, o agregando el DLL directamente. Usa el objeto ChromePdfRenderer y llama su método RenderHtmlAsPdf con tu contenido HTML.

¿Cómo instalo una biblioteca de PDF en un proyecto F#?

Puedes instalar la biblioteca IronPDF en un proyecto F# a través de NuGet Package Manager buscando IronPDF e instalándolo. Alternativamente, puedes usar la NuGet Package Manager Console, editar directamente el archivo .fsproj, o agregar manualmente el DLL de IronPDF a tu proyecto.

¿Puedo convertir una cadena HTML a PDF usando F#?

Sí, puedes convertir una cadena HTML a un PDF en F# usando IronPDF. Inicializa un objeto ChromePdfRenderer y usa el método RenderHtmlAsPdf con tu cadena HTML para crear un documento PDF.

¿Cómo convierto un archivo HTML a PDF en F#?

Para convertir un archivo HTML a PDF en F#, utiliza ChromePdfRenderer de IronPDF y llama al método RenderHtmlFileAsPdf, pasando la ruta del archivo de tu archivo HTML.

¿Cuáles son algunas características avanzadas para el estilizado de PDF en F#?

IronPDF soporta estilizado avanzado de PDFs en F#. Puedes usar ChromePdfRenderOptions para configurar opciones de renderizado personalizadas, como el tipo de medio CSS, la ejecución de JavaScript y los márgenes. También puedes agregar encabezados y pies de página en HTML para documentos de apariencia más profesional.

¿Cómo puedo agregar un encabezado a un PDF en F#?

En F#, puedes agregar un encabezado a un PDF usando IronPDF creando un objeto HtmlHeaderFooter, configurando sus propiedades como HtmlFragment, y aplicándolo a ChromePdfRenderOptions antes de renderizar tu PDF.

¿Cómo uso una clave de licencia con una biblioteca de PDF en F#?

Para usar una clave de licencia con IronPDF en F#, asigna tu cadena de clave de licencia a la propiedad IronPdf.License.LicenseKey en tu código F#.

¿Cómo puedo crear un PDF desde una URL en F#?

Con IronPDF, puedes crear un PDF desde una URL en F# iniciando un ChromePdfRenderer con las opciones de renderizado deseadas, y usando el método RenderUrlAsPdf con la URL que deseas convertir.

¿Qué entorno de desarrollo se recomienda para F# y bibliotecas de PDF?

El entorno de desarrollo recomendado para usar IronPDF con F# es Visual Studio. Ofrece herramientas completas para la gestión de paquetes, edición de código y construcción de proyectos, siendo adecuado para proyectos F# que implican la creación de PDF.

¿Es posible editar PDFs existentes con esta biblioteca en F#?

Sí, IronPDF te permite editar PDFs existentes en F#. Puedes modificar contenido de PDF, agregar encabezados o pies de página, y aplicar estilizado adicional usando las funciones de la API de la biblioteca.

¿IronPDF es compatible con .NET 10 cuando se utiliza F# para la generación de PDF?

Sí. IronPDF es totalmente compatible con .NET 10, incluso desde F#. Puedes usar .NET 10 como destino en tu proyecto de F# y usar la API de IronPDF (como ChromePdfRenderer ) sin necesidad de soluciones alternativas. IronPDF funciona de inmediato en todas las versiones modernas de .NET, incluyendo .NET 10. ([ironpdf.com](https://ironpdf.com/blog/net-help/net-10-features/?utm_source=openai))

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 16,133,208 | Versión: 2025.11 recién lanzado