HELP .. Word conversion to PDF

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);

@nick1234

Thanks for your inquiry. Please note when Aspose.Words does not find the referred font on host machine then it substitutes the font using fonts info from the document. Please check following article for more details.

Font Availability and Substitution

You can implement IWarningCallback to double check missing fonts. Please install missing fonts, hopefully it will resolve the issue. However, if the issue persists then please share your input and output files here as ZIP file. We will look into these and will guide you accordingly.

Document docWord = new Document("Input.docx");
docWord.WarningCallback = new HandleDocumentWarnings();
docWord.Save("AW_179.pdf");

/////////////////////////////

public class HandleDocumentWarnings : IWarningCallback
{
    /// <summary>
    /// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
    /// Potential issue during document processing. The callback can be set to listen for warnings generated during document
    /// Load and/or document save.
    /// </summary>
    public void Warning(WarningInfo info)
    {
        // We are only interested in fonts being substituted.
        if (info.WarningType == WarningType.FontSubstitution)
        {
            Console.WriteLine("Font substitution: " + info.Description);
        }
    }
}