Issues when converting docx to html & pdf

Hi everybody,

I need help to resolve the following issues:

  1. When converting docx to pdf
    - All images in pdf are fuzzier than original ones in docx -> How can Aspose keep the original quality of images when converting to pdf? OR Can I use Aspose Pdf or Aspose Pdf Kit to keep the image quality?

  2. When converting docx to html:
    - Some paragraphs, tables, … in my docx have background color. But; when converting to html, the background color is ignored. So, how can I resolve this issue?

Thanks and best regards!

Hi

Thanks for your inquiry. Could you attach your input and output documents here for testing? I will investigate the problem on my side and provide you more information.

Best regards,

Thanks for your quick reply,

My company’s network admin prevents upload file. I’m really sorry for this inconvenience.
Would you please find another way to help me?

Hi

Thanks for your request. Unfortunately, it is difficult to say what the problem is without the document. I need this document to reproduce the problem on my side.
It is safe to attach files in the forum. If you attach your document here, only you and Aspose staff members can download it. Also you can send the file to my e-mail as described here
https://forum.aspose.com/t/aspose-words-faq/2711
Best regards,

Thanks for your helps.

I send you our input/output files. Could you help to review?

Regards,

Hello
Thank you for additional information. I cannot reproduce the problem with PDF document on my side using the latest version of Aspose.Words (9.7.0) for testing. As I can see there is no any difference between qualities of images.
You can download the latest version from here:
https://releases.aspose.com/words/net
Also, I managed to reproduce the problem with background color on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is fixed.
Best regards,

Thanks AndreyN,

One more question about images when converting to pdf:
Can I use Aspose Pdf Kit or Aspose Pdf to improve the quality of images of converted pdf?
If yes, would you please give me some code hints or classes that I have to use.

Hi
Thanks for your request. I do not think that after converting to PDF you can improve quality of the images. Have you tried specifying JpegQuality before converting your documents to PDF? Maybe this will help you:
https://reference.aspose.com/words/net/aspose.words.saving/pdfsaveoptions/jpegquality/
Best regards,

Thanks **alexey.noskov,

I tried the latest version(Aspose Word 9.7.0.0).
I have set JpegQuality = 100 already, and I also tried properties of PdfSaveOptions class but no result.
Here is my code to convert:

public string Convert(string fullFilePath, OutputType outputType)
{
    StringBuilder outputFileBuilder = new StringBuilder();
    if (Utils.IsFileExist(fullFilePath))
    {
        // Build full path of output file
        outputFileBuilder.Append(Utils.GetDirectory(fullFilePath));
        outputFileBuilder.Append("\\");
        outputFileBuilder.Append(Utils.GetShortFileName(fullFilePath));

        try
        {
            // Initialize a word document to load input file
            LoadOptions loadOptions = new LoadOptions();
            loadOptions.LoadFormat = LoadFormat.Docx;
            Document doc = new Document(fullFilePath, loadOptions);
            switch (outputType)
            {
                case OutputType.Html:
                    outputFileBuilder.Append(".html");
                    HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
                    htmlSaveOptions.PrettyFormat = true;
                    htmlSaveOptions.SaveFormat = SaveFormat.Html;
                    htmlSaveOptions.AllowNegativeLeftIndent = true;
                    htmlSaveOptions.ImagesFolder = Utils.CreateDirectory(fullFilePath);
                    htmlSaveOptions.ImagesFolderAlias = Utils.GetShortFileName(fullFilePath);
                    htmlSaveOptions.ExportDocumentProperties = true;
                    htmlSaveOptions.ExportXhtmlTransitional = true;
                    this.Save(doc, htmlSaveOptions, outputFileBuilder.ToString());
                    break;
                case OutputType.Pdf:
                    outputFileBuilder.Append(".pdf");
                    PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
                    pdfSaveOptions.PrettyFormat = true;
                    pdfSaveOptions.SaveFormat = SaveFormat.Pdf;
                    pdfSaveOptions.JpegQuality = 100;
                    pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
                    this.Save(doc, pdfSaveOptions, outputFileBuilder.ToString());
                    break;
            }
        }
        catch (UnsupportedFileFormatException unsupportedEx)
        {
            Utility.WriteLog(this.LogDirectory, "DocumentConverter.log", unsupportedEx.StackTrace, LogLevel.ERROR);
            throw;
        }
        catch (IOException ioEx)
        {
            Utility.WriteLog(this.LogDirectory, "DocumentConverter.log", ioEx.StackTrace, LogLevel.ERROR);
            throw;
        }
        catch (Exception ex)
        {
            Utility.WriteLog(this.LogDirectory, "DocumentConverter.log", ex.StackTrace, LogLevel.ERROR);
            throw;
        }
    }

    return outputFileBuilder.ToString();
}

private void Save(Document doc, SaveOptions saveOptions, string outputFilePath)
{
    try
    {
        doc.Save(outputFilePath, saveOptions);
        Utility.WriteLog(this.LogDirectory, "DocumentConverter.log", "Converted to " + outputFilePath, LogLevel.INFO);
    }
    catch (UnsupportedFileFormatException unsupportedEx)
    {
        Utility.WriteLog(this.LogDirectory, "DocumentConverter.log", unsupportedEx.StackTrace, LogLevel.ERROR);
        throw;
    }
}

Is there any difference from your conversion code? If yes, would you please send me your conversion code?**

Hi
Thanks for your request. Your code is correct. I check your input document and as I can see, images in your document are PNG. So JpegQuality option will not have any effect.
Also, as I can see, quality of images in output PDF in the same as in the source document. So I do not see any problem here.
Best regards,

Thanks alexey.noskov,

I read your API reference(Aspose Word, Pdf and Pdf Kit), it seems that there is no property to affect quality of other image format(gif, png, …), apart from JpegQuality. Is it right?

Best regards,

Hi
Thanks for your request. You are right. In your case PNG images go to PDF without changed, i.e. quality of the images is not changed.
Best regards,

Special thanks for your response, alexey.noskov !

Could you help to convert my input docx file(inside the attached Data.rar) with your code again.And please give me the output pdf file and the code that you used to convert?

Thanks & best regards,

Hi
Thanks for your request. I sent the output PDF document produced on my side to your e-mail. Here is the code I used for conversion:

Document doc = new Document("in.docx");
doc.Save("out.pdf");

Best regards,

The issues you have found earlier (filed as WORDSNET-4566) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.