This article shows you how to create a multi-level list in a PDF document using Spire.PDF for Java.

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfNumberStyle;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.PdfPageSize;
import com.spire.pdf.graphics.*;
import com.spire.pdf.lists.PdfListItem;
import com.spire.pdf.lists.PdfOrderedMarker;
import com.spire.pdf.lists.PdfSortedList;

import java.awt.*;
import java.awt.geom.Point2D;

public class CreateMultiLevelList {

    public static void main(String[] args) {

        //Create a PdfDocument object
        PdfDocument doc = new PdfDocument();

        //Set the margin
        PdfMargins margin = new PdfMargins(60, 60, 40, 40);

        //Create one page
        PdfPageBase page = doc.getPages().add(PdfPageSize.A4, margin);

        //Specify the initial coordinate
        float x = 0;
        float y = 15;

        //Create two brushed
        PdfBrush blackBrush = PdfBrushes.getBlack();
        PdfBrush purpleBrush = PdfBrushes.getPurple();

        //Create two fonts
        PdfTrueTypeFont titleFont = new PdfTrueTypeFont(new java.awt.Font("Times New Roman", Font.BOLD, 12));
        PdfTrueTypeFont listFont = new PdfTrueTypeFont(new java.awt.Font("Calibri Light", Font.PLAIN, 12));

        //Draw title
        String title = "XHTML Tutorials/FAQs:";
        page.getCanvas().drawString(title, titleFont, blackBrush, x, y);
        y = y + (float) titleFont.measureString(title).getHeight();
        y = y + 5;

        //Create two ordered makers, which are used to define the number style of sorted list
        PdfOrderedMarker marker1 = new PdfOrderedMarker(PdfNumberStyle.Upper_Roman, listFont);
        PdfOrderedMarker marker2 = new PdfOrderedMarker(PdfNumberStyle.Numeric, listFont);

        //Create a parent list
        String parentListContent = "Introduction To XHTML 1.0\n"
                + "Introduction To Tag and Attribute Syntax";
        PdfSortedList parentList = new PdfSortedList(parentListContent);
        parentList.setFont(listFont);
        parentList.setIndent(8);
        parentList.setBrush(purpleBrush);
        parentList.setMarker(marker1);

        //Create a sub list - "subList_1"
        String subListContent_1 = "What Is XHTML?\n"
                + "What Does an XHMTL Document Look Like?\n"
                + "What Is the Relation between XHTML and HTML?\n"
                + "What Is the Relation between XHTML and XML?";
        PdfSortedList subList_1 = new PdfSortedList(subListContent_1);
        subList_1.setIndent(16);
        subList_1.setFont(listFont);
        subList_1.setBrush(purpleBrush);
        subList_1.setMarker(marker2);

        //Create another sub list -"subList_2"
        String subListContent_2 = "What Is an XHTML Element?\n"
                + "How To Enter Comments into XHTML Documents?\n"
                + "How To Write the Opening Tag of an XHTML Element?";
        PdfSortedList subList_2 = new PdfSortedList(subListContent_2);
        subList_2.setIndent(16);
        subList_2.setFont(listFont);
        subList_2.setBrush(purpleBrush);
        subList_2.setMarker(marker2);

        //Set subList_1 as sub list of the first item of parent list
        PdfListItem item_1 = parentList.getItems().get(0);
        item_1.setSubList(subList_1);

        //Set subList_2 as sub list of the second item of parent list
        PdfListItem item_2 = parentList.getItems().get(1);
        item_2.setSubList(subList_2);

        //Draw parent list
        PdfTextLayout textLayout = new PdfTextLayout();
        textLayout.setBreak(PdfLayoutBreakType.Fit_Page);
        textLayout.setLayout(PdfLayoutType.Paginate);
        parentList.draw(page,new Point2D.Float(x,y),textLayout);

        //Save to file
        doc.saveToFile("MultiLevelList.pdf");
    }
}

