Conversion

Conversion (32)

Start from version 7.3.3, Spire.Doc supports keeping Word headings as PDF bookmarks when converting Word to PDF. This article demonstrates how to use Spire.Doc to accomplish this functionality.

The input Word document:

Keep Word Headings as PDF Bookmarks When Converting Word to PDF in C#

Example code

using Spire.Doc;

namespace Keep_word_headings_as_pdf_bookmarks
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Input.docx");

            ToPdfParameterList topdf = new ToPdfParameterList();
            topdf.CreateWordBookmarks = true;
            topdf.CreateWordBookmarksUsingHeadings = true;

            doc.SaveToFile("Output.pdf", topdf);
        }
    }
}

The output PDF document:

Keep Word Headings as PDF Bookmarks When Converting Word to PDF in C#

Tuesday, 05 March 2019 09:02

Convert Word to PCL

Written by support iceblue

PCL File is Digital printed document created in the Printer Command Language (more commonly referred to as PCL) page description language. From v7.1.19, Spire.Doc supports to convert word document to PCL. There are many kinds of standard for PCL document; the PCL here refers to PCL 6 (PCL 6 Enhanced or PCL XL). This article will show you how to save word document to PCL in C# and VB.NET by only three lines of codes.

[C#]
//load the sample document
Document doc = new Document();
doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);

//save the document as a PCL file
doc.SaveToFile("Result.pcl", FileFormat.PCL);   
[VB.NET]
Private Sub SurroundingSub()
Dim doc As Document = New Document()
doc.LoadFromFile("Sample.docx", FileFormat.Docx2010)
doc.SaveToFile("Result.pcl", FileFormat.PCL)
End Sub
Thursday, 08 November 2018 07:59

How to convert Word to PostScript in C#

Written by jie zou

PostScript is a page description language that is an industry standard for outputting high-resolution text and graphics. From Version 6.11.2, Spire.Doc supports to convert doc/docx to a postscript file in both WinForm app and ASP.NET app. This article will demonstrate how to convert word to PostScript in C# and VB.NET.

Firstly, view the sample word document:

How to convert Word to PostScript in C#

[C#]
using Spire.Doc;

namespace Word
{
    class Program
    {
        static void Main(string[] args)
        {            
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);
            doc.SaveToFile("Result.ps", FileFormat.PostScript);                 
        }
    }
}
[VB.NET]
Imports Spire.Doc
Namespace Word
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim doc As Document = New Document()
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010)
            doc.SaveToFile("Result.ps", FileFormat.PostScript)
        End Sub
    End Class
End Namespace

Effective screenshot of the resulted PostScript file converted from .docx document:

How to convert Word to PostScript in C#

We already have the documentation introducing how to convert Word to EPUB. However, you may want to add a cover image to EPUB when creating an EPUB book from a Word document. The following code snippets will demonstrate the same.

Step 1: Create a Document instance and load a sample Word file.

Document doc = new Document();
doc.LoadFromFile("SampleWordFile.docx");

Step 2: Load a picture to DocPicture object.

DocPicture picture = new DocPicture(doc);
picture.LoadImage(Image.FromFile("CoverImage.jpg"));

Step 3: Add the picture to EPUB as cover image when creating EPUB from the Word document.

doc.SaveToEpub("output.epub", picture);

Output:

Add a Cover Image when Converting Word to EPUB in C#, VB.NET

Full Code:

