Hi,
i have the requirement that a user must not be able to select a text inside the pdf document. So i thought the best way to achieve this is to convert each page inside the pdf document into an image.
I already have a working code for that functionality but unfortunately the conversion from each page into an image is extremely slow.
Does anybody know a better / faster solution to transform each pdf page into an image ?
For example converting a pdf document with > 200 pages takes more than half an hour
Here is my code:
final Resolution resolution = new Resolution(200);
final JpegDevice jpegDevice = new JpegDevice(resolution);
// 4. Wandle jede Seite in eine Bilddatei um und füge diese in das end Dokument ein
start = System.currentTimeMillis();
final Document resultDocument = new Document();
for (int i = 1; i <= asposeDocument.getPages().size(); i++)
{
final Page sourcePage = asposeDocument.getPages().get_Item(i);
final Page targetPage = resultDocument.getPages().add();
try (ByteArrayOutputStream baos = new ByteArrayOutputStream())
{
jpegDevice.process(sourcePage, baos);
try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()))
{
targetPage.addImage(bais, new com.aspose.pdf.Rectangle(0, targetPage.getPageInfo().getHeight(),
targetPage.getPageInfo().getWidth(), 0));
}
}
}
log.info("Converting pdf page to image took: " + (System.currentTimeMillis() - start) + " ms");