page 253

When you need to print many PDF documents, surely you don't want to see the print dialog every time. This article will show you clearly how to print PDF documents in WPF without invoking Print Dialog by using Spire.PDFViewer for WPF.

Here comes to the steps of how to print PDF files in WPF.

Step 1: First you need to create a new project by choosing "WPF Application".

Step 2: Set the Target Framework to be .NET Framework 4 in Properties.

Step 3: Right-click on the blank part of the Toolbox → "Add Tab" → "Choose Items" → "WPF Components" → "Browse" to the "Bin" folder → find the file "Spire.PdfViewer.Wpf.dll" → "OK".

Step4: Spire.PDFViewer offers PdfViewer and PdfDocumentViewer to print the PDF files in C#. Please check the code snippet as below:

Print via PdfViewer without invoking PrintDialog with the following method.

PrintDialog dialog = new PrintDialog();
this.pdfViewer1.PrintDialog = dialog;
dialog.PrintDocument(pdfViewer1.PrintDocument.DocumentPaginator, "Print Document");

Print via PdfDocumentViewer without invoking PrintDialog with the following method.

PrintDialog dialog = new PrintDialog();
this.pdfDocumentViewer1.PrintDialog = dialog;
dialog.PrintDocument(pdfDocumentViewer1.PrintDocument.DocumentPaginator, "Print Document");

Then your PDF document will be printed directly without showing the print dialog.

Full codes of how to print PDF file in WPF.

namespace PrintPDFinWPF
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.pdfViewer1.LoadFromFile("sample.pdf");
            ////Print the PDF file directly with PrintDialog
            //this.pdfViewer1.Print();

            //Print without Print Dialog
            PrintDialog dialog = new PrintDialog();
            this.pdfViewer1.PrintDialog = dialog;
            dialog.PrintDocument(pdfViewer1.PrintDocument.DocumentPaginator, "Print Document");
        }
    }
}

A file with the XLSM extension is an Excel Macro-Enabled Workbook file. For security reasons, XLS file or XLSX file does not enable macros by default. Thus, if you want to execute macros in Excel file, you need to convert XLS or XLSX to XLSM at the first place. In this article, I’ll introduce you how to convert XLS to XLSM with the macro maintained using Spire.XLS.

Here is the method:

Step 1: Create a new instance of Spire.Xls.Workbook class.

Workbook workbook = new Workbook();

Step 2: Load the test file and imports its data to workbook.

workbook.LoadFromFile("test.xls", ExcelVersion.Version97to2003);

Step 3: Save the workbook as a new XLSM file.

workbook.SaveToFile("result.xlsm", FileFormat.Version2007);

Full Code:

[C#]
using Spire.Xls;
namespace Convert
{
    class Program
    {
          static void Main(string[] args)
{
    Workbook workbook = new Workbook();
    workbook.LoadFromFile("test.xls", ExcelVersion.Version97to2003);
    workbook.SaveToFile("result.xlsm", FileFormat.Version2007);
}

        }
    }
[VB.NET]
Imports Spire.Xls
Namespace Convert
	Class Program
		Private Shared Sub Main(args As String())
			Dim workbook As New Workbook()
			workbook.LoadFromFile("test.xls", ExcelVersion.Version97to2003)
			workbook.SaveToFile("result.xlsm", FileFormat.Version2007)
		End Sub

	End Class
End Namespace

Test File:

As is shown in the picture, Excel automatically disables macro in XLS file.

Convert XLS to XLSM and Maintain Macro in C#, VB.NET

Result:

No security warning in the converted XLSM file.

Convert XLS to XLSM and Maintain Macro in C#, VB.NET

C#/VB.NET: Convert PowerPoint to XPS

2022-09-23 01:06:00 Written by Koohji

The XML Paper Specification (XPS) format is an electronic representation of digital documents based on XML. It is a paginated, fixed-layout format that enables the content and design details of a document to be maintained intact across computers. Sometimes you may need to convert a PowerPoint document to XPS for better printing or sharing, and this article will demonstrate how to accomplish this task programmatically using Spire.Presentation for .NET.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Presentation

Convert PowerPoint to XPS

The detailed steps are as follows:

  • Create a Presentation instance.
  • Load a sample PowerPoint document using Presentation.LoadFromFile() method.
  • Save the PowerPoint document to XPS using Presentation.SaveToFile(String, FileFormat) method.
  • C#
  • VB.NET
using Spire.Presentation;

namespace PowerPointtoXPS
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation presentation = new Presentation();

            //Load a sample PowerPoint document
            presentation.LoadFromFile("test.pptx");

            //Save to XPS file
            presentation.SaveToFile("toXPS.xps", FileFormat.XPS);
        }
    }
}

C#/VB.NET: Convert PowerPoint to XPS

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

page 253