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(false);
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:

using Spire.Doc;
namespace DOCPDF
{
    class Program
    {
        static void Main(string[] args);
            public void WordtoPDFwithHyperlinks()
{
    Document doc = new Document(false);
    doc.LoadFromFile("Sample.docx");

ToPdfParameterList pdf = new ToPdfParameterList();

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

    doc.SaveToFile("result.pdf", pdf);
}
    } 
}
Published in Conversion

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(false);
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:

using Spire.Doc;
namespace DOCPDF
{
    class Program
    {
     
          static void Main(string[] args)
{
    Document doc = new Document(false);
    doc.LoadFromFile("sample.docx");

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

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

}
    
    }
}
Published in Conversion

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(false);
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.

using Spire.Doc;
namespace DOCPDF
{
    class Program
    {   
          static void Main(string[] args)
{
    
        Document doc = new Document(false);
        doc.LoadFromFile("sample.docx");

        ToPdfParameterList parms = new ToPdfParameterList()
        {
            IsEmbeddedAllFonts = true
        };
        doc.SaveToFile("result.pdf", parms);

    }

}

Effective screenshot:

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

Published in Conversion

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
Published in Conversion
Thursday, 17 March 2022 09:03

C#/VB.NET: Convert RTF to PDF

RTF (Rich Text Format) is a cross-platform document developed by Microsoft in the 1980s. RTF can be opened by most word processors, and it is also convenient for editing. But when it comes to sharing and printing documents in daily work, it’s more recommended to convert the RTF to PDF for further processing. In this article, you will learn how to convert RTF to PDF programmatically using Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Convert RTF to PDF in C# and VB.NET

Spire.Doc for .NET enables you to directly load a file with .rtf extension and then convert it to PDF with only three lines of code. The detailed steps are as follows.

  • Create a Document instance.
  • Load a sample RTF document using Document.LoadFromFile() method.
  • Save the document as a PDF file using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;

namespace RTFtoPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document doc = new Document();

            //Load a sample RTF document
            doc.LoadFromFile("sample.rtf", FileFormat.Rtf);

            //Save it to PDF
            doc.SaveToFile("RTFtoPDF.pdf", FileFormat.PDF);
        }
    }
}

C#/VB.NET: Convert RTF to PDF

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Published in Conversion

Spire.Doc has a powerful ability to operate RTF file formats in C# and VB.NET. By using Spire.Doc, developers can convert RTF to PDF, HTML and word documents in .doc, .docx. This article will show you how to convert RTF into image and then reset the image resolution.

Download and install Spire.Doc for .NET and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll". Here comes to the details of how to convert RTF into PNG and reset image resolution in C#.

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

Document doc = new Document();
doc.LoadFromFile("sample.rtf", FileFormat.Rtf);

Step 2: Save the RTF to image

Image[] images = doc.SaveToImages(Spire.Doc.Documents.ImageType.Metafile);

Step 3: Traverse the elements in the list of images and save them into .Png format.

for (int i = 0; i < images.Length; i++)
{
    Metafile mf = images[i] as Metafile;
    Image newimage = ResetResolution(mf, 200);
    string outputfile = String.Format("image-{0}.png", i);
    newimage.Save(outputfile, System.Drawing.Imaging.ImageFormat.Png);
}

Step 4: Set the image resolution call the method: ResetResolution.

public static Image ResetResolution(Metafile mf, float resolution)
{
    int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
    int height = (int)(mf.Height * resolution / mf.VerticalResolution);
    Bitmap bmp = new Bitmap(width, height);
    bmp.SetResolution(resolution, resolution);
    using (Graphics g = Graphics.FromImage(bmp))
    {
        g.DrawImage(mf, Point.Empty);
    }
    return bmp;
}

Effective screenshot of the image before reset the image resolution:

How to convert RTF to Image and reset image resolution

The image after reset the image resolution:

How to convert RTF to Image and reset image resolution

Full codes:

using Spire.Doc;
using System.Drawing;
using System.Drawing.Imaging;

namespace RTFtoImage
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new document and load from file.
            Document doc = new Document();
            doc.LoadFromFile("sample.rtf", FileFormat.Rtf);
            // save the RTF to image 
            Image[] images = doc.SaveToImages(Spire.Doc.Documents.ImageType.Metafile);
            for (int i = 0; i < images.Length; i++)
            {
                Metafile mf = images[i] as Metafile;
                Image newimage = ResetResolution(mf, 200);
                string outputfile = String.Format("image-{0}.png", i);
                newimage.Save(outputfile, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
        //set the image resolution by the ResetResolution() method
        public static Image ResetResolution(Metafile mf, float resolution)
        {
            int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
            int height = (int)(mf.Height * resolution / mf.VerticalResolution);
            Bitmap bmp = new Bitmap(width, height);
            bmp.SetResolution(resolution, resolution);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawImage(mf, Point.Empty);
            }
            return bmp;
        }
    }
}
Published in Conversion

Plain text format (TXT) is a basic format with the advantage of small size and it is compatible with almost all applications. With Spire.Doc for .NET, developers can convert word document into TXT easily. This article will show you how to load a plain text files and convert it to word documents.

Spire.Doc allows developers to import plain text file the same way as other document formats, by using the class Spire.Doc.Document. The whole process only need you three lines of codes. Firstly, please check the original plain text file as below:

