Skip to content
2 changes: 1 addition & 1 deletion File-Formats-toc.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion File-Formats/DocIO/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ It is a non-UI component that provides a full-fledged document instance model si
* Support to [create Word document](https://help.syncfusion.com/file-formats/docio/getting-started) from scratch.
* Support to open, modify and save existing Word documents.
* Advanced [Mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge) support with different data sources.
* Ability to create or edit Word 97-2003 and later version documents, and convert them to commonly used file formats such as [RTF](https://help.syncfusion.com/file-formats/docio/rtf), [WordML](https://help.syncfusion.com/file-formats/docio/word-file-formats#word-processing-xml-xml), [TXT](https://help.syncfusion.com/file-formats/docio/text), [HTML](https://help.syncfusion.com/file-formats/docio/html) and vice versa.
* Ability to create or edit Word 97-2003 and later version documents, and convert them to commonly used file formats such as [RTF](https://help.syncfusion.com/file-formats/docio/rtf), [WordML](https://help.syncfusion.com/file-formats/docio/word-file-formats#word-processing-xml-xml), [TXT](https://help.syncfusion.com/file-formats/docio/text), [HTML](https://help.syncfusion.com/file-formats/docio/html), [Markdown](https://help.syncfusion.com/file-formats/docio/convert-word-document-to-markdown-in-csharp) and vice versa.
* Ability to export a Word document as an [Image](https://help.syncfusion.com/file-formats/docio/word-to-image), [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf) file, and [EPUB](https://help.syncfusion.com/file-formats/docio/word-to-epub) in high quality.
* Ability to [merge](https://help.syncfusion.com/file-formats/docio/word-document/merging-word-documents) and [split](https://help.syncfusion.com/file-formats/docio/word-document/split-word-documents) Word documents.
* Support to [compare](https://help.syncfusion.com/file-formats/docio/word-document/compare-word-documents) two DOCX format documents.
Expand Down
3 changes: 3 additions & 0 deletions File-Formats/DocIO/Word-document/Split-Word-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ By using this feature, you can be able to split/extract the necessary parts from

You can save the resultant document as a Word document (DOCX, WordML, DOC), PDF, image, HTML, RTF, and more.

To quickly start splitting Word documents, please check out this video:
{% youtube "https://www.youtube.com/watch?v=w9np2NSfq94" %}

## Split by Section

The following code example illustrates how to split the Word document by sections.
Expand Down
58 changes: 57 additions & 1 deletion File-Formats/DocIO/Working-with-LaTeX.md
Original file line number Diff line number Diff line change
Expand Up @@ -1835,4 +1835,60 @@ document.Save("Result.docx", FormatType.Docx)

{% endtabs %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mathematical-Equation/LaTeX-equations/Format%20Equation).
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mathematical-Equation/LaTeX-equations/Format%20Equation).

## Apply Math Justification

Apply justification, such as Left, Right, and more to the equation in a Word document using the .NET Word Library.

The following code examples show how to apply the justification to equations in a Word document.

{% tabs %}

{% highlight c# tabtitle="C# [Cross-platform]" %}
// Create a new Word document.
using (WordDocument document = new WordDocument())
{
//Add one section and one paragraph to the document.
document.EnsureMinimal();
//Append an border box equation using LaTeX.
WMath math = document.LastParagraph.AppendMath(@"\boxed{{x}^{2}+{y}^{2}={z}^{2}}");
//Apply math justification.
math.MathParagraph.Justification = MathJustification.Left;
using (FileStream outputFileStream = new FileStream("Output.docx", FileMode.Create, FileAccess.ReadWrite))
{
//Save Word document.
document.Save(outputFileStream, FormatType.Docx);
}
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
//Create a new Word document.
WordDocument document = new WordDocument();
//Add one section and one paragraph to the document.
document.EnsureMinimal();
//Append an border box equation using LaTeX.
WMath math = document.LastParagraph.AppendMath(@"\boxed{{x}^{2}+{y}^{2}={z}^{2}}");
//Apply math justification.
math.MathParagraph.Justification = MathJustification.Left;
//Save Word document.
document.Save("Output.docx", FormatType.Docx);
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Create a new Word document.
Dim document As New WordDocument()
'Add one section and one paragraph to the document.
document.EnsureMinimal()
'Append a border box equation using LaTeX.
Dim math As WMath = document.LastParagraph.AppendMath("\boxed{{x}^{2}+{y}^{2}={z}^{2}}")
'Apply math justification.
math.MathParagraph.Justification = MathJustification.Left
'Save Word document.
document.Save("Output.docx", FormatType.Docx)
{% endhighlight %}

{% endtabs %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mathematical-Equation/Apply-math-justification).
52 changes: 52 additions & 0 deletions File-Formats/DocIO/html.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,58 @@ document.Close()

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/HTML-conversions/Customize-Word-to-HTML-conversion).


### Export HTML with body content alone

While saving a Word document as a HTML file using .NET Word Library, there is an option to save the HTML file with only the content within the <body> tags, excluding other elements through HtmlExportBodyContentAlone API.

The following code example illustrates how to export the HTML file with only the body content.

{% tabs %}

{% highlight c# tabtitle="C# [Cross-Platform]" %}
//Load an existing Word document.
using (FileStream fileStreamPath = new FileStream("Input.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
//Enable the flag, to save HTML with elements inside body tags alone.
document.SaveOptions.HtmlExportBodyContentAlone = true;

using (FileStream outputFileStream = new FileStream("WordToHTML.html", FileMode.Create, FileAccess.ReadWrite))
{
//Save Word document as HTML.
document.Save(outputFileStream, FormatType.Html);
}
}
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
//Loads an existing document
//Load an existing Word document.
WordDocument document = new WordDocument("Input.docx", FormatType.Docx);
//Enable the flag, to save HTML with elements inside body tags alone.
document.SaveOptions.HtmlExportBodyContentAlone = true;
//Saves the document as html file
document.Save(document, "WordtoHtml.html");
document.Close();
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Loads an existing document
Dim document As New WordDocument("Input.docx")
'Enable the flag, to save HTML with elements inside body tags alone.
document.SaveOptions.HtmlExportBodyContentAlone = true
'Saves the document as html file
document.Save(document, "WordtoHtml.html")
document.Close()
{% endhighlight %}

{% endtabs %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/HTML-conversions/Export-HTML-with-body-content)

## Supported and unsupported items

The following document elements and attributes are supported by DocIO in Word to HTML and HTML to Word conversions.
Expand Down
164 changes: 164 additions & 0 deletions File-Formats/DocIO/word-to-pdf.md
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,170 @@ In .NET Core and latest target, we have limitation in metafile. Refer {{'[here](
</tr>
</table>

## 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](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocToPDFConverter.DocToPDFConverterSettings.html#Syncfusion_DocToPDFConverter_DocToPDFConverterSettings_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](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocIO.DLS.WarningInfo.html#Syncfusion_DocIO_DLS_WarningInfo_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.


{% tabs %}

{% highlight c# tabtitle="C# [Cross-platform]" %}
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");
}
}
}
}
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
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");
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
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
{% endhighlight %}

{% endtabs %}

The following code demonstrates how to initialize the [Warning](https://help.syncfusion.com/cr/file-formats/Syncfusion.DocToPDFConverter.DocToPDFConverterSettings.html#Syncfusion_DocToPDFConverter_DocToPDFConverterSettings_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.

{% tabs %}

{% highlight c# tabtitle="C# [Cross-platform]" %}
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;
}
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
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;
}
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
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
{% endhighlight %}

{% endtabs %}

T> 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](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Word-to-PDF-Conversion/Show-Warning-for-unsupported-elements)

## See Also

* [How to perform font substitution in Word to PDF conversion](https://support.syncfusion.com/kb/article/7499/how-to-perform-font-substitution-in-word-to-pdf-conversion)
Expand Down
Loading