F# PDF Library (Full Tutorial)
This tutorial will guide you 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.
How to Generate PDF File in F# Library
- Download the F# PDF Library
- Create a PDF document with F# Library
- Customize your PDF document styles
- Build templates for document creation in F#
- Edit your PDF files from F# Library
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>
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
Create a PDF from HTML with F Sharp
First by opening the IronPDF library within your namespace using open
. After that create a ChromePdfRenderer
object, and pass a HTML string into it's RenderHtmlAsPdf
. Or if you already have a HTML file ready you can pass the filepath string
as a parameter to RenderHtmlFileAsPdf
.
HTML String to PDF in F
open IronPdf
let html = "<p>Hello World</p>"
let renderer = ChromePdfRenderer()
let pdf = html |> renderer.RenderHtmlAsPdf
pdf.SaveAs("document.pdf") |> ignore
HTML File to PDF in F
open IronPdf
let html = "C:/designs/html/layout.html"
let renderer = ChromePdfRenderer()
let pdf = html |> renderer.RenderHtmlFileAsPdf
pdf.SaveAs("document.pdf") |> ignore
Advanced IronPDF F# Template
This is a more advanced example of creating a function that will format and style a PDF from URL based on some rules and procedures:
open IronPdf
let CreateCompanyStandardDocument (url : string) =
// Setup Render Options
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
let company_style_header = HtmlHeaderFooter()
company_style_header.HtmlFragment <- "<img src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'"
company_style_header.DrawDividerLine <- true
// Apply a header to the Render Options
renderOptions.HtmlHeader <- company_style_header
// Init Renderer
let renderer = ChromePdfRenderer(RenderingOptions = renderOptions)
// Generate
let html_pdf_without_style = url |> ChromePdfRenderer().RenderUrlAsPdf
// All these methods return the PdfDocument for C# Linq style programming
// Because it mutates the original PDF, we can pipe the return to an ignore
html_pdf_without_style.AddHtmlHeaders company_style_header |> ignore
// Return
html_pdf_without_style
let IronPdfUrlToPdf (url : string) =
let pdf = url |> CreateCompanyStandardDocument
pdf.SaveAs("document.pdf") |> ignore
IronPdf.License.LicenseKey <- "YOUR_LICENSE_KEY_HERE"
IronPdfUrlToPdf "https://ironpdf.com/"