SelectPdf for .NET - Pdf Compression - VB.NET / ASP.NET Sample

SelectPdf Library for .NET offers the possibility to reduce the size of the generated pdf document using compression.

This sample shows how to create a new PDF document using SelectPdf, how to add a text element to it and use compression to reduce the size of the generated pdf document.

Compression Level:



Sample Code Vb.Net



Public Class pdf_compression
    Inherits System.Web.UI.Page

    Protected Sub BtnCreatePdf_Click(sender As Object, e As EventArgs)
        ' create a new pdf document
        Dim doc As New PdfDocument()
        doc.Margins = New PdfMargins(20, 20, 20, 20)

        ' set compression level
        doc.CompressionLevel = DirectCast([Enum].Parse(GetType(PdfCompressionLevel), _
            DdlPdfCompressionLevel.SelectedValue, True), PdfCompressionLevel)

        ' create a new pdf font
        Dim font As PdfFont = doc.AddFont(PdfStandardFont.Helvetica)
        font.Size = 16

        ' add a new page to the document
        Dim page As PdfPage = doc.AddPage()

        ' create a new text element and add it to the page
        Dim text As New PdfTextElement(0, 0, _
            SelectPdf.Samples.Helper.SomeVeryLongText(), font)
        page.Add(text)

        ' save pdf document
        doc.Save(Response, False, "Sample.pdf")

        ' close pdf document
        doc.Close()
    End Sub

End Class