.net.net-8.0.net-4.8asposeaspose.words

Where is the Document.Print Method in Aspose.Words in .NET 8?


I'm in the process of migrating a large Solution from .NET Framework 4.8 to .NET 8 (net8.0-windows).

I have changed the TargetFramework of all Projects to net8.0-windows from net48 and am now compiling, fixing whatever issues arise [repeat] until everything compiles under .NET 8.

We're using Aspose.Words in some of the Projects, and I've run into an issue that I can't seem to solve. The Document class seems to no longer have a Print method.

We have a class that holds an Aspose.Words.Document Object as a member and provides a number of methods to interact with this object, like replacing text, writing text and printing.

The Print method is pretty straightforward:

  Public Sub Print(printername As String,
                   Optional startPage As Integer? = Nothing,
                   Optional endPage As Integer? = Nothing,
                   Optional copies As Integer? = Nothing)
    Try
      Dim printersettings = New PrinterSettings
      With printersettings
        .PrinterName = printername
        If startPage.HasValue Then .FromPage = startPage.Value
        If endPage.HasValue Then .ToPage = endPage.Value
        If copies.HasValue Then .Copies = CShort(copies.Value)
      End With
#IF NETFRAMEWORK
      m_Document.Print(printersettings)
#ELSE
      'How to print in .NET 8?
#END IF
    Catch ex As Exception
      'handle ex
    End Try
  End Sub

The change from net48 to net8.0 in this project has otherwise been uneventful, I needed to adjust some Imports because of Conflicts betweend System.Drawing and Aspose.Drawing, but other than the Print issue it compiles now.

I can't find anything as to why the Print method is missing and/or what I can use to replace it. The official Documentation still lists Document.Print() as the default way to print a document. The examples also still contain Document.Print() or AsposeWordsPrintDocument, neither of which seem to exist.

I'm using Aspose.Words 24.9.0, and the only changes between the net48 and the net8.0-windows projects are the TargetFramework and some Imports/Namespaces.

If I go into the Aspose Code (from Metadata), I can see that the Document class does not contain a Print method when using the DLL that is compiled with .NET 8.

The issue is that I am not finding anything as to why that is the case and what I could use instead.


Solution

  • It seems that this functionality has been removed due to the cross-platform aim of .NET (incl. Core).

    Check out Xamarin and .NET Standard 2.0 Limitations and API Differences for more info.

    It would have been nice if they hadn't removed the methods but threw a PlatformNotSupportedException with a link to the documentation.

    There are other ways however. A project I'm currently working on renders documents to PDF, saves it to a folder and then invokes a command line process to print the PDF to the configured printer using a slightly modified version of SumatraPDF.