Hello,
When converting to Pdf and previewing the same Word file, we’re having problems with the images in the documents.
After a few investigations and tests on the parameters of the images in the Word file, nothing was really conclusive.
Please find enclosed:
- the Word file to be converted → R2401.0013-V1_C09962_RENAULT - 4EVER - Front and Rear Bumpers (C09962)_essais LA01.docx
- the pdf file obtained using aspose → result.pdf
- the file obtained by saving Word as a PDF file → Excepted.pdf
You can see the problem on page 10 of the file result.pdf and on page 9 of the file R2401.0013-V1_C09962_RENAULT - 4EVER - Front and Rear Bumpers (C09962)_essais LA01.docx or Excepted.pdf.
Here are the codes used for pdf conversion
protected void ConvertToPdf(string wordFile)
{
Document doc = new Document(wordFile);
PdfSaveOptions options = new PdfSaveOptions()
{
SaveFormat = SaveFormat.Pdf,
};
doc.Save(Path.ChangeExtension(wordFile, ".pdf"), options);
}
The version of Aspose used is 24.1.0.
Here’s the code used for the preview
using GroupDocs.Viewer.Options;
using GroupDocs.Viewer.Results;
using System;
using System.IO;
namespace Web.code.Lib.GroupDocsViewer
{
public class HtmlViewer : IDisposable
{
private readonly GroupDocs.Viewer.Viewer viewer;
private readonly HtmlViewOptions htmlViewOptions;
private readonly ViewInfoOptions viewInfoOptions;
private Stream stream;
public HtmlViewer(string filePath, LoadOptions loadOptions)
{
viewer = new GroupDocs.Viewer.Viewer(filePath, loadOptions);
htmlViewOptions = CreateHtmlViewOptions();
viewInfoOptions = ViewInfoOptions.FromHtmlViewOptions(htmlViewOptions);
}
private HtmlViewOptions CreateHtmlViewOptions()
{
HtmlViewOptions htmlViewOptions = HtmlViewOptions.ForEmbeddedResources(
// The action that will be done before each page informations is read
pageNumber =>
{
Stream pageStream = new MemoryStream();
stream = pageStream;
return pageStream;
},
// The action to do after each page information is read.
// Must be there otherwise the stream is disposed and we can't used it anymore
(pageNumber, stream) =>
{
});
htmlViewOptions.SpreadsheetOptions = SpreadsheetOptions.ForOnePagePerSheet();
htmlViewOptions.SpreadsheetOptions.TextOverflowMode = TextOverflowMode.HideText;
htmlViewOptions.SpreadsheetOptions.RenderHeadings = true;
htmlViewOptions.ExcludeFonts = false;
return htmlViewOptions;
}
public string GetPageContent(int pageNumber)
{
viewer.View(htmlViewOptions, pageNumber);
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream))
{
string htmlContent = reader.ReadToEnd();
stream.Dispose();
return htmlContent;
}
}
public void Dispose()
{
viewer.Dispose();
}
}
}
Version of GroupDocs.Viewer used 23.12.
We’re developing a web application and your solution is being used by our application for customers who want to be able to preview and convert their files correctly.
Thanks in advance