Visual Studio: Printing all source files in a solution?

30,967

Solution 1

From what I gather from a similar question asked elsewhere, this "feature" is not build into Visual Studio.

However it looks like MSDN has a macro you can use to print all of your code; perhaps you can use this, or something like it:

Sub PrintItemsInSelectedProject()
    Dim proj As Project
    Dim objProj As Object()

    objProj = DTE.ActiveSolutionProjects
    If objProj.Length = 0 Then
        Exit Sub
    End If
    proj = DTE.ActiveSolutionProjects(0)
    PrintItemsInSelectedProject(proj.ProjectItems)
End Sub

Private Sub PrintItemsInSelectedProject( _
    ByVal projitems As ProjectItems)
    Dim projitem As ProjectItem

    For Each projitem In projitems
        If (IsPrintableFile(projitem) = True) Then
            If (projitem.IsOpen( _
                    EnvDTE.Constants.vsViewKindTextView)) Then
                projitem.Document.PrintOut()
            Else
                Dim doc As Document
                doc = projitem.Open( _
                    EnvDTE.Constants.vsViewKindTextView).Document
                doc.PrintOut()
                doc.Close(vsSaveChanges.vsSaveChangesNo)
            End If
        End If
        PrintItemsInSelectedProject(projitem.ProjectItems)
    Next
End Sub

Function IsPrintableFile( _
        ByVal projItem As ProjectItem) As Boolean
    Dim fileName As String
    Dim extensions As _
        New System.Collections.Specialized.StringCollection
    ' If you add a file to your project that is of 
    ' a type that can be printed, 
    ' then add the extension of that 
    ' file type to this list.
    Dim exts As String() = {".cs", ".vb", _
        ".aspx", ".xsd", ".xml", ".xslt", _
        ".config", ".htm", ".html", ".css", _
        ".js", ".vbs", ".wsf", ".txt", ".cpp", _
        ".c", ".h", ".idl", ".def", ".rgs", ".rc"}

    extensions.AddRange(exts)
    fileName = projItem.FileNames(1)
    Return extensions.Contains( _
        System.IO.Path.GetExtension(fileName).ToLower())
End Function

Solution 2

Putting aside the fun comments from tree-huggers, let's assume you want to printout the Visual Studio solution as PDF (and we won't ask what you do with it later).

For people who use VisualStudio there is a very nice program that used to be sold but is now available to download for free, called PrettyCode.Print for .NET 2.0. It is available for download here (the company retired the product).

It reads in a VisualStudio project (works with VS2005, VS2008 and VS2010) and let one print a selection of files with various printing options. It does a pretty decent job.

Solution 3

You can download PrettyCode.Print for .NET 2.0 (VS2008 and VS2005) in:http://pan.baidu.com/wap/shareview?&shareid=3968547697&uk=286220058&dir=%2FSoftz&page=1&num=20&fsid=1117386981714891&third=0 In my computer work fine with Visual Studio 2013.

Share:
30,967
Dervin Thunk
Author by

Dervin Thunk

Updated on July 09, 2022

Comments

  • Dervin Thunk
    Dervin Thunk almost 2 years

    Is there a way to print all (*.cs) files in a solution at once, that is, without clicking on each of them and then hitting print?

  • Danny Beckett
    Danny Beckett over 9 years
    Works fine here for VS2013
  • Dror Harari
    Dror Harari almost 7 years
    User @uncanny has added the following which I could not check but it may be useful: Warning: With VS2015 it does not read the files correctly and it can happen that it skips functions to print. This is not necessarily noticable and thus can cause some headaches if you do not double-check your pdf before printing it.