public interface PdfSaveAsImageHandler
PdfDocument.saveAsImage() method tries to
save the image of a page. User classes can implement this interface
to track or control how images are saved.
import java.io.IOException;
import com.gnostice.pdfone.PDFOne;
import com.gnostice.pdfone.PdfDocument;
import com.gnostice.pdfone.PdfException;
import com.gnostice.pdfone.PdfReader;
import com.gnostice.pdfone.PdfSaveAsImageHandler;
public class PdfSaveAsImageHandler_Example implements
PdfSaveAsImageHandler
{
static
{
PDFOne.activate("T95VZE:W8HBPVA:74VQ8QV:LO4V8",
"9B1HRZAP:X5853ERNE:5EREMEGRQ:TX1R10");
}
public static void main(String args[]) throws IOException,
PdfException
{
// Read document passed in command line
PdfReader reader = PdfReader.fileReader(args[0]);
PdfDocument doc1 = new PdfDocument(reader);
// Specify object implementing onSaveAsImage() event
doc1.setSaveAsImageHandler(
new PdfSaveAsImageHandler_Example());
// Save pages 1 and 2 of the read document as images
doc1.saveAsImage("jpg", "1,2", "image_of_page_#", ".");
reader.dispose();
}
// Append page number to the names of the images
public void onSaveAsImage(PdfDocument pdfDocument, int pageNum,
StringBuffer imageName, StringBuffer outputPath)
{
imageName = imageName.append(String.valueOf(pageNum));
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
onSaveAsImage(PdfDocument pdfDocument,
int pageNum,
StringBuffer imageName,
StringBuffer outputPath)
Called by an overloaded
PdfDocument.saveAsImage()
method when it tries to save an image of a page or several
pages. |
void onSaveAsImage(PdfDocument pdfDocument, int pageNum, StringBuffer imageName, StringBuffer outputPath)
PdfDocument.saveAsImage()
method when it tries to save an image of a page or several
pages. User classes implementing this interface can handle this
event to make further changes to imageName and
outputPath at run time.pdfDocument - document from which image is savedpageNum - number of the page whose image is savedimageName - name of the imageoutputPath - path of location where the image is saved