Presenting information in a logical sequence is vital for an effective PowerPoint presentation. Reordering slides in a PowerPoint document gives you the flexibility to fine-tune your presentation and ensure that it delivers your message with maximum impact. By organizing your slides strategically, you can create a dynamic and engaging presentation experience.

In this article, you will learn how to reorder slides in a PowerPoint document in Java using the Spire.Presentation for Java library.

Install 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>11.5.1</version>
    </dependency>
</dependencies>

Reorder Slides in a PowerPoint Document in Java

To rearrange the slides in a PowerPoint presentation, you need to create two presentation objects. One object will be used to load the original document while the other will be used to create a new document. By copying the slides from the original document to the new document in the desired order, you can effectively rearrange the slides.

The following are the steps to rearrange slides in a PowerPoint document using Java.

  • Create a Presentationobject.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Specify the slide order within an array.
  • Create another Presentation object for creating a new presentation.
  • Add the slides from the original document to the new presentation in the specified order using Presentation.getSlides().append() method.
  • Save the new presentation to a PPTX file using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class ReorderSlides {

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

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

        // Load a PowerPoint file
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\input.pptx");

        // Specify the new slide order within an array
        int[] newSlideOrder = new int[] { 3, 4, 1, 2 };

        // Create another Presentation object
        Presentation new_presentation = new Presentation();

        // Remove the default slide
        new_presentation.getSlides().removeAt(0);

        // Iterate through the array
        for (int i = 0; i < newSlideOrder.length; i++)
        {
            // Add the slides from the original PowerPoint file to the new PowerPoint document in the new order
            new_presentation.getSlides().append(presentation.getSlides().get(newSlideOrder[i] - 1));
        }

        // Save the new presentation to file
        new_presentation.saveToFile("output/NewOrder.pptx", FileFormat.PPTX_2019);

        // Dispose resources
        presentation.dispose();
        new_presentation.dispose();
    }
}

Java: Reorder Slides in a PowerPoint Document

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: Extract Bookmarks from PDF

2024-06-04 01:03:28 Written by Koohji

Bookmarks in PDF function as interactive table of contents, allowing users to quickly jump to specific sections within the document. Extracting these bookmarks not only provides a comprehensive overview of the document's structure, but also reveals its core parts or key information, providing users with a streamlined and intuitive method of accessing content. In this article, you will learn how to extract PDF bookmarks in Java using Spire.PDF for Java.

Install Spire.PDF for Java

First of all, you're required to add the Spire.Pdf.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.pdf</artifactId>
        <version>12.7.0</version>
    </dependency>
</dependencies>

Extract Bookmarks from PDF in Java

With Spire.PDF for Java, you can create custom methods GetBookmarks() and GetChildBookmark() to get the title and text styles of both parent and child bookmarks in a PDF file, then export them to a TXT file. The following are the detailed steps.

  • Create a PdfDocument instance.
  • Load a PDF file using PdfDocument.loadFromFile() method.
  • Get bookmarks collection in the PDF file using PdfDocument.getBookmarks() method.
  • Call custom methods GetBookmarks() and GetChildBookmark() to get the text content and text style of parent and child bookmarks.
  • Export the extracted PDF bookmarks to a TXT file.
  • Java
import com.spire.pdf.*;
import com.spire.pdf.bookmarks.*;
import java.io.*;

public class getAllPdfBookmarks {
    public static void main(String[] args) throws IOException{
        //Create a PdfDocument instance
        PdfDocument pdf = new PdfDocument();

        //Load a PDF file
        pdf.loadFromFile("AnnualReport.pdf");

        //Get bookmarks collections of the PDF file
        PdfBookmarkCollection bookmarks = pdf.getBookmarks();

        //Get the contents of bookmarks and save them to a TXT file
        GetBookmarks(bookmarks, "GetPdfBookmarks.txt");

    }

    private static void GetBookmarks(PdfBookmarkCollection bookmarks, String result) throws IOException {
        //create a StringBuilder instance
        StringBuilder content = new StringBuilder();

        //Get parent bookmarks information
        if (bookmarks.getCount() > 0) {
            content.append("Pdf bookmarks:");
            for (int i = 0; i < bookmarks.getCount(); i++) {
                PdfBookmark parentBookmark = bookmarks.get(i);
                content.append(parentBookmark.getTitle() + "\r\n");

                //Get the text style
                String textStyle = parentBookmark.getDisplayStyle().toString();
                content.append(textStyle + "\r\n");
                GetChildBookmark(parentBookmark, content);
            }
        }

        writeStringToTxt(content.toString(),result);
    }

