page 107

Sometimes you may want to print Word documents in accordance with your own preferences, for instance, print your files on custom paper sizes to make them more personalized. In this article, you will learn how to achieve this function using Spire.Doc for .NET.

Install Spire.Doc for .NET

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

  • Package Manager
PM> Install-Package Spire.Doc

Print Word on a Custom Paper Size

The table below shows a list of core classes, methods and properties utilized in this scenario.

Name Description
Document Class Represents a document model for Word.
PaperSize Class Specifies the size of a piece of paper.
PrintDocument Class Defines a reusable object that sends output to a printer, when printing from a Windows Forms application.
PrintDocument.DefaultPageSettings Property Gets or sets page settings that are used as defaults for all pages to be printed.
Document.PrintDocument Property Gets the PrintDocument object.
DefaultPageSettings.PaperSize Property Sets the custom paper size.
Document.LoadFromFile() Method Loads the sample document.
PrintDocument.Print() Method Prints the document.

The following are the steps to print Word on a custom paper size.

  • C#
  • VB.NET
using Spire.Doc;
using System.Drawing.Printing;

namespace PrintWord
{
    class Program
    {
        static void Main(string[] args)
        {
             //Instantiate a Document object.
            Document doc = new Document();

            //Load the document
            doc.LoadFromFile(@"Sample.docx");

            //Get the PrintDocument object
            PrintDocument printDoc = doc.PrintDocument;

            //Customize the paper size
            printDoc.DefaultPageSettings.PaperSize = new PaperSize("custom", 900, 800);

            //Print the document
            printDoc.Print();

        }
    }
}
Imports Spire.Doc
Imports System.Drawing.Printing

Namespace PrintWord
	Class Program
		Private Shared Sub Main(args As String())
			'Instantiate a Document object.
			Dim doc As New Document()

			'Load the document
			doc.LoadFromFile("Sample.docx")

			'Get the PrintDocument object
			Dim printDoc As PrintDocument = doc.PrintDocument

			'Customize the paper size
			printDoc.DefaultPageSettings.PaperSize = New PaperSize("custom", 900, 800)

			'Print the document
			printDoc.Print()

		End Sub
	End Class
End Namespace

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.

Java: Edit or Remove Comments in Excel

2021-10-13 06:29:45 Written by Koohji

Comments in Excel are used to explain the contents in cells, or to offer reminders/notes to other users. Once a comment’s been added, Microsoft Excel allows users to show, hide, edit and delete the comments easily in a worksheet. This article will introduce how to edit existing comments as well as remove comments programmatically using Spire.XLS for Java.

Install Spire.XLS for Java

First of all, you're required to add the Spire.Xls.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls</artifactId>
        <version>15.11.3</version>
    </dependency>
</dependencies>

Edit Comments in Excel

After adding comments to your Excel workbook, you may want to make changes to the added comments. The below table lists some of the core classes and methods used to get the existing comments and then set new text as well as formatting for the comments.

Name Description
ExcelCommentObject Class Represents a comment in an Excel document.
CellRange.getComment() Method Returns a comment object that represents a comment in a specific cell range.
ExcelCommentObject.setText() Method Sets the comment text.
ExcelCommentObject.setHeight() Method Sets height of a comment.
ExcelCommentObject.setWidth() Method Sets width of a comment.
ExcelCommentObject.setAutoSize() Method Sets whether the size of the specified object is changed automatically to fit text within its boundaries.

The following are steps to edit comments in Excel:

  • Java
import com.spire.xls.*;

public class ModifyComment {
    public static void main(String[] args) {

        //Create a Workbook instance
        Workbook wb = new Workbook();
        
        //Load an Excel file
        wb.loadFromFile("Comments.xlsx");

        //Get the first worksheet
        Worksheet sheet = wb.getWorksheets().get(0);

        //Get comments in specific cells and set new comments
        sheet.getRange().get("A8").getComment().setText("Frank has left the company.");
        sheet.getRange().get("F6").getComment().setText("Best sales.");

        //Set the height and width of the new comments
        sheet.getRange().get("A8").getComment().setHeight(50);
        sheet.getRange().get("A8").getComment().setWidth(100);
        sheet.getRange().get("F6").getComment().setAutoSize(true);

        //Save to file.
        wb.saveToFile("ModifyComment.xlsx",ExcelVersion.Version2013);
        wb.dispose();
    }
}

Java: Edit or Remove Comments in Excel

Remove Comments in Excel

The following are steps to remove a comment in Excel:

  • Java
import com.spire.xls.*;

public class DeleteComment {
    public static void main(String[] args) {
        
        //Create a Workbook instance
        Workbook wb = new Workbook();
        
        //Load an Excel file
        wb.loadFromFile("Comments.xlsx");

        //Get the first worksheet
        Worksheet sheet = wb.getWorksheets().get(0);

        //Get the comment in a specific cell and remove it
        sheet.getRange().get("F6").getComment().remove();

        //Save to file.
        wb.saveToFile("DeleteComment.xlsx", ExcelVersion.Version2013);
        wb.dispose();
    }
}

Java: Edit or Remove Comments in Excel

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.

A digital signature confirms that the document content originates from the signer and has not been changed. In this article, you will learn how to add a digital signature to your PowerPoint documents as well as remove all digital signatures using Spire.Presentation for Java.

Installl Spire.Presentation for Java

First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>10.11.4</version>
    </dependency>
</dependencies>

Add a Digital Signature to PowerPoint

The following are the steps to add a digital signature to a PowerPoint document.

  • Create an object of Presentation class.
  • Load the sample PowerPoint document using Presentation.loadFromFile() method.
  • Add a digital signature to the document using Presentation.addDigitalSignature(String pfxPath, String password, String comments, java.util.Date signTime) method.
  • Save the result to a .pptx file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

import java.util.Date;

public class AddDigitalSignature {
    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load the sample PowerPoint document
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");

        //Add a digital signature
        String pfxPath = "C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx";
        String password = "e-iceblue";
        String comment = "Modification is not allowed";
        presentation.addDigitalSignature(pfxPath,password,comment,new Date());

        //Save the result to file
        presentation.saveToFile("output/AddDigitalSignature.pptx", FileFormat.PPTX_2013);
    }
}

Java: Add or Remove Digital Signatures in PowerPoint

Remove all Digital Signaters from PowerPoint

The following are steps to remove all digital signatures from a PowerPoint document.

  • Create an object of Presentation class.
  • Load the sample PowerPoint document using Presentation.loadFromFile() method.
  • Determine if the document contains digital signatures using Presentation.isDigitallySigned() method.
  • Remove all signatures using Presentation.removeAllDigitalSignatures() method.
  • Save the result to a .pptx file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class RemoveDigitalSignature {
    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load the sample PowerPoint document
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\AddDigitalSignature.pptx");

        //Determine if the document is digitally signed
        if (presentation.isDigitallySigned() == true)
        {
            //Remove all digital signatures
            presentation.removeAllDigitalSignatures();
        }

        //Save the result to file
        presentation.saveToFile("output/RemoveDigitalSignature.pptx", FileFormat.PPTX_2013);
    }
}

Java: Add or Remove Digital Signatures in PowerPoint

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 107

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details