When I convert docx to pdf… although the conversion went fine… towards the end, we can see that the document didn’t appear as an exact copy of the docx. After the first few pages, the paragraph last line on the page is not exact… It got shifted down to the next page which means the size of the font was off or something… By the last page, almost an entire paragraph ended up on the wrong page as the docx.
Is there anyway that we can explicitly tells the conversion routine to keep all the formatting of the docx… font size, margins etc…
Thanks
Below is the conversion code I am using
public bool ConvertDocxToPdf(string docxFilePath, string pdfFilePath)
{
bool rc = false;
try
{
Document docx = new Aspose.Words.Document(docxFilePath);
string systemfontfolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts);
string fontsfolder = HttpContext.Current.Server.MapPath("/Fonts");
FontSettings fontsetting = new FontSettings();
fontsetting.SetFontsFolders(new string[] { systemfontfolder, fontsfolder }, true);
docx.FontSettings = fontsetting;
// converting it into memorystream fixes the issue with the problem of line breaking
// inconsistently between docx and generated pdf.
MemoryStream docStream = new MemoryStream();
docx.Save(docStream, SaveFormat.Doc);
Aspose.Words.Document doc = new Aspose.Words.Document(docStream);
doc.FontSettings = fontsetting;
doc.Save(pdfFilePath);
rc = true;
}
catch (Exception ex)
{
errorMsg = string.Format("Error in PDFGeneratorService method: ConvertDocxToPdf. Docx Name {0}. PDf Name = {1}", docxFilePath, pdfFilePath);