Create a Multi-Level List in PDF in Java

This article will show you how to use Spire.Doc for Java to set the character spacing and paragraph spacing on Word.

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.TextRange;

import java.awt.*;
import java.io.*;

public class setSpacing {
    public static void main(String[] args)throws IOException {
        //Load the sample document
        Document document= new Document("Sample1.docx");

        //Add a new paragraph and append the text
        Paragraph para = new Paragraph(document);
        TextRange textRange1 = para.appendText("Newly added paragraph and set the paragraph spacing and character spacing");
        textRange1.getCharacterFormat().setTextColor(Color.blue);
        textRange1.getCharacterFormat().setFontSize(14);

        //Set the spacing before and after paragraph
        para.getFormat().setBeforeAutoSpacing(false);
        para.getFormat().setBeforeSpacing(10);
        para.getFormat().setAfterAutoSpacing(false);
        para.getFormat().setAfterSpacing(10);

        //Set the character spacing
        for (DocumentObject object :(Iterable<DocumentObject>)para.getChildObjects())
        {
            TextRange textRange= (TextRange) object;
            textRange.getCharacterFormat().setCharacterSpacing(3f);
        }

        //Insert the paragraph
        document.getSections().get(0).getParagraphs().insert(2, para);

        //Save the document to file
        document.saveToFile("Result.docx", FileFormat.Docx);

    }
}

Output:

Java set the character spacing and paragraph spacing on Word document

A digital signature is a modern alternative to signing documents manually on paper with pen. It uses an advanced mathematical technique to check the authenticity and integrity of digital documents, which guarantees that the contents in a digital document comes from the signer and has not been altered since then. Sometimes PowerPoint documents that contain confidential information may require a signature. In this article, you will learn how to programmatically add or remove digital signatures in PowerPoint 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

Add a Digital Signature to PowerPoint in C# and VB.NET

To add a digital signature, you'll need to have a valid signature certificate first. Then you can digitally sign a PowerPoint document with the certificate using Presentation.AddDigitalSignature (X509Certificate2 certificate, string comments, DateTime signTime) method. The detailed steps are as follows.

  • Create a Presentation instance.
  • Load a sample PowerPoint document using Presentation.LoadFromFile() method.
  • Initializes an instance of X509Certificate2 class with the certificate file name and password.
  • Add a digital signature to the PowerPoint document using Presentation.AddDigitalSignature (X509Certificate2 certificate, string comments, DateTime signTime) method.
  • Save result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using System;
using System.Security.Cryptography.X509Certificates;

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

            //Load a PowerPoint document
            ppt.LoadFromFile("input.pptx");

            //Load the certificate
            X509Certificate2 x509 = new X509Certificate2("gary.pfx", "e-iceblue");

            //Add a digital signature
            ppt.AddDigitalSignature(x509, "e-iceblue", DateTime.Now);

            //Save the result document
            ppt.SaveToFile("AddDigitalSignature.pptx", FileFormat.Pptx2013);
        }
    }
}

C#/VB.NET: Add or Remove Digital Signatures in PowerPoint

Remove All Digital Signatures from PowerPoint in C# and VB.NET

At some point you may need to remove the digital signatures from a PowerPoint document. Spire.Presentation for .NET provides the Presentation.RemoveAllDigitalSignatures() method to remove all digital signatures at once. The detailed steps are as follows:

  • Create a Presentation instance.
  • Load a sample PowerPoint document using Presentation.LoadFromFile() method.
  • Determine if the document contains digital signatures using Presentation.IsDigitallySigned property.
  • Remove all digital signatures from the document using Presentation.RemoveAllDigitalSignatures() method.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;

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

            //Load a PowerPoint document 
            ppt.LoadFromFile("AddDigitalSignature.pptx");

            //Detect if the document is digitally signed
            if (ppt.IsDigitallySigned == true)
            {
                //Remove all digital signatures
                ppt.RemoveAllDigitalSignatures();
            }

            //Save the result document
            ppt.SaveToFile("RemoveDigitalSignature.pptx", FileFormat.Pptx2013);

        }
    }
}

