Setting PDF Export Options programmatically to export only certain page range to PDF

800 views
Skip to first unread message

tsaixingwei

unread,
Oct 17, 2011, 6:33:24 AM10/17/11
to JODConverter
Hi,

I've read this post: http://groups.google.com/group/jodconverter/browse_thread/thread/578ace3b9ba1d32b

and also this page: http://www.artofsolving.com/node/18

but I still couldn't figure out how to set the PDF Export Options
programmatically (and not through the static file document-
formats.xml)
to export only a certain range of pages to PDF.

Can anyone show me how? I imagine that it could look something like
this:
pdfOptions.put("EncryptFile", Boolean.TRUE);

but I don't know what the option name string should be for a page
range.

Thanks in advance.

tsaixingwei

unread,
Oct 17, 2011, 6:35:38 AM10/17/11
to JODConverter
By the way, I'm using JODConverter v3.0-beta-4.



On Oct 17, 6:33 pm, tsaixingwei <tsaixing...@gmail.com> wrote:
> Hi,
>
> I've read this post:http://groups.google.com/group/jodconverter/browse_thread/thread/578a...

Yahya Abdullah

unread,
Oct 17, 2011, 7:51:09 AM10/17/11
to JODConverter
Here is the sample code for doing so:

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.document.DocumentFamily;
import org.artofsolving.jodconverter.document.DocumentFormat;
import
org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeConnectionProtocol;
import org.artofsolving.jodconverter.office.OfficeManager;

public class TestConverter {
public static void main(String[] args) {
OfficeManager officeManager = new
DefaultOfficeManagerConfiguration().setOfficeHome("C:\\Program Files
(x86)\\OpenOffice.org
3").setConnectionProtocol(OfficeConnectionProtocol.SOCKET)
.setPortNumber(9999).setTaskExecutionTimeout(30000L).buildOfficeManager();

officeManager.start();

try {

String pageRange = "1-3"; // = "3";
DocumentFormat documentFormat =
TestConverter.getDocumentFormat(pageRange);


OfficeDocumentConverter converter = new
OfficeDocumentConverter(officeManager);
long start = System.currentTimeMillis();
converter.convert(new File(args[0]), new File(args[1]),
documentFormat);
long end = System.currentTimeMillis();
double duration = (end - start) / 1000d;
System.out.println("Conversion took: " + duration + "seconds.");
} finally {
officeManager.stop();
}
}

public static DocumentFormat getDocumentFormat(String pageRange) {
DocumentFormat format = new DocumentFormat("Portable Document
Format", "pdf", "application/pdf");

Map<String, Object> properties1 = new HashMap<String, Object>();
properties1.put("FilterName", "writer_pdf_Export");
Map<String, Object> filterData1 = new HashMap<String, Object>();
filterData1.put("PageRange", pageRange);
properties1.put("FilterData", filterData1);
format.setStoreProperties(DocumentFamily.TEXT, properties1);

Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put("FilterName", "draw_pdf_Export");
Map<String, Object> filterData2 = new HashMap<String, Object>();
filterData2.put("PageRange", pageRange);
properties2.put("FilterData", filterData2);
format.setStoreProperties(DocumentFamily.DRAWING, properties2);

Map<String, Object> properties3 = new HashMap<String, Object>();
properties3.put("FilterName", "impress_pdf_Export");
Map<String, Object> filterData3 = new HashMap<String, Object>();
filterData3.put("PageRange", pageRange);
properties3.put("FilterData", filterData3);
format.setStoreProperties(DocumentFamily.PRESENTATION,
properties3);

Map<String, Object> properties4 = new HashMap<String, Object>();
properties4.put("FilterName", "calc_pdf_Export");
Map<String, Object> filterData4 = new HashMap<String, Object>();
filterData4.put("PageRange", pageRange);
properties4.put("FilterData", filterData4);
format.setStoreProperties(DocumentFamily.SPREADSHEET, properties4);

return format;

Yahya Abdullah

unread,
Oct 17, 2011, 7:49:40 AM10/17/11
to JODConverter
Here is the sample code:
Reply all
Reply to author
Forward
0 new messages