AVAILABLE NOW: Spring 2025 Release
By Apryse | 2025 Apr 03
8 min
Tags
C#
java
html
pdf conversion
You might have heard about how Apryse has a world-class document converter. Our Apryse SDK can easily transform HTML to PDF. The portability of a PDF allows you to access content from webpages across multiple devices both on- and off-line.
Below are a few code snippets to convert HTML to PDF.
using pdftron;
using pdftron.Common;
using pdftron.PDF;
using pdftron.SDF;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
try {
PDFNet.Initialize(PDFTronLicense.License);
HTML2PDF.SetModulePath(PDFTronLicense.ModulePath);
using (PDFDoc doc = new PDFDoc())
{
HTML2PDF converter = new HTML2PDF();
// Our HTML data
string html = "<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>";
// Add html data
converter.InsertFromHtmlString(html);
// Note, InsertFromHtmlString can be mixed with the other Insert methods.
converter.Convert(doc);
doc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized);
}
}
catch (PDFNetException e)
{
Console.WriteLine(e.Message);
}
}
}
}
The above code could easily be modified to convert the input file to one of Apryse’s supported document formats by changing the document format enumeration.
import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.*;
import com.pdftron.sdf.*;
public class App {
public static void main(String[] args) {
try{
PDFNet.initialize(PDFTronLicense.LICENSE);
HTML2PDF.setModulePath(PDFTronLicense.MODULE_PATH);
PDFDoc doc = new PDFDoc();
HTML2PDF converter = new HTML2PDF();
// Our HTML data
String html = "<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>";
// Add HTML data
converter.insertFromHtmlString(html);
// Note, insertFromHtmlString can be mixed with the other insert methods.
converter.convert(doc);
doc.save("src\\samples\\output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
doc.close();
} catch (PDFNetException e) {
System.out.println(e.getMessage());
}
}
}
Download the Apryse SDK for free. It’s fully functional and comes with free chat and email support.
Stay tuned for more conversion examples to see how the Apryse SDK will easily fit into any workflow converting PDF files into other document files or images and back again. Need help in the meantime? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team.
Tags
C#
java
html
pdf conversion
Apryse
Share this post
PRODUCTS
Platform Integrations
End User Applications
Popular Content