C#/VB.NET: 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.

Saturday, 08 May 2021 03:26

Add image comment to Excel in Java

We have demonstrated how to add and read text comments in Excel in Java applications. This article will show you how to insert image comment to Excel with Spire.XLS for Java.

import com.spire.xls.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;

public class Test {
    public static void main(String[] args)throws IOException {
        //Load the sample Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Sample.xlsx");
        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //set the font
        ExcelFont font = workbook.createFont();
        font.setFontName("Arial");
        font.setSize(11);
        font.setKnownColor(ExcelColors.Orange);

        CellRange range = sheet.getCellRange("D1");
        //Add the commet
        ExcelComment comment = range.addComment();
        //Load the image
        BufferedImage bufferedImage = ImageIO.read(new File("Logo.jpg"));
        //Use the image to fill the comment
        comment.getFill().customPicture(bufferedImage, "Logo.jpg");

        //Set the height and width for the comment
        comment.setHeight(bufferedImage.getHeight());
        comment.setWidth(bufferedImage.getWidth());
        //Show the comment
        comment.setVisible(true);

        //Save the document to file
        workbook.saveToFile("output/setimageComment.xlsx", ExcelVersion.Version2013);

    }
}

Output:

Add image comment to Excel in Java

This article shows you how to download a PDF document from an URL using Spire.PDF with C# and VB.NET.

C#
using System.IO;
using System.Net;
using Spire.Pdf;

namespace DownloadPdfFromUrl
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument object
            PdfDocument doc = new PdfDocument();

            //Create a WebClient object
            WebClient webClient = new WebClient();

            //Download data from URL and save as memory stream
            using (MemoryStream ms = new MemoryStream(webClient.DownloadData("https://www.e-iceblue.com/article/toDownload.pdf")))
            {
                //Load the stream
                doc.LoadFromStream(ms);
            }

            //Save to PDF file
            doc.SaveToFile("result.pdf", FileFormat.PDF);
        }
    }
}
VB.NET
Imports System.IO
Imports System.Net
Imports Spire.Pdf

Namespace DownloadPdfFromUrl
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'Create a PdfDocument object
            Dim doc As PdfDocument = New PdfDocument()
 
            'Create a WebClient object
            Dim webClient As WebClient = New WebClient()
 
            'Download data from URL and save as memory stream
            Imports(MemoryStream ms = New MemoryStream(webClient.DownloadData("https:'www.e-iceblue.com/article/toDownload.pdf")))
            {
                'Load the stream
                doc.LoadFromStream(ms)
            }
 
            'Save to PDF file
            doc.SaveToFile("result.pdf", FileFormat.PDF)
        End Sub
    End Class
End Namespace

Download PDF Document from URL in C#, VB.NET

This article will show you how to replace the searched text with image in Excel worksheet by using Spire.XLS in Java applications.

Sample Excel:

Java replace the text with image in Excel worksheet

import com.spire.xls.*;
import java.io.IOException;

public class replaceTextwithImage {
    public static void main(String[] args) throws IOException {

        //Load the sample Excel document
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Sample.xlsx");
        //Get the first worksheet
        Worksheet worksheet = workbook.getWorksheets().get(0);

        //Find the text string {{Image}}
        CellRange[] ranges = worksheet.findAllString("{{Image}}", false, false);
        for (CellRange range : ranges) {
            //set the text as null
            range.setText("");

            //get the row and column of the searched range
            int row = range.getRow();
            int column = range.getColumn();
            //Add the image to the searched range
            worksheet.getPictures().add(row, column, "logo.jpg", ImageFormatType.Jpeg);

            //Save the document to file
            workbook.saveToFile("replaceTextwithImage.xlsx", ExcelVersion.Version2013);
            }
        }
    }

