Skip to content

Instantly share code, notes, and snippets.

@JoelGeraci-Datalogics
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoelGeraci-Datalogics/64cbe688e6647f8449ff to your computer and use it in GitHub Desktop.
Save JoelGeraci-Datalogics/64cbe688e6647f8449ff to your computer and use it in GitHub Desktop.
This Gist will convert each page of a PDF file to a SWF file.
/*
* Copyright Datalogics, Inc. 2015
*/
package pdfjt.cookbook.document;
import java.io.InputStream;
import java.net.URL;
import pdfjt.util.SampleFileServices;
import pdfjt.util.SampleFontLoaderUtil;
import com.adobe.internal.io.ByteReader;
import com.adobe.internal.io.ByteWriter;
import com.adobe.internal.io.InputStreamByteReader;
import com.adobe.pdfjt.core.fontset.PDFFontSet;
import com.adobe.pdfjt.pdf.document.PDFDocument;
import com.adobe.pdfjt.pdf.document.PDFOpenOptions;
import com.adobe.pdfjt.pdf.page.PDFPage;
import com.adobe.pdfjt.services.swf.PDFToSWFConverter;
import com.adobe.pdfjt.services.swf.SWFConversionOptions;
/**
* This sample will convert each page of a PDF file to a SWF file using the
* default conversion options.
*/
public class ConvertPDFToSWF {
private static final String inputPDF = "http://dev.datalogics.com/cookbook/document/pdfjavatoolkit-ds.pdf";
private static final String outputDir = "cookbook/Document/output/";
public static void main(String[] args) throws Exception {
try {
/*
* Read the PDF input file and convert each page to a SWF file.
*/
InputStream fis = new URL(inputPDF).openStream();
ByteReader byteReader = new InputStreamByteReader(fis);
PDFDocument pdfDocument = PDFDocument.newInstance(byteReader, PDFOpenOptions.newInstance());
PDFFontSet pdfFontSet = SampleFontLoaderUtil.loadSampleFontSet();
ByteWriter outputFile = null;
PDFPage pdfPage = null;
int numPages = pdfDocument.requirePages().size();
for (int pageNum = 0; pageNum < numPages; pageNum++) {
pdfPage = pdfDocument.requirePages().getPage(pageNum);
outputFile = SampleFileServices.getRAFByteWriter(outputDir + "pdfjavatoolkit-ds_" + String.valueOf(pageNum) + ".swf");
PDFToSWFConverter.toSWF(pdfPage, pdfFontSet, new SWFConversionOptions(), outputFile);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment