Content controls provide a way for you to design documents. When you add a content control to a document, the control is identified by a border, a title, and temporary text that can provide instructions to the user. According to Microsoft, content controls mainly benefit from two features:

  • Prevent users from editing or deleting protected sections of a document.
  • Bind parts of a document or template to data. You can bind content controls to database fields, managed objects in the .NET Framework, XML elements that are stored in the document, and other data sources.

Therefore, it is necessary for developers to get the properties of content controls when dealing content controls at run time. This article illustrates how to get all controls and their properties including alias, id and tag via Spire.Doc.

Firstly, check the test file that contains six content controls distributed in lines and a table. By default, the border and the title of the control do not appear if we don't click the protected section.

Test File:

Get alias, tag and id of content controls in a Word document in C#

Main Steps:

Step 1: Create a new Word document and load the test file.

Step 2: Create two lists to store tags which are distributed in lines and a table separately. Here, each content control will be identified by tag.

Step 3: Use foreach sentence to get all tags in the Word document.

Full Code:

       static void Main(string[] args)
        {
            using (Document document = new Document(@"..\..\TestData\test.docx"))
            {
                StructureTags structureTags = GetAllTags(document);
                List<StructureDocumentTagInline> tagInlines = structureTags.tagInlines;

                string alias = tagInlines[0].SDTProperties.Alias;
                decimal id = tagInlines[0].SDTProperties.Id;
                string tag = tagInlines[0].SDTProperties.Tag;

                List<StructureDocumentTag> tags = structureTags.tags;
                alias = tags[0].SDTProperties.Alias;
                id = tags[0].SDTProperties.Id;
                tag = tags[0].SDTProperties.Tag;

            }
        }
       static StructureTags GetAllTags(Document document)
        {
            StructureTags structureTags = new StructureTags();
            foreach (Section section in document.Sections)
            {
                foreach (DocumentObject obj in section.Body.ChildObjects)
                {
                    if (obj.DocumentObjectType == DocumentObjectType.Paragraph)
                    {
                        foreach (DocumentObject pobj in (obj as Paragraph).ChildObjects)
                        {
                            if (pobj.DocumentObjectType == DocumentObjectType.StructureDocumentTagInline)
                            {
                                structureTags.tagInlines.Add(pobj as StructureDocumentTagInline);
                            }
                        }
                    }
                    else if (obj.DocumentObjectType == DocumentObjectType.Table)
                    {
                        foreach (TableRow row in (obj as Table).Rows)
                        {
                            foreach (TableCell cell in row.Cells)
                            {
                                foreach (DocumentObject cellChild in cell.ChildObjects)
                                {
                                    if (cellChild.DocumentObjectType == DocumentObjectType.StructureDocumentTag)
                                    {
                                        structureTags.tags.Add(cellChild as StructureDocumentTag);
                                    }
                                    else if (cellChild.DocumentObjectType == DocumentObjectType.Paragraph)
                                    {
                                        foreach (DocumentObject pobj in (cellChild as Paragraph).ChildObjects)
                                        {
                                            if (pobj.DocumentObjectType == DocumentObjectType.StructureDocumentTagInline)
                                            {
                                                structureTags.tagInlines.Add(pobj as StructureDocumentTagInline);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return structureTags;
        }
        public class StructureTags
        {
            List<StructureDocumentTagInline> m_tagInlines;
            public List tagInlines
            {
                get
                {
                    if (m_tagInlines == null)
                        m_tagInlines = new List();
                    return m_tagInlines;
                }
                set
                {
                    m_tagInlines = value;
                }
            }
            List<StructureDocumentTag> m_tags;
            public List tags
            {
                get
                {
                    if (m_tags == null)
                        m_tags = new List();
                    return m_tags;
                }
                set
                {
                    m_tags = value;
                }
            }
        }

Effect Screenshot:

Content controls in lines

Get alias, tag and id of content controls in a Word document in C#

Content controls in table

Get alias, tag and id of content controls in a Word document in C#

Wednesday, 08 October 2014 09:07

Add image as page background in PDF file

As a powerful PDF component, Spire.PDF supports to work with page setting for PDF well, such as set PDF properties, view preference, and set background color etc. This article will focus on show you how to add image as page background to an existing PDF file in C#.

Make sure Spire.PDF for .NET has been installed correctly and then add Spire.Pdf.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Pdf\Bin\NET4.0\ Spire.Pdf.dll".

Firstly, check the original PDF file without background image.

Add image as page background in PDF file

The following code snippet shows you how to add image as background for PDF in C#.

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

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");

Step 2: Get the first page in PDF file

PdfPageBase page = doc.Pages[0];

Step 3: Load the image from file and set it as background image.

Image backgroundImage = Image.FromFile("background.png");
page.BackgroundImage = backgroundImage;

Step 4: Save the document to file and launch it.

doc.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");

Effective Screenshot:

Add image as page background in PDF file

Full Codes:

using Spire.Pdf;
using System.Drawing;

namespace Addimagebackground
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("sample.pdf");
            PdfPageBase page = doc.Pages[0];
            Image backgroundImage = Image.FromFile("background.png");
            page.BackgroundImage = backgroundImage;
            doc.SaveToFile("result.pdf");
            System.Diagnostics.Process.Start("result.pdf");
        }
    }
}

Text annotation is frequently used in PDF for creating a comment or explaining more about an item. Using Spire.PDF you can create a text mark-up annotation, edit an existing annotation and delete specified or all annotations. This article is aimed to demonstrate how to modify and format an existing text annotation in a PDF document.

Test File:

Modify and Format Annotation in PDF in C#, VB.NET

Changes we want to make:

  • Modify the annotation text.
  • Change the color of the annotation icon.
  • Fix the annotation flag including its position, color, and type.

Code Snippet

Step 1: Create a new PDF document and load the test file.

PdfDocument pdf = new PdfDocument("test.pdf");

Step 2: Get the annotation from the document.

PdfAnnotation annotation = pdf.Pages[0].Annotations[0];

Step 3: Set the text, border, color of the annotation and lock the annotation flag.

annotation.Text = "Revised annotation";
annotation.Border = new PdfAnnotationBorder(0.75f);
annotation.Color = new PdfRGBColor(Color.White);
annotation.Flags = PdfAnnotationFlags.Locked;

Step 4: Save and launch the file.

pdf.SaveToFile("result.pdf");
Process.Start("result.pdf");

Target Effect:

Modify and Format Annotation in PDF in C#, VB.NET

Full Code:

[C#]
using Spire.Pdf;
using Spire.Pdf.Annotations;
using Spire.Pdf.Graphics;
using System.Diagnostics;
using System.Drawing;

namespace ModifyAndFormatAnnotation
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument pdf = new PdfDocument("test.pdf");
            PdfAnnotation annotation = pdf.Pages[0].Annotations[0];

            annotation.Text = "Revised annotation";
            annotation.Border = new PdfAnnotationBorder(0.75f);
            annotation.Color = new PdfRGBColor(Color.White);
            annotation.Flags = PdfAnnotationFlags.Locked;

            pdf.SaveToFile("result.pdf");
            Process.Start("result.pdf");
        }

    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Annotations
Imports Spire.Pdf.Graphics
Imports System.Diagnostics
Imports System.Drawing

Namespace ModifyAndFormatAnnotation
	Class Program
		Private Shared Sub Main(args As String())
			Dim pdf As New PdfDocument("test.pdf")
			Dim annotation As PdfAnnotation = pdf.Pages(0).Annotations(0)

			annotation.Text = "Revised annotation"
			annotation.Border = New PdfAnnotationBorder(0.75F)
			annotation.Color = New PdfRGBColor(Color.White)
			annotation.Flags = PdfAnnotationFlags.Locked

			pdf.SaveToFile("result.pdf")
			Process.Start("result.pdf")
		End Sub

	End Class
End Namespace

When you need to print many PDF documents, surely you don't want to see the print dialog every time. This article will show you clearly how to print PDF documents in WPF without invoking Print Dialog by using Spire.PDFViewer for WPF.

Here comes to the steps of how to print PDF files in WPF.

Step 1: First you need to create a new project by choosing "WPF Application".

Step 2: Set the Target Framework to be .NET Framework 4 in Properties.

Step 3: Right-click on the blank part of the Toolbox → "Add Tab" → "Choose Items" → "WPF Components" → "Browse" to the "Bin" folder → find the file "Spire.PdfViewer.Wpf.dll" → "OK".

Step4: Spire.PDFViewer offers PdfViewer and PdfDocumentViewer to print the PDF files in C#. Please check the code snippet as below:

Print via PdfViewer without invoking PrintDialog with the following method.

PrintDialog dialog = new PrintDialog();
this.pdfViewer1.PrintDialog = dialog;
dialog.PrintDocument(pdfViewer1.PrintDocument.DocumentPaginator, "Print Document");

Print via PdfDocumentViewer without invoking PrintDialog with the following method.

PrintDialog dialog = new PrintDialog();
this.pdfDocumentViewer1.PrintDialog = dialog;
dialog.PrintDocument(pdfDocumentViewer1.PrintDocument.DocumentPaginator, "Print Document");

Then your PDF document will be printed directly without showing the print dialog.

Full codes of how to print PDF file in WPF.

namespace PrintPDFinWPF
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.pdfViewer1.LoadFromFile("sample.pdf");
            ////Print the PDF file directly with PrintDialog
            //this.pdfViewer1.Print();

            //Print without Print Dialog
            PrintDialog dialog = new PrintDialog();
            this.pdfViewer1.PrintDialog = dialog;
            dialog.PrintDocument(pdfViewer1.PrintDocument.DocumentPaginator, "Print Document");
        }
    }
}

A file with the XLSM extension is an Excel Macro-Enabled Workbook file. For security reasons, XLS file or XLSX file does not enable macros by default. Thus, if you want to execute macros in Excel file, you need to convert XLS or XLSX to XLSM at the first place. In this article, I’ll introduce you how to convert XLS to XLSM with the macro maintained using Spire.XLS.

Here is the method:

Step 1: Create a new instance of Spire.Xls.Workbook class.

Workbook workbook = new Workbook();

Step 2: Load the test file and imports its data to workbook.

workbook.LoadFromFile("test.xls", ExcelVersion.Version97to2003);

Step 3: Save the workbook as a new XLSM file.

workbook.SaveToFile("result.xlsm", FileFormat.Version2007);

Full Code:

[C#]
using Spire.Xls;
namespace Convert
{
    class Program
    {
          static void Main(string[] args)
{
    Workbook workbook = new Workbook();
    workbook.LoadFromFile("test.xls", ExcelVersion.Version97to2003);
    workbook.SaveToFile("result.xlsm", FileFormat.Version2007);
}

        }
    }
[VB.NET]
Imports Spire.Xls
Namespace Convert
	Class Program
		Private Shared Sub Main(args As String())
			Dim workbook As New Workbook()
			workbook.LoadFromFile("test.xls", ExcelVersion.Version97to2003)
			workbook.SaveToFile("result.xlsm", FileFormat.Version2007)
		End Sub

	End Class
End Namespace

Test File:

As is shown in the picture, Excel automatically disables macro in XLS file.

Convert XLS to XLSM and Maintain Macro in C#, VB.NET

Result:

No security warning in the converted XLSM file.

Convert XLS to XLSM and Maintain Macro in C#, VB.NET

Friday, 23 September 2022 01:06

C#/VB.NET: Convert PowerPoint to XPS

The XML Paper Specification (XPS) format is an electronic representation of digital documents based on XML. It is a paginated, fixed-layout format that enables the content and design details of a document to be maintained intact across computers. Sometimes you may need to convert a PowerPoint document to XPS for better printing or sharing, and this article will demonstrate how to accomplish this task programmatically using Spire.Presentation for .NET.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation 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.Presentation

Convert PowerPoint to XPS

The detailed steps are as follows:

  • Create a Presentation instance.
  • Load a sample PowerPoint document using Presentation.LoadFromFile() method.
  • Save the PowerPoint document to XPS using Presentation.SaveToFile(String, FileFormat) method.
  • C#
  • VB.NET
using Spire.Presentation;

namespace PowerPointtoXPS
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation presentation = new Presentation();

            //Load a sample PowerPoint document
            presentation.LoadFromFile("test.pptx");

            //Save to XPS file
            presentation.SaveToFile("toXPS.xps", FileFormat.XPS);
        }
    }
}

C#/VB.NET: Convert PowerPoint to XPS

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.

Friday, 30 December 2022 06:15

C#/VB.NET: Replace Images in Word Documents

Sometimes you may encounter a situation where you need to replace images in a Word document. For example, if you are creating a resume from a template, you may need to replace the profile picture in the template with your own photo. In this article, we will show you how to replace images in a Word document in C# and VB.NET 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

Replace Image with New Image in Word in C# and VB.NET

To replace an image in a Word document with another image, you need to loop through the elements of the document, find the images and add them to a list, then get the image that you want to replace from the list and call the DocPicture.LoadImage() method to replace it with another image.

The following are the detailed steps:

  • Initialize an instance of the Document class.
  • Load a Word document using Document.LoadFromFile() method.
  • Initialize an instance of the List class.
  • Iterate through all sections in the document.
  • Iterate through all paragraphs in each section.
  • Iterate through all child objects in each paragraph.
  • Find the images and add them to the list.
  • Get a specific image from the list and replace it with another image using DocPicture.LoadImage() method.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Collections.Generic;
using System.Drawing;

namespace ReplaceImageWithImage
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Document class
            Document doc = new Document();
            //Load a Word document
            doc.LoadFromFile("Sample.docx");

            //Initialize an instance of the List class
            List pictures = new List();

            //Iterate through all sections in the document
            foreach (Section sec in doc.Sections)
            {
                //Iterate through all paragraphs in each section
                foreach (Paragraph para in sec.Paragraphs)
                {
                    //Iterate through all child objects in each paragraph
                    foreach (DocumentObject docObj in para.ChildObjects)
                    {
                        //Find the images and add them to the list
                        if (docObj.DocumentObjectType == DocumentObjectType.Picture)
                        {
                            pictures.Add(docObj);
                        }
                    }
                }
            }

            //Replace the first picture in the list with another image
            DocPicture picture = pictures[0] as DocPicture;
            picture.LoadImage(Image.FromFile(@"doc.png"));

            //Save the result document
            doc.SaveToFile("ReplaceWithNewImage.docx", FileFormat.Docx2013);

        }
    }
}

C#/VB.NET: Replace Images in Word Documents

Replace Image with Text in Word in C# and VB.NET

Spire.Doc doesn’t provide a direct method to replace image with text, but you can achieve this task by inserting the text at the image location and then removing the image from the document.

The following steps demonstrate how to replace all images in a Word document with text:

  • Initialize an instance of the Document class.
  • Load a Word document using Document.LoadFromFile() method.
  • Iterate through all sections in the document.
  • Iterate through all paragraphs in each section.
  • Initialize an instance of the List class.
  • Iterate through all child objects in each paragraph.
  • Find the images and add them to the list.
  • Iterate through the images in the list.
  • Get the index of the image in the paragraph using Paragraph.ChildObjects.Indexof() method.
  • Initialize an instance of TextRange class and set text for the text range through TextRange.Text property.
  • Insert the text range at the image location using Paragraph.ChildObjects.Insert() method.
  • Remove the image from the paragraph using Paragraph.ChildObjects.Remove() method.
  • Save the result document using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Collections.Generic;

namespace ReplaceImageWithText
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Document class
            Document doc = new Document();
            //Load a Word document
            doc.LoadFromFile("Sample.docx");

            int j = 1;
            //Iterate through all sections in the document
            foreach (Section sec in doc.Sections)
            {
                //Iterate through all paragraphs in each section
                foreach (Paragraph para in sec.Paragraphs)
                {
                    //Initialize an instance of the List class
                    List pictures = new List();
                    //Find the images and add them to the list
                    foreach (DocumentObject docObj in para.ChildObjects)
                    {
                        if (docObj.DocumentObjectType == DocumentObjectType.Picture)
                        {
                            pictures.Add(docObj);
                        }
                    }

                    //Iterate through all images in the list and replace them with text "Here is image {image index}"
                    foreach (DocumentObject pic in pictures)
                    {
                        int index = para.ChildObjects.IndexOf(pic);
                        TextRange range = new TextRange(doc);
                        range.Text = string.Format("Here is image-{0}", j);
                        para.ChildObjects.Insert(index, range);
                        para.ChildObjects.Remove(pic);
                        j++;
                    }
                }
            }

            //Save the result document
            doc.SaveToFile("ReplaceWithText.docx", FileFormat.Docx);
        }
    }
}

C#/VB.NET: Replace Images in Word Documents

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.

Monday, 22 September 2014 09:10

Print PDF files in C#

PDF files can't be edited easily and for this reason, it is the most popular file format in business field. Printing PDF files becomes a widely asked requirement as a result. This tutorial focus on introducing how to print PDF files via a .NET PDF API. With the help of Spire.PDF for .NET, developers can finish the print function in a few lines codes to print the PDF files with the default printer or any other network connected printer. You can also print all the PDF pages or only print the selected pages you want.

ATTENTION THAT, if you are using the Spire.PDF Version 3.9.360 or above, please refer to tutorial here.

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

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");

If you want to print all the pages in PDF file with the default printer, please go to Step 2. If you want to set the printer and only print some pages in the PDF file, please go to Step 3 directly.

Step 2: Print the PDF file with the default printer to print all the pages

doc.PrintDocument.Print();

Step 3: Set the Printer and select the pages you want to print in the PDF file.

PrintDialog dialogPrint = new PrintDialog();
dialogPrint.AllowPrintToFile = true;
dialogPrint.AllowSomePages = true;
dialogPrint.PrinterSettings.MinimumPage = 1;
dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
dialogPrint.PrinterSettings.FromPage = 1;
dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;
          
if (dialogPrint.ShowDialog() == DialogResult.OK)
   {
     //Set the pagenumber which you choose as the start page to print
     doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
     //Set the pagenumber which you choose as the final page to print
     doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
     //Set the name of the printer which is to print the PDF
     doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

     PrintDocument printDoc = doc.PrintDocument;
     printDoc.Print();
  }

By using the Step 2 method to print all the pages with the default printer, it will start to print the PDF files automatically when you process it. If you select the printer and the pages you choose to print, then you will get a printer dialog as below:

How to print PDF files in C#

The full codes of how to print PDF file in C#:

[C#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Pdf;
using System.Windows.Forms;
using Spire.Pdf.Annotations;
using Spire.Pdf.Widget;
using System.Drawing.Printing;


namespace PrintPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("sample.pdf");

            //Use the default printer to print all the pages
            //doc.PrintDocument.Print();

            //Set the printer and select the pages you want to print

            PrintDialog dialogPrint = new PrintDialog();
            dialogPrint.AllowPrintToFile = true;
            dialogPrint.AllowSomePages = true;
            dialogPrint.PrinterSettings.MinimumPage = 1;
            dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
            dialogPrint.PrinterSettings.FromPage = 1;
            dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;
          
            if (dialogPrint.ShowDialog() == DialogResult.OK)
            {
                doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
                doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
                doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

                PrintDocument printDoc = doc.PrintDocument;
                printDoc.Print();
            }

        }
    }
}

Maybe you have met this case in your work: You receive a lot of files that are in different file types, some are Word, some are PowerPoint slides, or some are Excel, etc, and you need to combine these files to one PDF for easy sharing. In this article, I’ll introduce you how to convert each file type into an Adobe PDF and then simultaneously merge them into a single PDF document using Spire.Office.

In this sample, I get four types of file (.doc, .docx, .xls, .pdf) prepared at first. Within the Spire.Office, it provides SaveToStream() method which allows us to save Word and Excel documents into stream, then these streams can be converted to PDF documents by calling the method of PdfDocument(Stream stream). At last, we could merge these PDF files to one file with the method PdfDocument.AppendPage(). More details would be as follows:

Code Snippet for Merge Multiple File Types to One PDF

Step 1: Create four new PDF documents.

PdfDocument[] documents = new PdfDocument[4];

Step 2: Load the .doc file, save it into stream and generate new PDF document from the stream.

using (MemoryStream ms1 = new MemoryStream())
{
      Document doc = new Document("01.doc", Spire.Doc.FileFormat.Doc);
      doc.SaveToStream(ms1, Spire.Doc.FileFormat.PDF);
      documents[0] = new PdfDocument(ms1);
}

Step 3: Repeat Step 2 to generate two PDF documents from .docx file and .xls file.

using (MemoryStream ms2 = new MemoryStream())
{
      Document docx = new Document("02.docx", Spire.Doc.FileFormat.Docx2010);
      docx.SaveToStream(ms2, Spire.Doc.FileFormat.PDF);
      documents[1] = new PdfDocument(ms2);
}
using (MemoryStream ms3 = new MemoryStream())
{
      Workbook workbook = new Workbook();
      workbook.LoadFromFile("03.xls", ExcelVersion.Version97to2003);
      workbook.SaveToStream(ms3, Spire.Xls.FileFormat.PDF);
      documents[2] = new PdfDocument(ms3);
}

Step 4: Load .pdf file and save it to documents[3].

documents[3] = new PdfDocument("04.pdf");

Step 5: Append the documents[0],[1],[2] to documents[3] and save as a new PDF document.

for (int i = 2; i > -1; i--)
{
      documents[3].AppendPage(documents[i]);
}
documents[3].SaveToFile("Result.pdf");

Screenshot of the Effect:

Merge Multiple File Types into One PDF

Full Code:

[C#]
using Spire.Doc;
using Spire.Xls;
using Spire.Pdf;

namespace MergeMultiTypestoOnePDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument[] documents = new PdfDocument[4];
            using (MemoryStream ms1 = new MemoryStream())
            {
                Document doc = new Document("01.doc", Spire.Doc.FileFormat.Doc);
                doc.SaveToStream(ms1, Spire.Doc.FileFormat.PDF);
                documents[0] = new PdfDocument(ms1);
            }
            using (MemoryStream ms2 = new MemoryStream())
            {
                Document docx = new Document("02.docx", Spire.Doc.FileFormat.Docx2010);
                docx.SaveToStream(ms2, Spire.Doc.FileFormat.PDF);
                documents[1] = new PdfDocument(ms2);
            }
            using (MemoryStream ms3 = new MemoryStream())
            {
                Workbook workbook = new Workbook();
                workbook.LoadFromFile("03.xls", ExcelVersion.Version97to2003);
                workbook.SaveToStream(ms3, Spire.Xls.FileFormat.PDF);
                documents[2] = new PdfDocument(ms3);
            }
            documents[3] = new PdfDocument("04.pdf");

            for (int i = 2; i > -1; i--)
            {
                documents[3].AppendPage(documents[i]);
            }

            documents[3].SaveToFile("Result.pdf");

        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Xls
Imports Spire.Pdf

Namespace MergeMultiTypestoOnePDF
	Class Program
		Private Shared Sub Main(args As String())
			Dim documents As PdfDocument() = New PdfDocument(3) {}
			Using ms1 As New MemoryStream()
				Dim doc As New Document("01.doc", Spire.Doc.FileFormat.Doc)
				doc.SaveToStream(ms1, Spire.Doc.FileFormat.PDF)
				documents(0) = New PdfDocument(ms1)
			End Using
			Using ms2 As New MemoryStream()
				Dim docx As New Document("02.docx", Spire.Doc.FileFormat.Docx2010)
				docx.SaveToStream(ms2, Spire.Doc.FileFormat.PDF)
				documents(1) = New PdfDocument(ms2)
			End Using
			Using ms3 As New MemoryStream()
				Dim workbook As New Workbook()
				workbook.LoadFromFile("03.xls", ExcelVersion.Version97to2003)
				workbook.SaveToStream(ms3, Spire.Xls.FileFormat.PDF)
				documents(2) = New PdfDocument(ms3)
			End Using
			documents(3) = New PdfDocument("04.pdf")

			For i As Integer = 2 To -1 + 1 Step -1
				documents(3).AppendPage(documents(i))
			Next

			documents(3).SaveToFile("Result.pdf")

		End Sub
	End Class
End Namespace

Microsoft PowerPoint automatically shows the number Format in Arabic number for data cell on chart and it will show tick marks on the value axis and category axis. In order to make the chart more clearly and tidy, we may need to set percentage number format for the data and remove the tick marks. With the help of Spire.Presentation, we can achieve these requirements easily.

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

Check the custom chart on presentation slides at first:

Set Number Format and remove tick marks on Chart

Step 1: Create a presentation document and load the file from disk.

Presentation ppt = new Presentation();
ppt.LoadFromFile("sample.pptx");

Step 2: Get the chart that need to be adjust the number format and remove the tick marks.

IChart chart = ppt.Slides[0].Shapes[3] as IChart;

Step 3: Set percentage number format for the axis value of chart.

chart.PrimaryValueAxis.NumberFormat = "0#\\%";

Step 4: Remove the tick marks for value axis and category axis.

chart.PrimaryValueAxis.MajorTickMark = TickMarkType.TickMarkNone;
chart.PrimaryValueAxis.MinorTickMark = TickMarkType.TickMarkNone;
chart.PrimaryCategoryAxis.MajorTickMark = TickMarkType.TickMarkNone;
chart.PrimaryCategoryAxis.MinorTickMark = TickMarkType.TickMarkNone;

Step 5: Save and Launch to view the resulted PPTX file.

ppt.SaveToFile("Result.pptx", FileFormat.Pptx2007);
System.Diagnostics.Process.Start("Result.pptx");

Effective screenshot:

Set Number Format and remove tick marks on Chart

Full codes:

namespace SetNumberFormatforChartData
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("sample.pptx");
            IChart chart = ppt.Slides[0].Shapes[3] as IChart;
            chart.PrimaryValueAxis.NumberFormat = "0#\\%";

            chart.PrimaryValueAxis.MajorTickMark = TickMarkType.TickMarkNone;
            chart.PrimaryValueAxis.MinorTickMark = TickMarkType.TickMarkNone;
           
            chart.PrimaryCategoryAxis.MajorTickMark = TickMarkType.TickMarkNone;
            chart.PrimaryCategoryAxis.MinorTickMark = TickMarkType.TickMarkNone;

            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2007);
            System.Diagnostics.Process.Start("Result.pptx");

        }
    }
}