Output:

Java replace the text with image in Excel worksheet

This article shows you how to create a hyperlink to a bookmark within the same Word document by using Spire.Doc with C# and VB.NET.

C#
using Spire.Doc;
using Spire.Doc.Documents;

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

            //Add two sections
            Section section1 = doc.AddSection();
            Section section2 = doc.AddSection();

            //Insert a paragraph in section 2 and add a bookmark named "myBookmark" to it
            Paragraph bookmarkParagrapg = section2.AddParagraph();
            bookmarkParagrapg.AppendText("Here is a bookmark");
            BookmarkStart start = bookmarkParagrapg.AppendBookmarkStart("myBookmark");
            bookmarkParagrapg.Items.Insert(0, start);
            bookmarkParagrapg.AppendBookmarkEnd("myBookmark");

            //Link to the bookmark
            Paragraph paragraph = section1.AddParagraph();
            paragraph.AppendText("Link to a bookmark: ");
            paragraph.AppendHyperlink("myBookmark", "Jump to a location in this document", HyperlinkType.Bookmark);

            //Save to file
            doc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013);
        }
    }
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace LinkToBookmark
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'Create a Document object
            Document doc = New Document()
 
            'Add two sections
            Dim section1 As Section = doc.AddSection()
            Dim section2 As Section = doc.AddSection()
 
            'Insert a paragraph in section 2 and add a bookmark named "myBookmark" to it
            Dim bookmarkParagrapg As Paragraph = section2.AddParagraph()
            bookmarkParagrapg.AppendText("Here is a bookmark")
            Dim start As BookmarkStart = bookmarkParagrapg.AppendBookmarkStart("myBookmark")
            bookmarkParagrapg.Items.Insert(0, start)
            bookmarkParagrapg.AppendBookmarkEnd("myBookmark")
 
            'Link to the bookmark
            Dim paragraph As Paragraph = section1.AddParagraph()
            paragraph.AppendText("Link to a bookmark: ")
            paragraph.AppendHyperlink("myBookmark", "Jump to a location in this document", HyperlinkType.Bookmark)
 
            'Save to file
            doc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013)
        End Sub
    End Class
End Namespace

Link to a Bookmark in a Word Document in C#/VB.NET

Spire.XLS for Java supports to insert Word, Excel, PowerPoint slide and PDF as linked object or embedded object into Excel Worksheet. This article will show you how to insert a Word document as an embedded object into Excel by using Spire.XLS for Java in Java applications.

import com.spire.xls.*;
import com.spire.xls.core.IOleObject;
import com.spire.doc.*;
import com.spire.doc.documents.ImageType;
import java.awt.image.BufferedImage;

public class insertOLEObjects {
    public static void main(String[] args) {
        String docFile = "Sample.docx";
        String outputFile = "output/insertOLEObjects_result.xlsx";

        //Load the Excel document
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Sample.xlsx");
        //Get the first worksheet
        Worksheet worksheet = workbook.getWorksheets().get(0);

        //Generate image
        BufferedImage image = GenerateImage(docFile);
        //insert OLE object
        IOleObject oleObject = worksheet.getOleObjects().add(docFile, image, OleLinkType.Embed);
        oleObject.setLocation(worksheet.getCellRange("B4"));
        oleObject.setObjectType(OleObjectType.ExcelWorksheet);
        //Save the file
        workbook.saveToFile(outputFile, ExcelVersion.Version2010);
    }

    private static BufferedImage GenerateImage(String fileName) {

        //Load the sample word document
        Document document = new Document();
        document.loadFromFile(fileName);

        //Save the first page of word as an image
        BufferedImage image = document.saveToImages(0, ImageType.Bitmap);
        return image;
    }
}

Output:

Insert OLE Object in Excel in Java applications