    private static void GetChildBookmark(PdfBookmark parentBookmark, StringBuilder content)
    {
        //Get child bookmarks information
        if (parentBookmark.getCount() > 0)
        {
            content.append("Pdf bookmarks:" + "\r\n");
            for (int i = 0; i < parentBookmark.getCount(); i++)
            {
                PdfBookmark childBookmark = parentBookmark.get(i);
                content.append(childBookmark.getTitle() +"\r\n");

                //Get the text style
                String textStyle = childBookmark.getDisplayStyle().toString();
                content.append(textStyle +"\r\n");
                GetChildBookmark(childBookmark, content);
            }
        }
    }
    public static void writeStringToTxt(String content, String txtFileName) throws IOException {
        FileWriter fWriter = new FileWriter(txtFileName, true);
        try {
            fWriter.write(content);
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                fWriter.flush();
                fWriter.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}

Java: Extract Bookmarks from PDF

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: Convert Markdown to Word and PDF

2024-05-28 01:25:53 Written by Koohji

Markdown is a popular format among writers and developers for its simplicity and readability, allowing content to be formatted using easy-to-write plain text syntax. However, converting Markdown files to universally accessible formats like Word documents and PDF files is essential for sharing documents with readers, enabling complex formatting, and ensuring capability and consistency across devices and platforms. This article demonstrates how to convert Markdown files to Word and PDF files with the powerful library Spire.Doc for Java, enhancing the versatility and distribution potential of your written content.

Install Spire.Doc for Java

First of all, you're required to add the Spire.Doc.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.doc</artifactId>
        <version>14.7.0</version>
    </dependency>
</dependencies>

Convert a Markdown File to a Word Document with Java

Spire.Doc for Java provides a simple way to convert Markdown format to Word and PDF document formats by using the Document.loadFromFile(String: fileName, FileFormat.Markdown) method to load the Markdown file and the Document.saveToFile(String: fileName, FileFormat: fileFormat) method to save the file as a Word or PDF document.

It should be noted that since images are stored as links in Markdown files, they need to be further processed after conversion if they are to be retained.

The detailed steps for converting a Markdown file to a Word document are as follows:

  • Create an instance of Document class.
  • Load a Markdown file using Document.loadFromFile(String: fileName, FileFormat.Markdown) method.
  • Save the Markdown file as Word document using Document.saveToFile(String: fileName, FileFormat.Docx) method.
  • Java
import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class MarkdownToWord {
    public static void main(String[] args) {
        // Create an instance of Document
        Document doc = new Document();

        // Load a Markdown file
        doc.loadFromFile("Sample.md", FileFormat.Markdown);

        // Save the Markdown file as Word document
        doc.saveToFile("output/MarkdownToWord.docx", FileFormat.Docx);
        doc.dispose();
    }
}

Java: Convert Markdown to Word and PDF

Convert a Markdown File to a PDF Document with Java

By using the FileFormat.PDF Enum as the format parameter of the Document.saveToFile() method, the Markdown file can be directly converted to a PDF document.

The detailed steps for converting a Markdown file to a PDF document are as follows:

  • Create an instance of Document class.
  • Load a Markdown file using Document.loadFromFile(String: fileName, FileFormat.Markdown) method.
  • Save the Markdown file as PDF document using Document.saveToFile(String: fileName, FileFormat.PDF) method.
  • Java
import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class MarkdownToPDF {
    public static void main(String[] args) {
        // Create an instance of the Document class
        Document doc = new Document();

        // Load a Markdown file
        doc.loadFromFile("Sample.md");

        // Save the Markdown file as a PDF file
        doc.saveToFile("output/MarkdownToPDF.pdf", FileFormat.PDF);
        doc.dispose();
    }
}

Java: Convert Markdown to Word and PDF

Customizing Page Settings of the Result Document

Spire.Doc for Java also provides methods under PageSetup class to do page setup before the conversion, allowing control over page settings such as page margins and page size of the resulting document.

The following are the steps to customize the page settings of the resulting document:

  • Create an instance of Document class.
  • Load a Markdown file using Document.loadFromFile(String: fileName, FileFormat.Markdown) method.
  • Get the first section using Document.getSections().get() method.
  • Set the page size, page orientation, and page margins using methods under PageSetup class.
  • Save the Markdown file as PDF document using Document.saveToFile(String: fileName, FileFormat.PDF) method.
  • Java
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.PageSetup;
import com.spire.doc.Section;
import com.spire.doc.documents.MarginsF;
import com.spire.doc.documents.PageOrientation;
import com.spire.doc.documents.PageSize;

public class PageSettingMarkdown {
    public static void main(String[] args) {
        // Create an instance of the Document class
        Document doc = new Document();

        // Load a Markdown file
        doc.loadFromFile("Sample.md");

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

        // Set the page size, orientation, and margins
        PageSetup pageSetup = section.getPageSetup();
        pageSetup.setPageSize(PageSize.Letter);
        pageSetup.setOrientation(PageOrientation.Landscape);
        pageSetup.setMargins(new MarginsF(100, 100, 100, 100));

        // Save the Markdown file as a PDF file
        doc.saveToFile("output/MarkdownToPDF.pdf", FileFormat.PDF);
        doc.dispose();
    }
}

Java: Convert Markdown to Word and PDF

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 8 of 81
page 8