Unsupported elements in Word to PDF Conversion
14 Jun 202411 minutes to read
The following table shows the unsupported elements of Word to PDF conversion.
Element | Unsupported elements |
---|---|
Predefined shapes | Only DOCX and WordML format documents are supported. |
Chart | Only DOCX and WordML format documents are supported from .NET Framework 4.0 onwards. |
Table Styles | Only DOCX and WordML format documents are supported. |
Pagination | The Essential DocIO makes sensible decision when layout the text, and its supported elements while generating the PDF documents. But however, there may not be guaranteed pagination with all the documents. |
Grouped Shapes | Only DOCX and WordML format documents are supported. |
Custom Shapes | Only DrawingML custom shapes in DOCX and WordML format documents are supported. |
Fit Text – Table cell | Not supported |
Vertical Alignment of the section | Not supported |
Equation | Mathematical equations extending to multiple lines will be rendered in a single line and content exceeding the right margin will clip in the PDF. |
SmartArt | Not supported |
WordArt | Not supported |
Watermark | First watermark of the Word document should be applied to the entire converted PDF document when the Word document have multiple watermarks. |
Multi-Column Texts | Multi-Column text positions are calculated dynamically when layout the text. So, there may be some content position differences occur in the PDF document. |
Borders | Using of patterns and 3D borders are not retained in the output PDF document. |
Break – Page break, column break and Line break | Text wrapping break is not supported. |
Footnote and endnote | Number formats in Roman, Alphabets, and Arabic only supported. |
Textbox | Linked text boxes are not supported. |
Font kerning | Partially supported. At present, the text in a line is scaled uniformly to match the width of kerned text, instead of adjusting the space between each pair of characters. |
Images | In .NET Core and latest target, we have limitation in metafile. Refer |
Show Warning for Unsupported Elements
When converting a Word document to a PDF, the presence of unsupported elements in the input Word document can lead to preservation issues in the converted PDF. The .NET Word library (DocIO) contains Warning API, which helps to detect and handle these unsupported elements during the conversion process. This API holds the information of unsupported elements once found in the input Word document.
Users can display warning messages for the unsupported elements using the WarningType during Word to PDF conversion. Users can set a flag to stop the conversion process based on the warning.
The following code demonstrates how to stop conversion if the input Word document has an unsupported element like SmartArt during Word to PDF conversion.
using (FileStream fileStream = new FileStream("Input.docx", FileMode.Open))
{
//Loads an existing Word document.
using (WordDocument wordDocument = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic))
{
//Creates an instance of DocIORenderer.
using (DocIORenderer renderer = new DocIORenderer())
{
renderer.Settings.Warning = new DocumentWarning();
//Converts Word document into a PDF document.
using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument))
{
//If the IsCanceled boolean is enabled, the input document will contain an unsupported element.
if (renderer.IsCanceled)
{
Console.WriteLine("The execution stopped due to unsupported element.");
Console.ReadKey();
}
else
{
//Saves the PDF file.
FileStream outputFile = new FileStream("Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
pdfDocument.Save(outputFile);
outputFile.Dispose();
Console.WriteLine("Success");
}
}
}
}
}
WordDocument wordDocument = new WordDocument("Input.docx");
DocToPDFConverter converter = new DocToPDFConverter();
converter.Settings.Warning = new DocumentWarning();
PdfDocument pdfDocument = converter.ConvertToPDF(document);
//If the IsCanceled boolean is enabled, the input document will contain an unsupported element.
if (converter.IsCanceled)
{
Console.WriteLine("The execution stopped due to unsupported element.");
Console.ReadKey();
}
else
{
//Saves the PDF file.
FileStream outputFile = new FileStream("Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
pdfDocument.Save(outputFile);
outputFile.Dispose();
Console.WriteLine("Success");
}
Dim wordDocument As New WordDocument("Input.docx")
Dim converter As New DocToPDFConverter()
converter.Settings.Warning = New DocumentWarning()
Dim pdfDocument As PdfDocument = converter.ConvertToPDF(document)
' If the IsCanceled boolean is enabled, the input document will contain an unsupported element.
If converter.IsCanceled Then
Console.WriteLine("The execution stopped due to unsupported element.")
Console.ReadKey()
Else
' Saves the PDF file.
Using outputFile As New FileStream("Output.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite)
pdfDocument.Save(outputFile)
Console.WriteLine("Success")
End Using
End If
The following code demonstrates how to initialize the Warning API and display warning messages for all unsupported elements in the input document. Additionally, this code shows how to set a flag to stop Word to PDF conversion if an unsupported element is identified.
public class DocumentWarning : IWarning
{
public bool ShowWarnings(List<WarningInfo> warningInfo)
{
bool isContinueConversion = true;
foreach (WarningInfo warning in warningInfo)
{
//Based on the WarningType enumeration, you can do your manipulation.
//Skip the Word to PDF conversion by setting the isContinueConversion value to false.
//To stop execution if the input document has a SmartArt.
if (warning.WarningType == WarningType.SmartArt)
isContinueConversion = false;
//Warning messages for unsupported elements in the input document.
Console.WriteLine("The input document contains " + warning.WarningType + " unsupported element.");
}
return isContinueConversion;
}
}
public class DocumentWarning : IWarning
{
public bool ShowWarnings(List<WarningInfo> warningInfo)
{
bool isContinueConversion = true;
foreach (WarningInfo warning in warningInfo)
{
//Based on the WarningType enumeration, you can do your manipulation.
//Skip the Word to PDF conversion by setting the isContinueConversion value to false.
//To stop execution if the input document has a SmartArt.
if (warning.WarningType == WarningType.SmartArt)
isContinueConversion = false;
//Warning messages for unsupported elements in the input document.
Console.WriteLine("The input document contains " + warning.WarningType + " unsupported element.");
}
return isContinueConversion;
}
}
Public Class DocumentWarning
Implements IWarning
Public Function ShowWarnings(warningInfo As List(Of WarningInfo)) As Boolean Implements IWarning.ShowWarnings
Dim isContinueConversion As Boolean = True
For Each warning As WarningInfo In warningInfo
' Based on the WarningType enumeration, you can perform your manipulation.
' Skip the Word to PDF conversion by setting the isContinueConversion value to false.
' To stop execution if the input document has a SmartArt.
If warning.WarningType = WarningType.SmartArt Then
isContinueConversion = False
End If
' Warning messages for unsupported elements in the input document.
Console.WriteLine("The input document contains " & warning.WarningType & " unsupported element.")
Next
Return isContinueConversion
End Function
End Class
TIPS
Using the above Warning API, handle logic to identify the documents with unsupported elements and notify the end users to use supported elements for good preservation in the output PDF.
You can download a complete working sample from GitHub