none
Creating Pdf Print in visual Basic RRS feed

  • Question

  • Dear all,

    I am trying to build visual basic application to calculate solar System design. I would like to create Tab window where we can set list of parameter like Panel details, Inverter Details, Temperature rating. Etc

    I have setup formula which being using above Input parameters and calculate system design.Now Till end I can Use this formulaand Get system output. Now my Intention is to Print File output in PDf Format. SO that I can Readble output result.

    Can someone give some set of example how can i use result printing examples.

    Requested to share some sample example links for understanding PDF print statement


    AMPS12

    Monday, September 26, 2016 11:57 AM

Answers

  • If you actually desire to create a .PDF document you can use iTextSharp which if you use NuGet with Visual Studio you can get here NuGet - iTextSharp 5.5.9 and if you just want to download the library rather than using NuGet you can download that here SourceForge iTextSharp which I tested and it begins a download of iTextSharp 5.5.9.

    You can get a .PDF manual for iTextSharp, probably mostly in C#, here iText in Action 2nd Edition.pdf and if it is mostly in C# you can use Telerik or some other converter to convert the code.

    As far as printing a .PDF directly from a .Net app I would recommend you instead save the .PDF to a file and print it using the previous code I provided. However you will need Adobe Acrobat or possibly Adobe Reader installed in order to do that I think but am not positive. Trying to print a .PDF document directly from .Net using System.Drawing.Printing class probably would be difficult at best.

    You could save a created .PDF to file and view it using the AxAcroPDF control from Adobe Reader although maybe it comes with other versions of Adobe software.


    La vida loca

    Monday, September 26, 2016 6:23 PM
  • Hi AMPS12,

    The link tutorials on creating PDF file (this code is in C# but with every converter it can be converted to VB), please check if it helps.

    Microsoft .NET doesn't include a PDF component, you could use a third-party component, here are a few popular components for the task (ABCpdf.NET, iTextsharp, PDFSharp).

    Hope it’s helpful to you.

    Best Regards,

    Neda Zhang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, September 27, 2016 6:50 AM
    Moderator

All replies

  • print pdf files

    .

    .

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim psi As New ProcessStartInfo
    
            psi.UseShellExecute = True
    
            psi.Verb = "print"
    
            psi.WindowStyle = ProcessWindowStyle.Hidden
    
    'psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
    
            psi.FileName = "C:\MyFile.pdf" ' Here specify a document to be printed
    
            Process.Start(psi)
    
        End Sub
    


    La vida loca

    Monday, September 26, 2016 4:28 PM
  • If you want to generate PDF File and print that file then following links may help

    https://vishalsbsinha.wordpress.com/2014/05/06/how-to-programmatically-c-net-print-a-pdf-file-directly-to-the-printer/
    http://blog.scottlogic.com/2012/10/05/pdf-generation-and-printing-in-net-2.html


    Gaurav Khanna | Microsoft MVP | Microsoft Community Contributor

    Monday, September 26, 2016 5:36 PM
  • If you actually desire to create a .PDF document you can use iTextSharp which if you use NuGet with Visual Studio you can get here NuGet - iTextSharp 5.5.9 and if you just want to download the library rather than using NuGet you can download that here SourceForge iTextSharp which I tested and it begins a download of iTextSharp 5.5.9.

    You can get a .PDF manual for iTextSharp, probably mostly in C#, here iText in Action 2nd Edition.pdf and if it is mostly in C# you can use Telerik or some other converter to convert the code.

    As far as printing a .PDF directly from a .Net app I would recommend you instead save the .PDF to a file and print it using the previous code I provided. However you will need Adobe Acrobat or possibly Adobe Reader installed in order to do that I think but am not positive. Trying to print a .PDF document directly from .Net using System.Drawing.Printing class probably would be difficult at best.

    You could save a created .PDF to file and view it using the AxAcroPDF control from Adobe Reader although maybe it comes with other versions of Adobe software.


    La vida loca

    Monday, September 26, 2016 6:23 PM
  • Hi,

    You could try this Free .NET PDF Library from NuGet, as far as I know, it supports generate, edit and print pdf files to default printer or other network connected printer without installing Adobe. 

    Print PDF:

    Dim doc As New PdfDocument()
    doc.LoadFromFile("sample.pdf")
    
    'Use the default printer to print all the pages 
    'doc.PrintDocument.Print(); 
    
    'Set the printer and select the pages you want to print 
    Dim dialogPrint As New PrintDialog()
    dialogPrint.AllowPrintToFile = True
    dialogPrint.AllowSomePages = True
    dialogPrint.PrinterSettings.MinimumPage = 1
    dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count
    dialogPrint.PrinterSettings.FromPage = 1
    dialogPrint.PrinterSettings.ToPage = doc.Pages.Count
    
    If dialogPrint.ShowDialog() = DialogResult.OK Then
    	'Set the pagenumber which you choose as the start page to print 
    	doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage
    	'Set the pagenumber which you choose as the final page to print 
    	doc.PrintToPage = dialogPrint.PrinterSettings.ToPage
    	'Set the name of the printer which is to print the PDF 
    	doc.PrinterName = dialogPrint.PrinterSettings.PrinterName
    
    	Dim printDoc As PrintDocument = doc.PrintDocument
    	dialogPrint.Document = printDoc
    	printDoc.Print()
    End If


    • Edited by LeonDav Tuesday, September 27, 2016 2:44 AM
    Tuesday, September 27, 2016 2:43 AM
  • Hi AMPS12,

    The link tutorials on creating PDF file (this code is in C# but with every converter it can be converted to VB), please check if it helps.

    Microsoft .NET doesn't include a PDF component, you could use a third-party component, here are a few popular components for the task (ABCpdf.NET, iTextsharp, PDFSharp).

    Hope it’s helpful to you.

    Best Regards,

    Neda Zhang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, September 27, 2016 6:50 AM
    Moderator
  • here you can have a simple solution that I've made and publish to print all you need 

    writing a simple script out of your source code.

    https://www.codeproject.com/Articles/1237036/Printing-with-CodeDom-Scripts

    bye

    Friday, April 13, 2018 3:42 PM