This article shows you how to set ASCII characters (special symbols) as bullet points in Word documents using Spire.Doc for Java.

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.ListStyle;
import com.spire.doc.documents.ListType;
import com.spire.doc.documents.Paragraph;

public class SetBulletPoints {

    public static void main(String[] args) {

        //Create a Document object and add a section
        Document doc = new Document();
        Section section = doc.addSection();

        //Create four list styles based on different ASCII characters
        ListStyle listStyle1 = new ListStyle(doc, ListType.Bulleted);
        listStyle1.getLevels().get(0).setBulletCharacter("\u006e");
        listStyle1.getLevels().get(0).getCharacterFormat().setFontName("Wingdings");
        listStyle1.setName("liststyle1");
        doc.getListStyles().add(listStyle1);
        ListStyle listStyle2 = new ListStyle(doc, ListType.Bulleted);
        listStyle2.getLevels().get(0).setBulletCharacter("\u0075");
        listStyle2.getLevels().get(0).getCharacterFormat().setFontName("Wingdings");
        listStyle2.setName("liststyle2");
        doc.getListStyles().add(listStyle2);
        ListStyle listStyle3 = new ListStyle(doc, ListType.Bulleted);
        listStyle3.getLevels().get(0).setBulletCharacter("\u00b2");
        listStyle3.getLevels().get(0).getCharacterFormat().setFontName("Wingdings");
        listStyle3.setName("liststyle3");
        doc.getListStyles().add(listStyle3);
        ListStyle listStyle4 = new ListStyle(doc, ListType.Bulleted);
        listStyle4 .getLevels().get(0).setBulletCharacter("\u00d8");
        listStyle4 .getLevels().get(0).getCharacterFormat().setFontName("Wingdings");
        listStyle4.setName("liststyle4");
        doc.getListStyles().add(listStyle4);

        //Add four paragraphs and apply list style separately
        Paragraph p1 = section.getBody().addParagraph();
        p1.appendText("Spire.Doc for .NET");
        p1.getListFormat().applyStyle(listStyle1.getName());
        Paragraph p2 = section.getBody().addParagraph();
        p2.appendText("Spire.PDF for .NET");
        p2.getListFormat().applyStyle(listStyle2.getName());
        Paragraph p3 = section.getBody().addParagraph();
        p3.appendText("Spire.XLS for .NET");
        p3.getListFormat().applyStyle(listStyle3.getName());
        Paragraph p4= section.getBody().addParagraph();
        p4.appendText("Spire.Presentation for .NET");
        p4.getListFormat().applyStyle(listStyle4.getName());

        //Save to file
        doc.saveToFile("SetBulletCharacter.docx", FileFormat.Docx);
    }
}

Set ASCII Characters as Bullet Points in Word in Java

Monday, 12 April 2021 07:05

Add an Endnote to Word in Java

This article shows you how to add an endnote to Word documents using Spire.Doc for Java.

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.Footnote;
import com.spire.doc.fields.TextRange;

import java.awt.*;

public class AddEndnote {

    public static void main(String[] args) {

        //Create a Document object
        Document doc = new Document();

        //Load the sample Word file
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx");

        //Get the first section
        Section section = doc.getSections().get(0);

        //Get the specific paragraph to add endnote
        Paragraph paragraph = section.getParagraphs().get(2);

        //Add an endnote
        Footnote endnote = paragraph.appendFootnote(FootnoteType.Endnote);

        //Set endnote text
        TextRange textRange = endnote.getTextBody().addParagraph().appendText("This is an endnote created by Spire.Doc.");

        //Set text format of endnote
        textRange.getCharacterFormat().setFontName("Arial");
        textRange.getCharacterFormat().setFontSize(13f);
        textRange.getCharacterFormat().setTextColor(Color.RED);

        //Save to file
        doc.saveToFile("AddEndnote.docx", FileFormat.Docx_2013);
    }
}

Add an Endnote to Word in Java