Convert specific pages

Use the setPageNumbers method of DocumentConvertOptions to convert only selected pages (or worksheets) from the source document. Page numbering starts from 1.

Using static method

import com.groupdocs.markdown.*;

public class SpecificPagesStatic {

    public static void main(String[] args) {
        DocumentConvertOptions options = new DocumentConvertOptions();
        options.setPageNumbers(new int[] { 1, 3 });

        // Convert only pages 1 and 3
        MarkdownConverter.toFile("business-plan.docx", "specific-pages-static.md", options);
    }
}

business-plan.docx is a sample file used in this example. Click here to download it.

![](data:...;base64,[elided])

**Meridian Outdoor Co. — Business Plan**

FY2026 Strategic Plan


# **1. Executive Summary**

Meridian Outdoor Co. is a direct-to-consumer outdoor apparel and gear brand serving thru-hikers, backcountry travelers, and weekend adventurers. This plan outlines our strategy for fiscal year 2026, a year in which we expect to grow revenue by forty percent, expand into three new retail categories, and launch our sustainability certification program.
[TRUNCATED]

Download full output

Using instance API

import com.groupdocs.markdown.*;

public class SpecificPagesInstance {

    public static void main(String[] args) {
        try (MarkdownConverter converter = new MarkdownConverter("business-plan.docx")) {
            DocumentConvertOptions options = new DocumentConvertOptions();
            options.setPageNumbers(new int[] { 1, 3 });

            converter.convert("specific-pages-instance.md", options);
        }
    }
}

business-plan.docx is a sample file used in this example. Click here to download it.

![](data:...;base64,[elided])

**Meridian Outdoor Co. — Business Plan**

FY2026 Strategic Plan


# **1. Executive Summary**

Meridian Outdoor Co. is a direct-to-consumer outdoor apparel and gear brand serving thru-hikers, backcountry travelers, and weekend adventurers. This plan outlines our strategy for fiscal year 2026, a year in which we expect to grow revenue by forty percent, expand into three new retail categories, and launch our sustainability certification program.
[TRUNCATED]

Download full output

Save specific pages to a file

import com.groupdocs.markdown.*;

public class SpecificPagesFile {

    public static void main(String[] args) {
        DocumentConvertOptions options = new DocumentConvertOptions();
        options.setPageNumbers(new int[] { 2, 4, 5 });

        MarkdownConverter.toFile("business-plan.pdf", "specific-pages-file.md", options);
    }
}

business-plan.pdf is a sample file used in this example. Click here to download it.

**Table of Contents**

MeridianOutdoorCo.—BusinessPlan.........................................................................................1

FY2026StrategicPlan.................................................................................................................1

TableofContents.............................................................................................................................2

1.ExecutiveSummary..........................................................
[TRUNCATED]

Download full output

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.