Hi,
We are trying to convert from word to pdf using below code snippet, but either font is getting change and lines are also breaking and coming to next page that cause a major issue.
We have recently moved to Kubernetes, is this issue is related to kubernates?
public static void convertDocxToPdf() throws Exception {
OutputStream outputStream = null;
OutputStream fileOutputStream = new FileOutputStream(new File("C:\\Work\\font-issue\\check_font_issue.pdf"));
try {
File initialFile = new File("C:\\Work\\font-issue\\check_font_issue.docx");
InputStream inputStream = FileUtils.openInputStream(initialFile);
long startAPITime = System.currentTimeMillis();
outputStream = new ByteArrayOutputStream();
Document returnFile = new Document(inputStream);
// returnFile = saveDocxFile(returnFile);
// returnFile.acceptAllRevisions();
NodeCollection comments = returnFile.getChildNodes(NodeType.COMMENT, true);
// Remove all comments.
comments.clear();
// if (File.pathSeparator.equalsIgnoreCase(":")) {
FontSettings fontSettings = new FontSettings();
fontSettings.setFontsFolder("C:\\Work\\font-issue\\Fonts", true);
returnFile.setFontSettings(fontSettings);
PdfSaveOptions opt = new PdfSaveOptions();
opt.setExportDocumentStructure(true);
opt.setSaveFormat(SaveFormat.PDF);
opt.setMemoryOptimization(true); // will increase time
returnFile.save(outputStream, opt);
byte[] fileByteArray = ((ByteArrayOutputStream) outputStream).toByteArray();
fileOutputStream.write(fileByteArray);
long endAPITime = System.currentTimeMillis();
} catch (Exception e) {
throw e;
} finally {
if (outputStream != null)
outputStream.close();
if (fileOutputStream != null)
fileOutputStream.close();
}
}
Please verify and let us know if anything required from our side.