[C#]
Document doc = new Document();
doc.LoadFromFile("SampleWordFile.docx");

DocPicture picture = new DocPicture(doc);
picture.LoadImage(Image.FromFile("CoverImage.jpg"));
doc.SaveToEpub("output.epub", picture);  
[VB.NET]
Document doc  =  New Document()
doc.LoadFromFile("SampleWordFile.docx")

Dim picture As DocPicture =  New DocPicture(doc) 
picture.LoadImage(Image.FromFile("CoverImage.jpg"))
doc.SaveToEpub("output.epub", picture)

A file with the .ODT file extension is an OpenDocument Text document file. These files are most often created by the free OpenOffice Writer word processor program. ODT files are similar to the popular DOCX file format used with Microsoft Word. Both of the two file types can hold things like text, images, objects, and styles.

However, when you open an ODT document in Microsoft Word, the formatting of the ODT document may differ as a result of the two programs not sharing the same features. When converting ODT to DOCX or vice versa, the data and content will be converted successfully, but may not including the original formatting.

Following code snippets introduce how to convert ODT to DOC or DOCX and vice versa using Spire.Doc.

ODT to DOCX

To convert ODT to DOC, change the file extension and file format to .Doc in SaveToFile method.

[C#]
Document doc = new Document();
doc.LoadFromFile("SampleODTFile.odt");
doc.SaveToFile("output.docx", FileFormat.Docx);
[VB.NET]
Document doc = New Document()
doc.LoadFromFile("SampleODTFile.odt")
doc.SaveToFile("output.docx", FileFormat.Docx)

DOCX to ODT

To convert Doc to ODT, load a .Doc file format document when loading the source file.

[C#]
Document doc = new Document();
doc.LoadFromFile("SampleWordFile.docx");
doc.SaveToFile("output.odt", FileFormat.Odt);
[VB.NET]
Document doc = New Document()
doc.LoadFromFile("SampleWordFile.docx")
doc.SaveToFile("output.odt", FileFormat.Odt)

SVG (Scalable Vector Graphics) is an image file format and it has the advantage of be edited and indexed easily. It is widely used for interactivity and animation. Starts from Spire.Doc V5.8, Spire.Doc offers a method doc.SaveToFile() to enable developers to save the word document to SVG file format in C# easily. This article will focus on demonstrate how to convert word document to SVG with the help of Spire.Doc by using a simple line of code in C#.

Firstly, please view the original word document:

How to Convert Word to SVG (Scalable Vector Graphics) in C#

Step 1: Create a C# project in visual studio, then add a reference to Spire.Doc.dll and use the following namespace.

using Spire.Doc;

Step 2: Create a word instance and load the source word document from file.

Document doc = new Document();
doc.LoadFromFile("Sample.docx");

Step 3: Save the document to SVG file.

doc.SaveToFile("result.svg", FileFormat.SVG);

After running the code, we'll get the effective screenshot of the following result SVG file from word document:

How to Convert Word to SVG (Scalable Vector Graphics) in C#

Full codes:

using Spire.Doc;

namespace wordconversion.Case
{
    class WordtoSVG
    {

         public WordtoSVG()
         {
        Document doc = new Document();
        doc.LoadFromFile("Sample.docx");

        doc.SaveToFile("result.svg", FileFormat.SVG);
         }

    }
}

Hyperlinks give more additional information for readers and it is widely used on our word documents. Spire.Doc has a powerful function of operating the word elements of hyperlinks. Developers can add hyperlinks, modify and remove hyperlinks from word documents. Spire.Doc also supports to preserve hyperlinks or not in word to PDF conversion. This article will show you how to preserve hyperlinks or disable the hyperlinks in C# when converting word document into PDF file format.

Here comes to the code snippets of how to disable or preserve hyperlinks from word to PDF.

Step 1: Load a word documents with hyperlinks.

Document doc = new Document();
doc.LoadFromFile("Sample.docx");

Step 2: Create an instance of ToPdfParameterList.

ToPdfParameterList pdf = new ToPdfParameterList();

Step 3: Set DisableLink to true to remove the hyperlink effect for the result PDF page.

//set DisableLink to false to preserve the hyperlinks
pdf.DisableLink = true;

Step 4: Save the PDF file.

doc.SaveToFile("result.pdf", pdf);

Effective screenshot of preserve the hyperlinks from the result PDF page.

Preserve or disable hyperlinks from word to PDF conversion

Effective screenshot of disabled the hyperlinks from the result PDF page.

Preserve or disable hyperlinks from word to PDF conversion

Full codes of how to preserve the hyperlinks or not when convert word document to PDF file:

public WordtoPDFwithHyperlinks()
{
    Document doc = new Document();
    doc.LoadFromFile("Sample.docx");

ToPdfParameterList pdf = new ToPdfParameterList();

    //set DisableLink to false to preserve the hyperlinks
    pdf.DisableLink = true;

    doc.SaveToFile("result.pdf", pdf);
}
Wednesday, 15 June 2016 07:45

Save the hidden texts on word document to PDF

Written by support iceblue

With the help of Spire.Doc for .NET, we can easily hide the texts on the word document in C#. This article will demonstrate how to get word hidden text to show on the resulted PDF page by using Spire.Doc.

Note: Before Start, please download the latest version of Spire.Doc and add Spire.Doc.Doc.dll in the bin folder as the reference of Visual Studio.

Here comes to the steps of how to save the hidden texts on word document to PDF in C#. Firstly, view the original word document with hidden texts:

Save the hidden texts on word document to PDF

Step 1: Create a new word document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("sample.docx");

Step 2: When convert to PDF file, set the property IsHidden as true.

ToPdfParameterList pdf = new ToPdfParameterList();
pdf.IsHidden = true;

Step 3: Save the document to file and apply the style in the step 2.

doc.SaveToFile("result.pdf", pdf);

Effective screenshot of the resulted PDF page with the hidden texts on the original word document:

Save the hidden texts on word document to PDF

Full codes:

static void Main(string[] args)
{
    Document doc = new Document();
    doc.LoadFromFile("sample.docx");

    ToPdfParameterList pdf = new ToPdfParameterList();
    pdf.IsHidden = true;

    doc.SaveToFile("result.pdf", pdf);

}

With the help of Spire.Doc, we can use the method doc.SaveToFile () to convert the word document files to PDF format easily. When the word documents contains non-standard font, we will find that we can't pick up the non-standard font in the result PDF page. In fact, Spire.Doc also supports to convert the word document with non-standard font to PDF successfully. This article will show you how to remain the non-standard font on the result PDF file no matter I install the font or not in my server.

Here comes to the code snippets. Firstly, please the word document with the non-standard font Bar-Code 39:

How to convert the word document with non-standard font to PDF

Without the special setting when convert it to PDF, the barcode font will be replaced by text in the result PDF file. View the results as below:

How to convert the word document with non-standard font to PDF

Now I will show you the code of how to render word document to PDF, where the font won't be changed.

Step 1: Create a word document and load from file:

Document doc = new Document();
doc.LoadFromFile("sample.docx");

Step 2: When convert to PDF file, set the property IsEmbeddedAllFonts as true.

ToPdfParameterList parms = new ToPdfParameterList()
    {
        IsEmbeddedAllFonts = true
    };

Step 3: Save the document to file and apply the style in the step 2.

doc.SaveToFile("result.pdf", parms);

If we don't want to install the font on our server machine, we can use the following method to apply the fonts and save it to PDF successfully.

{
    Document doc = new Document();
    doc.LoadFromFile("sample.docx");

    ToPdfParameterList parms = new ToPdfParameterList()
    {
        PrivateFontPaths = new List()
       {
          new PrivateFontPath("Bar-Code 39","..\\..\\Code39.ttf")
       }
    };
    doc.SaveToFile("result.pdf", parms);
}

Effective screenshot:

How to convert the word document with non-standard font to PDF

Friday, 18 December 2015 02:20

How to convert Word to Word XML in C#, VB.NET

Written by support iceblue

Simple introduction about Word XML

Word XML is a special XML format, which makes Word be able to manipulate the Word documents stored in XML format. It can be divided into two types: WordML(supported by Word 2003) and WordXML(supported by Word 2007). If external applications support Word XML and the generated data follow the Word XML structure, then the data can be processed by Word. In this way, Word XML has become the bridge between Word and other external applications, any XML- formatted document based on Word XML structure can be opened, edited and saved in Word.

Using C#/VB.NET to convert Word to Word XML via Spire.Doc

Spire.Doc enables users to convert word document to Word XML format easily by using the doc.SaveToFile() method. Now, please follow the detail steps below:

Note: Before start, please download Spire.Doc and install it correctly, then add Spire.Doc.dll file from Bin folder as the reference of your project.

This is the screenshot of the original word document:

How to convert Word to Word XML in C#, VB.NET

Step 1: Create a new document instance.

Document doc = new Document();

Step 2: Load the sample word document from file.

doc.LoadFromFile("Spire.Doc for .NET.docx");

Step 3: Save the word document as Word XML format.

For word 2003:
doc.SaveToFile("DocxToWordML.xml", FileFormat.WordML);

For word 2007:
doc.SaveToFile("DocxToWordXML.xml", FileFormat.WordXml);

Effective screenshot:

How to convert Word to Word XML in C#, VB.NET

Full codes:

[C#]
using Spire.Doc;

namespace Convert_Word_to_Word_XML
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Spire.Doc for .NET.docx");
            doc.SaveToFile("DocxToWordML.xml", FileFormat.WordML);
            //doc.SaveToFile("DocxToWordXML.xml", FileFormat.WordXml);
        }
    }
}
[VB.NET]
Imports Spire.Doc
Namespace Convert_Word_to_Word_XML
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New Document()
			doc.LoadFromFile("Spire.Doc for .NET.docx")
			doc.SaveToFile("DocxToWordML.xml", FileFormat.WordML)
			'doc.SaveToFile("DocxToWordXML.xml", FileFormat.WordXml);
		End Sub
	End Class
End Namespace
Page 1 of 3