how to printpreview and print SharpPDFLabel in vb.net

40 views Asked by At

how to printpreview and print SharpPDFLabel in vb.net?

As per the link with the documentation below : https://github.com/finalcut/SharpPDFLabel/tree/master

but there is an error in the code below Response.AddHeader.

is there something wrong with my code?

Thanks

Private personCollection As List(Of personCollection)
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ' Create the required label
        Dim labelDefinition = New SharpPDFLabel.Labels.A4Labels.Avery.L5160()

        ' Create a CustomLabelCreator, passing the required label
        Dim customLabelCreator = New SharpPDFLabel.CustomLabelCreator(labelDefinition)

        '//Add content to the labels
        '    ... 
        '    some IEnumerable collection was created...
        '...

        For Each person In personCollection
            ' you can specify LEFT, RIGHT, or CENTER for the horizontal alignment during Label construction
            Dim label As New Label(Enums.Alignment.LEFT)
            label.AddText(person.fullname, "Verdana", 12, embedFont:=True)
            label.AddText(person.address1, "Verdana", 12, embedFont:=True)
            label.AddText(person.address2, "Verdana", 12, embedFont:=True)
            label.AddText(person.city & ", " & person.stateCode & " " & person.zipcode, "Verdana", 12, embedFont:=True)
            customLabelCreator.AddLabel(label)
        Next person
        'Create the PDF as a stream
        Dim pdfStream = customLabelCreator.CreatePDF()

        'Do something with it!
'I have an error in the code below
        Response.AddHeader("Content-Disposition", "attachment; filename=address_labels.pdf")
        Return New FileStreamResult(pdfStream, "application/pdf")


    End Sub
End Class
Public Class personCollection
    Public fullname As String
    Public address1 As String
    Public address2 As String
    Public city As String
    Public stateCode As String
    Public zipcode As String
End Class
0

There are 0 answers