swift-html-to-pdf

Hello Swift Community!

Working with documents is my job as a lawyer, and I’m excited to share a new library I’ve been working on: swift-html-to-pdf. This library provides an easy-to-use interface to print HTML strings to PDF documents on iOS and MacOS.

Key Features

  • Convert HTML strings to PDF documents on both iOS and macOS.
  • Lightweight and fast: it can handle thousands of documents quickly.
  • Customize margins for PDF documents.
  • Swift 6 language mode enabled

Why did I build swift-html-to-pdf?

As a lawyer with a passion for legal tech, a significant part of my work involves generating legal documents. However, I have always found converting HTML to PDFs to be quite cumbersome.

This library is built to address common pain points I faced when dealing with PDF generation from HTML. It provides a modern and easy to use interface API that simplifies the process, allowing me (and you!) to focus on building great documents without worrying about the intricacies of PDF conversion.

Example Usage

Here’s a quick example of how you can get started with swift-html-to-pdf:

import HtmlToPdf

let htmlString = "<html><body><h1>Hello, World!</h1></body></html>"

try await htmlString.print(
    to: URL(fileURLWithPath: "path/to/output.pdf"),
    configuration: .a4
)

Get Involved

swift-html-to-pdf is open-source and contributions are welcome! Check out the swift-html-to-pdf for more details, and feel free to report issues, suggest features, or submit pull requests.

I hope this library helps you as much as it has helped me. I look forward to your feedback and contributions!

6 Likes

You may have forgotten to include a link to the project - or it's too well hidden for me to find it! :slightly_smiling_face:

Thanks for noticing that!