Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
Hi, I am new in Joget. I want to Run Process whereby if User upload File Document ( pdf ) it will convert into Image (jpeg/png). I found that it is possible if doing Java hardcode project, however how can i do it inside Joget?
package com.roytuts.java.pdf.to.image;
import java.awt.image.BufferedImage;import java.io.File;
import javax.imageio.ImageIO;
import org.apache.pdfbox.pdmodel.PDDocument;import org.apache.pdfbox.rendering.PDFRenderer;
public class PdfToImageConverter {
public static void main(String[] args) { try { String destinationDir = "pdf-to-image/";
File sourceFile = new File("sample.pdf"); File destinationFile = new File(destinationDir);
if (!destinationFile.exists()) { destinationFile.mkdir(); System.out.println("Folder Created -> " + destinationFile.getAbsolutePath()); }
if (sourceFile.exists()) { PDDocument document = PDDocument.load(sourceFile); PDFRenderer pdfRenderer = new PDFRenderer(document);
String fileName = sourceFile.getName().replace(".pdf", "");
// int pageNumber = 0;
// for (PDPage page : document.getPages()) { for (int pageNumber = 0; pageNumber < document.getNumberOfPages(); ++pageNumber) { BufferedImage bim = pdfRenderer.renderImage(pageNumber);
String destDir = destinationDir + fileName + "_" + pageNumber + ".png";
ImageIO.write(bim, "png", new File(destDir)); }
document.close();
System.out.println("Image saved at -> " + destinationFile.getAbsolutePath()); } else { System.err.println(sourceFile.getName() + " File does not exist"); } } catch (Exception e) { e.printStackTrace(); } }
}
Hi, you will need to use that code either in a BeanShell script, or as part of a Joget plugin.
Hi, I am new in Joget. I want to Run Process whereby if User upload File Document ( pdf ) it will convert into Image (jpeg/png). I found that it is possible if doing Java hardcode project, however how can i do it inside Joget?
package com.roytuts.java.pdf.to.image;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
public class PdfToImageConverter {
public static void main(String[] args) {
try {
String destinationDir = "pdf-to-image/";
File sourceFile = new File("sample.pdf");
File destinationFile = new File(destinationDir);
if (!destinationFile.exists()) {
destinationFile.mkdir();
System.out.println("Folder Created -> " + destinationFile.getAbsolutePath());
}
if (sourceFile.exists()) {
PDDocument document = PDDocument.load(sourceFile);
PDFRenderer pdfRenderer = new PDFRenderer(document);
String fileName = sourceFile.getName().replace(".pdf", "");
// int pageNumber = 0;
// for (PDPage page : document.getPages()) {
for (int pageNumber = 0; pageNumber < document.getNumberOfPages(); ++pageNumber) {
BufferedImage bim = pdfRenderer.renderImage(pageNumber);
String destDir = destinationDir + fileName + "_" + pageNumber + ".png";
ImageIO.write(bim, "png", new File(destDir));
}
document.close();
System.out.println("Image saved at -> " + destinationFile.getAbsolutePath());
} else {
System.err.println(sourceFile.getName() + " File does not exist");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}