Update REF Fields in Word Document & Convert to PDF using C# .NET | Error! No text of specified style in document

Hello team,

While converting word to PDF some of the texts are not rendering correctly in PDF instead i am getting below error message in pdf

Error! No text of specified style in document

Please find the attached input and output filecurrentQueue_out.zip (83.7 KB)

I am using below code to convert word to pdf

public  bool WordToPdf(Aspose.Words.Document doc, string outPdfPath, out string errorMessage)
    {
        bool res = false;
        errorMessage = string.Empty;
        try
        {
            Aspose.Words.Saving.PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions();
            options.DmlRenderingMode = Aspose.Words.Saving.DmlRenderingMode.Fallback;
            options.UpdateFields = true;
            options.DmlEffectsRenderingMode = Aspose.Words.Saving.DmlEffectsRenderingMode.Simplified;
            // options.Compliance = Aspose.Words.Saving.PdfCompliance.PdfA1b;
            options.UseBookFoldPrintingSettings = true;
            options.ImageCompression = Aspose.Words.Saving.PdfImageCompression.Auto;
            options.ZoomBehavior = Aspose.Words.Saving.PdfZoomBehavior.FitPage;
            options.UseHighQualityRendering = true;
            options.OptimizeOutput = true;
            options.MemoryOptimization = true;
            //options.UpdateSdtContent = true;
            doc.AcceptAllRevisions();
            doc.Revisions.AcceptAll();
            RemoveComments(doc);
            doc.UpdateFields();
            doc.Save(outPdfPath, options);
            // doc.Save(outPdfPath + ".docx");
            res = true;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
            try
            {
                Aspose.Words.Saving.PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions();
                options.DmlRenderingMode = Aspose.Words.Saving.DmlRenderingMode.DrawingML;
                options.ImageCompression = Aspose.Words.Saving.PdfImageCompression.Auto;
                //options.MemoryOptimization = true;
                options.TempFolder = Path.Combine(Path.GetTempPath(), "astmp");
                try
                {
                    Directory.CreateDirectory(options.TempFolder);
                }
                catch
                {

                }
                
                doc.AcceptAllRevisions();
                doc.Revisions.AcceptAll();
                RemoveComments(doc);
                doc.Save(outPdfPath, options);
                res = true;
            }
            catch (Exception e)
            {
            }
        }
        return res;
    }

Any help on this will be much appericiated

@senthilspi,

But, MS Word 2019 also injects those error messages in PDF. Please check the following MS Word 2019 generated (using Save As command) and Aspose.Words generated PDF files:

Aspose.Words tries to mimic the behavior of MS Word. However, you can use the following code as a workaround:

Document doc = new Document("C:\\currentQueue_out\\C03 Cations_Part2-edit.docx");

PdfSaveOptions opts = new PdfSaveOptions();
opts.UpdateFields = false;

doc.Save("C:\\currentQueue_out\\20.9-UpdateFields-false.pdf", opts);

Hi Hafeez,

The above code doesn’t save me all the time. This time it’s “Error! Reference source not found” error. It is occurring in more documents in our production, and the worst part is due to which the page numbers are increasing in PDF. The error only occurs in Aspose, when I convert pdf using word (2016) save as method it is perfect.
I will send the sample docs if needed in your private inbox. (It’s hidden as of now)

Any quick assist on this will save me;(

@senthilspi,

Have you tried the latest (20.10) version of Aspose.Words for .NET on your end? In case the problem still remains, then please ZIP and upload your sample Word document 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.

Hi Hafeez,

Yes i am using latest aspose. I can’t post the docs here due to our policy. Can you please enable direct messaging to your account. I can upload there.

@senthilspi,

Please note that it is safe to attach files in the forum. If you attach your documents/resources here, then only you and Aspose staff members can download them. Also, I have made this forum thread Private now - only you and Aspose staff members can see its content now.

Please find the samples below.

Trithiocarbonate chapter 11e final.zip (4.2 MB)
Trithiocarbonate chapter 11e final-word-saveas.zip (5.2 MB)
Trithiocarbonate chapter 11e final - aspose-lat.zip (1.3 MB)

@senthilspi,

We have logged this problem in our issue tracking system with ID WORDSNET-21236. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

The issues you have found earlier have been fixed in this Aspose.Words for .NET 20.12 update and this Aspose.Words for Java 20.12 update.