How to load a plain text (txt) files and save it as word document

Here comes to the steps of how to save txt document into .docx.

Step 1: Create document instance and load the plain text file.

Document doc = new Document();
doc.LoadText("Sample.txt");

Step 2: Save the file as word document in .docx by using the code below

doc.SaveToFile("Result.docx", FileFormat.Docx2010);

Below is an effective screenshot of the result word document.

How to load a plain text (txt) files and save it as word document

Full codes:

namespace txttoword
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadText("Sample.txt");
            doc.SaveToFile("Result.docx", FileFormat.Docx2010);
        }
    }
}
Published in Conversion
Thursday, 20 March 2014 08:52

How to Convert Word to PDF/A in C# ?

PDF/A is an ISO-standardized version of the Portable Document Format (PDF) specialized for the digital preservation of electronic documents. It is widely used for long term archiving for PDF format. This article mainly shows how to convert word document (doc and docx) to PDF/A in C# by using Spire.Doc.

Make sure Spire.Doc for .NET Version 5.0.26 (or above) has been installed correctly and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll".

First, check the original word document that will be converted to PDF/A.

Convert Word to PDF/A in C#

Here comes to the details of how developers convert word document to PDF/A directly by using Spire.Doc:

Step 1: Load a word document from the file.

Document document = new Document();
document.LoadFromFile(@"D:\test.docx",FileFormat.Docx);

Step 2: Sets the Pdf document's Conformance-level to PDF_A1B.

ToPdfParameterList toPdf = new ToPdfParameterList();
toPdf.PdfConformanceLevel = Spire.Pdf.PdfConformanceLevel.Pdf_A1B;

Step 3: Save word document to PDF

document.SaveToFile("result.Pdf",toPdf);

Please check the effective screenshot of the result PDF in PDF/A format.

Convert Word to PDF/A in C#

Published in Conversion
Tuesday, 04 March 2014 01:29

Convert HTML file to PDF and XPS in C#

HTML file is widely used to collect data and for the security reason, we need to convert it to printable documents in PDF and XPS formats. You can easily convert HTML page in URL to PDF in high quality by using Spire.PDF. This article will focus on demonstrate how to convert HTML files into the printable document, both in PDF and XPS by the help of Spire.Doc.

First, check the html file that will be converted to PDF and XPS.

Convert HTML file to PDF and XPS

Secondly, download Spire.Doc and install on your system. The Spire.Doc installation is clean, professional and wrapped up in a MSI installer.

Then adds Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll".

Now it comes to the steps of how to convert HTML into PDF and XPS.

Step 1: Load a HTML file from the file.

Document document = new Document();
document.LoadFromFile("Good.htm", FileFormat.Html, XHTMLValidationType.None) ;

Step 2: Save HTML to the file format in PDF and XPS.

//Save html to PDF.
document.SaveToFile("Sample.pdf", FileFormat.PDF);

//Save html to XPS.
document.SaveToFile("Sample.xps", FileFormat.XPS);

After debugging, please check the following PDF and XPS file as the result.

Convert HTML file to PDF and XPS

Convert HTML file to PDF and XPS

Full codes:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace HTML2PDFXPS
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Document document = new Document();
            document.LoadFromFile("Good.htm", FileFormat.Html, XHTMLValidationType.None);

            //Save html to PDF.
            document.SaveToFile("Sample.pdf", FileFormat.PDF);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Document document = new Document();
            document.LoadFromFile("Good.htm", FileFormat.Html, XHTMLValidationType.None);

            //Save html to PDF.
            document.SaveToFile("Sample.xps", FileFormat.XPS);
         }
    }
}
Published in Conversion
Tuesday, 17 December 2013 08:17

How to Convert HTML to XML in C#, VB.NET

Office OpenXML becomes the technology of choice for delivering structured data on the Web, working hand-in-hand with HTML and fully complementing HTML. Consequently, we need to convert HTML to Office OpenXML at some point at work. This article mainly talks about the conversion process through a professional Word .NET library Spire.Doc.

First we need to complete the preparatory work before the procedure:

  • Download the Spire.Doc and install it on your machine.
  • Add the Spire.Doc.dll files as reference.
  • Open bin folder and select the three dll files under .NET 4.0.
  • Right click property and select properties in its menu.
  • Set the target framework as .NET 4.
  • Add Spire.Doc as namespace.

The following steps will show you how to do this with ease:

Step 1: Create a Word document.

[C#]
Document doc = new Document();

Step 2: Load the HTML file.

[C#]
doc.LoadFromFile("Sample.html");

Step 3: Save the HTML as the XML file.

[C#]
doc.SaveToFile("test.xml", FileFormat.Xml);

Here comes to the full C# and VB.NET code

[C#]
using Spire.Doc;

namespace HTMLXML
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Sample.html");
            doc.SaveToFile("test.xml", FileFormat.Xml);
        }

 
    }
}
[VB.NET]
Imports Spire.Doc

Namespace HTMLXML
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New Document()
			doc.LoadFromFile("Sample.html")
			doc.SaveToFile("test.xml", FileFormat.Xml)
		End Sub


	End Class
End Namespace

Preview of original HTML file.

HTML_effect_screenshot

Preview of generated Office OpenXML file.

XML_effect_screenshot

Published in Conversion
Page 2 of 4