How to Convert HEIC file to PDF
We would like to convert HEIC file to PDF.
I tried with below code which works for JPG ( convert JPG to PDF) but not working for HEIC file , does lowagi has library to support HEIC files?
PublicAPI api = (PublicAPI) ThreadContainer.get().getPublicAPI();
//find primary page
//ClipboardPage mainPage = api.findPage("pyWorkPage");
String IMGstr = myStepPage.getString("pyFileSource");
String IMGname = myStepPage.getString("pyFileName");
IMGname = IMGname.substring(0, IMGname.lastIndexOf('.') == -1 ? IMGname.length() : IMGname.lastIndexOf('.'));
byte[] ImgArray = IMGstr.getBytes();
java.io.ByteArrayOutputStream outfile = new java.io.ByteArrayOutputStream();
com.lowagie.text.Document document = new com.lowagie.text.Document();
try {
com.lowagie.text.pdf.PdfWriter writer = com.lowagie.text.pdf.PdfWriter.getInstance(document, outfile);
writer.setStrictImageSequence(true);
document.open();
//Get array
com.lowagie.text.Image jpg = com.lowagie.text.Image.getInstance(Base64Util.decodeToByteArray(IMGstr));
//Scale the image
float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()) / jpg.getWidth()) * 100;
jpg.scalePercent(scaler);
We would like to convert HEIC file to PDF.
I tried with below code which works for JPG ( convert JPG to PDF) but not working for HEIC file , does lowagi has library to support HEIC files?
PublicAPI api = (PublicAPI) ThreadContainer.get().getPublicAPI();
//find primary page
//ClipboardPage mainPage = api.findPage("pyWorkPage");
String IMGstr = myStepPage.getString("pyFileSource");
String IMGname = myStepPage.getString("pyFileName");
IMGname = IMGname.substring(0, IMGname.lastIndexOf('.') == -1 ? IMGname.length() : IMGname.lastIndexOf('.'));
byte[] ImgArray = IMGstr.getBytes();
java.io.ByteArrayOutputStream outfile = new java.io.ByteArrayOutputStream();
com.lowagie.text.Document document = new com.lowagie.text.Document();
try {
com.lowagie.text.pdf.PdfWriter writer = com.lowagie.text.pdf.PdfWriter.getInstance(document, outfile);
writer.setStrictImageSequence(true);
document.open();
//Get array
com.lowagie.text.Image jpg = com.lowagie.text.Image.getInstance(Base64Util.decodeToByteArray(IMGstr));
//Scale the image
float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()) / jpg.getWidth()) * 100;
jpg.scalePercent(scaler);
//Add image to document and finish work with document
document.add(jpg);
document.close();
//set correct values to properties
myStepPage.putString("pyFileName", IMGname + "_converted.pdf");
myStepPage.putString("pyFileType", "pdf");
myStepPage.putString("pyFileMimeType", "pdf");
myStepPage.putString("pyNote", IMGname + "_convertedToPDF");
//Encode result pdf and replace it instead of uploaded JPEG
String pdfStream = Base64Util.encodeToString(outfile.toByteArray());
myStepPage.getProperty("pyFileSource").setValue(pdfStream);
outfile.flush();
} catch (Exception e) {
e.printStackTrace();
}