Free Support Forum - aspose.com

Aspose words docx to pdf does not preserve paragraph alignment

Hi,
I am using Apose words 18.7 jdk 1.6.WordBreak.zip (285.2 KB)
Please find attached the zip file containing

  1. the docx file (CP00300607.DOCX)
  2. file saved to pdf using word 2013 (CP00300607_WordToPDF.pdf)
  3. File converted using aspose words for Java to pdf. (CP00300607.pdf)

Is there some configuration available to preserve paragraph alignment.

image.png (7.7 KB)

image.png (8.3 KB)

There are several such fidelity issues in the generated output. Please help me resolve this issue.

Thanks and Regards,
Sourabh

@sourabhsj5

Thanks for your inquiry. Your query is related to hyphenation of words. Please register the hyphenation dictionary to get the desired output. Please refer to the following article.
How to Hyphenate Words of Specified Languages

Hi @tahir.manzoor,
Thanks for the quick response.
Would like to share the code snippet that I am using.

private static License license;

public static License getLicense() throws Exception {
	if (license == null) {
		license = new License();
		try {
			license.setLicense(AsposeUtils.class.getClassLoader().getResourceAsStream("Aspose.Words.lic"));
		} catch (Exception e1) {
			e1.printStackTrace();
			throw e1;
		}
	}
	return license;
}

public static void registerDefaultHyphenation() throws Exception {
	Hyphenation.registerDictionary("en-US", ClasspathUtils.readFileFromClasspath("hyph_en_US.dic"));
}
public static ByteArrayOutputStream convertToPDF(InputStream templateInputStream, String fileName) throws Exception {
	getLicense();
	
	if (templateInputStream != null) {
		try {
			LoadOptions options = new LoadOptions();
			options.setLoadFormat(LoadFormat.DOCX);
			Document doc = new Document(templateInputStream, options);
			AsposeUtils.registerDefaultHyphenation();
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			doc.updatePageLayout();
			doc.save(baos, 40);
			return baos;
		} catch (Exception e) {
			throw  e;
		}

	}
	return null;
}
public static void main(String[] args) throws Exception {
	String pdfFileName = "CP00300607.pdf";
	System.out.println("Aspose Utility Start. Document name: " + pdfFileName);
	byte[] mappedDocxFile = FileUtils.readFileToByteArray(new File("${docx_folder}/CP00300607.DOCX") );
	ByteArrayInputStream docxInputStream = new ByteArrayInputStream(mappedDocxFile);
	ByteArrayOutputStream pdfFile = convertToPDF(docxInputStream, pdfFileName);
	File file = new File("${output_folder}\\CP00300607.pdf");
	if (!file.exists()) { file.createNewFile(); }
	FileUtils.writeByteArrayToFile(file, pdfFile.toByteArray());
	System.out.println("Aspose Utility Ends. Document name: " + pdfFileName);

}

According to me if you closely check the docx file attached earlier, we are using justified alignment at some places and looks like it is not preserved in the generated pdf.
image.png (46.8 KB)

Please correct me if I am wrong. Also can you please share the path to download hyphenation dictionaries. I would like to try with “en-IN”.

Thanks and Regards,
Sourabh

@sourabhsj5

Thanks for your inquiry. The text alignment for the shared paragraph is justify in the output PDF. Please check the attached image.

We have tested the scenario and noticed that words are not hyphenated in output PDF. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17547. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-17547) have been fixed in this Aspose.Words for .NET 18.12 update and this Aspose.Words for Java 18.12 update.