Free Support Forum - aspose.com

Remove spaces from generated image filename during Word to HTML conversion

Hi Hafeez,
Good Day.
I converted the word document into html using aspose, the converted files in the resultant folder as follows.
For Example:
Filename: sampletest.doc.

Converted Html filename: sampletest.doc.html
Converted Image File Names: sampletest.doc.001.jpeg, sampletest.doc.002.jpeg, etc…

If the filename was not having space its working fine, If filename having space (ex. Sample test one.doc, Converted image files as: sample test one.doc.001.jpeg), we fell some difficult to chnage the filename in HTML content. So please advise us to solve this issue. So we are in need of converted image file should not contain space and also the same in HTML content.

@SM0767,

Please try using the following code:

Document doc = new Document("D:\\Temp\\Sample test one.doc");

HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.HTML);
opts.setPrettyFormat(true);
opts.setImageSavingCallback(new HandleImageSaving());

doc.save("D:\\temp\\Sample test one.doc.html", opts);
///////////////////////////////////////
static class HandleImageSaving implements IImageSavingCallback {
    public void imageSaving(ImageSavingArgs args) throws Exception {
        if (args.getImageFileName().contains(" "))
            args.setImageFileName(args.getImageFileName().replace(" ", "_"));
    }
}

Hi Hafeez,
Good Day.
I tried to convert the HTML file as PDF its working fine if the file doesn’t contains table. If the the file consist of tables the alignment if the PDF was worse. Here with i attached a screenshot for your reference. Please advise me to get an proper PDF file from HTML even it consist of tables.printing errrossssss.jpeg (93.3 KB)

@SM0767,

Thanks for your inquiry. Please ZIP and upload your input HTML file and Aspose.Words generated PDF file showing the undesired behavior here for testing. We will then investigate the issue on our end and provide you more information.