Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Feb 02, 2024 7:28 pm

Hello All, I have some existing reports in VB such as invoice and purchase order that I would like to convert to pdf. Can I use Spire to convert entire printdocument from VB or do I need to re-write with Spire code?

Any help would be appriciated

hamidhalimi
 
Posts: 2
Joined: Fri Feb 02, 2024 7:19 pm

Sun Feb 04, 2024 3:47 am

Hello,

Thank you for your inquiry.
Based on your description, I understand that you are looking to convert an Excel file to PDF. If that's the case, please follow the steps below:
1. Install our Spire.XLS package via NuGet. You can do this by opening the NuGet Package Manager in your Visual Studio project and searching for "Spire.XLS". Install the package to add the necessary dependencies to your project.
2. Once the package is installed, you can use the following code snippet to test the conversion:
Code: Select all
Imports Spire.Xls

Namespace ConvertExcelToPDF
   
    Class Program
       
        Private Shared Sub Main(ByVal args() As String)
            'Create a Workbook instance
            Dim workbook As Workbook = New Workbook
            'Load a sample Excel file
            workbook.LoadFromFile("C:\Desktop\Sample.xlsx")
            'Set worksheets to fit to page when converting
            workbook.ConverterSetting.SheetFitToPage = true
            'Save to PDF
            workbook.SaveToFile("ExcelToPdf.pdf", FileFormat.PDF)
        End Sub
    End Class
End Namespace

If your requirements are different or if you need assistance with any other document type, please provide us with more detailed information so that we can better assist you. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1652
Joined: Wed Apr 07, 2021 2:50 am

Mon Feb 05, 2024 12:19 am

Hi Annika, thanks for the reply. My reports are not in Excel. I have used VB.NET to write the reports as shown here. The reports print perfectly to the printer but they are not in a file so I can not use the LoadFromFile to open and convert.


Code: Select all
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim StringFormat = New StringFormat() : StringFormat.Alignment = StringAlignment.Far ' Right Justify
        PG += 1

        Down = 30
        e.Graphics.DrawString("Sales Order", Font20, Brushes.Black, Right, Down, StringFormat)
        Down = 60
        Dim bitmap As New Bitmap("logo.jpg")
        e.Graphics.DrawImage(bitmap, Left, Down, 50, 50)
        'If CoAddress2 = "" Then Down = 90 Else Down = 80 ' Company Name
        e.Graphics.DrawString(CoName, Font12B, Brushes.Black, Left + 55, Down) : Down += Offset
        e.Graphics.DrawString(CoAddress1, Font12, Brushes.Black, Left + 55, Down) : Down += Offset
        If CoAddress2 <> "" Then
            e.Graphics.DrawString(CoAddress2, Font12, Brushes.Black, Left + 55, Down)
            Down += Offset
        End If
        e.Graphics.DrawString(CoCity + ", " + CoState + " " + CoZip, Font12, Brushes.Black, Left + 55, Down)

hamidhalimi
 
Posts: 2
Joined: Fri Feb 02, 2024 7:19 pm

Mon Feb 05, 2024 1:46 am

Hello,

Thank you for your feedback.
Based on the code you provided, I suggest that you directly use a virtual printer to print your report as a PDF file, eliminating the need to use Spire.PDF to load and convert the document. The virtual printers you can use are "Adobe PDF" or "Microsoft Print to PDF". Here is an example code:
Code: Select all
Dim printerSettings As PrinterSettings = New System.Drawing.Printing.PrinterSettings
printerSettings.PrinterName = "Adobe PDF"    'or "Microsoft Print to PDF"

If you have any further questions or need assistance, please feel free to let me know.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1652
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF