Comparison of two versions of a document is the process of checking the new version against the previous one to identify changes made by different contributors. By comparing documents, legal staffs can easily review contracts to determine what changes have been made or still need to be made, and teachers can quickly compare student papers to determine whether or not necessary changes have been applied. In this article, you will learn how to compare two Word documents in C++ using Spire.Doc for C++.

The following is a screenshot of the two Word documents we’re going to compare.

C++: Compare Two Word Documents for Differences

Install Spire.Doc for C++

There are two ways to integrate Spire.Doc for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.

Integrate Spire.Doc for C++ in a C++ Application

Compare Two Word Documents in C++

Spire.Doc for C++ allows to compare two Word documents and save the result in a third document. When opening this document with MS Word, you can see all changes that have been made to the original document, including insertions, deletions as well as formatting modifications. The following are the detailed steps.

  • Load two Word documents separately while initialing two different Document objects.
  • Compare these two documents using Document->Compare() method.
  • Save the result in a third Word document using Document->SaveToFile() method.
  • C++
#include "Spire.Doc.o.h"

using namespace Spire::Doc;

int main() {

 //Load the first document
 intrusive_ptr<Document> doc1 = new Document(L"C:\\Users\\Administrator\\Desktop\\Original.docx");

 //Load the second document
 intrusive_ptr<Document> doc2 = new Document(L"C:\\Users\\Administrator\\Desktop\\Revised.docx");

 //Compare the second document on the basis of the first document 
 doc1->Compare(doc2, L"Patrick");

 //Save to a docx file
 doc1->SaveToFile(L"output/Result.docx", Spire::Doc::FileFormat::Docx2013);

 doc1->Close();
 doc2->Close();
}

C++: Compare Two Word Documents for Differences

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.

PDF margins are blank areas between content and page edges. In most cases, we set moderate or narrow margins in order to create a compact appearance. However, if we wish to place a company logo or other relevant information in the margins, we need to make the margins a bit wider. In this article, you will learn how to increase or decrease the margins of an existing PDF document in C# and VB.NET using Spire.PDF for .NET.

Install Spire.PDF for .NET

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

Increase the Margins of a PDF Document in C#, VB.NET

The way to enlarge the margins of a PDF document is to create a new PDF that has a larger page size, and then draw the source page on the large page at the appropriate location. The following are the steps to increase the margins of a PDF document using Spire.PDF for .NET.

  • Load the original PDF document while initialing the PdfDocument object.
  • Create another PdfDocument object, which is used to create a new PDF document that has a larger page size.
  • Set the increasing values of the margins.
  • Calculate the page size of the new PDF document.
  • Loop through the pages in the original document, and create a template based on a specific page using PdfPageBase.CreateTemplate() method.
  • Add a page to the new PDF document using PdfDocument.Pages.Add() method.
  • Draw the template on the page at the coordinate (0, 0) using PdfTemplate.Draw() method.
  • Save the new PDF document to file using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace IncreaseMargins
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the original PDF document
            PdfDocument originalPdf = new PdfDocument("C:\\Users\\Administrator\\Desktop\\sample.pdf");

            //Get the first page
            PdfPageBase firstPage = originalPdf.Pages[0];

            //Create a new PdfDocument object
            PdfDocument newPdf = new PdfDocument();

            //Set increasing value of the margins
            PdfMargins margins = newPdf.PageSettings.Margins;
            margins.Top = 40;
            margins.Bottom=40;
            margins.Left=40;
            margins.Right= 40;

            //Calculate the new page size
            SizeF sizeF = new SizeF(firstPage.Size.Width + margins.Left + margins.Right, firstPage.Size.Height + margins.Top + margins.Bottom);

            //Loop through the pages in the original document
            for (int i = 0; i < originalPdf.Pages.Count; i++)
            {
                //Create a template based on a spcific page
                PdfTemplate pdfTemplate = originalPdf.Pages[i].CreateTemplate();

                //Add a page to the new PDF
                PdfPageBase page = newPdf.Pages.Add(sizeF);

                //Draw template on the page
                pdfTemplate.Draw(page, 0, 0);
            }

            //Save the new document
            newPdf.SaveToFile("IncreaseMargins.pdf", FileFormat.PDF);
        }
    }
}

C#/VB.NET: Adjust the Margins of a PDF Document

Decrease the Margins of a PDF Document in C#, VB.NET

The way to decrease the margins of a PDF is to create a new PDF that has a smaller page size, and then draw the source page on the small page at a specified coordinate. The following are the steps to decrease the margins of a PDF document using Spire.PDF for .NET.

  • Load the original PDF document while initialing the PdfDocument object.
  • Create another PdfDocument object, which is used to create a new PDF document that has a smaller page size.
  • Set the decreasing values of the margins.
  • Calculate the page size of the new PDF document.
  • Loop through the pages in the original document, and create a template based on a specific page using PdfPageBase.CreateTemplate() method.
  • Add a page to the new PDF document using PdfDocument.Pages.Add() method.
  • Draw the template on the page at a specified coordinate using PdfTemplate.Draw() method.
  • Save the new PDF document to file using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace DecreaseMargins
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the original PDF document
            PdfDocument originalPdf = new PdfDocument("C:\\Users\\Administrator\\Desktop\\sample.pdf");

            //Get the first page
            PdfPageBase firstPage = originalPdf.Pages[0]; 

            //Create a new PdfDocument object
            PdfDocument newPdf = new PdfDocument();

            //Set decreasing value
            float left = -20;
            float right = -20;
            float top = -20;
            float bottom = -20;

            //Calculate the new page size
            SizeF sizeF = new SizeF(firstPage.Size.Width + left + right, firstPage.Size.Height + top + bottom);

            //Loop through the pages in the original document
            for (int i = 0; i < originalPdf.Pages.Count; i++)
            {
                //Create a template based on a specific page
                PdfTemplate pdfTemplate = originalPdf.Pages[i].CreateTemplate();

                //Add a page to the new PDF
                PdfPageBase page = newPdf.Pages.Add(sizeF, new PdfMargins(0));

                //Draw template on the page
                pdfTemplate.Draw(page, left, top);
            }

            //Save the new document
            newPdf.SaveToFile("DecreaseMargins.pdf", FileFormat.PDF);
        }
    }
}

C#/VB.NET: Adjust the Margins of a PDF Document

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.

Speaker notes are hidden notes that can be added to slides to help recall some important or key information. Speaker notes are only visible to the presenter, so adding speaker notes in PowerPoint will not affect the overall visual effectiveness of the document. In this article, you will learn how to programmatically add, read or delete speaker notes in a PowerPoint presentation using Spire.Presentation for C++.

Install Spire.Presentation for C++

There are two ways to integrate Spire.Presentation for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.

Integrate Spire.Presentation for C++ in a C++ Application

Add Speaker Notes in PowerPoint in C++

There are a number of benefits to using speaker notes in a PowerPoint presentation, such as it can help you stay on point and also appear more confident during a presentation. The following are the steps to add speaker notes to a specified slide.

  • Create a Presentation instance and load a PowerPoint document using Presentation->LoadFromFile() method.
  • Get a specified slide using Presentation->GetSlides()->GetItem(slideIndex) method.
  • Add a notes slide to the slide using ISlide->AddNotesSlide() method.
  • Create a TextParagraph instance.
  • Set text for the paragraph using TextParagraph->SetText() method, and then append the paragraph to the notes slide using NotesSlide->GetNotesTextFrame()->GetParagraphs()->Append() method.
  • Save the result document using Presentation->SaveToFile() method.
  • C++
#include "Spire.Presentation.o.h";

using namespace Spire::Presentation;
using namespace std;

int main()
{
	//Specify the input and output file paths
	std::wstring inputFile = L"Data\\Template.pptx";
	std::wstring outputFile = L"SpeakerNotes.pptx";

	//Create a Presentation instance
	intrusive_ptr<Presentation> ppt = new Presentation();

	//Load a sample PowerPoint document from disk
	ppt->LoadFromFile(inputFile.c_str());

	//Get the second slide
	intrusive_ptr<ISlide> slide = ppt->GetSlides()->GetItem(1);

	//Add a notes slide
	intrusive_ptr<NotesSlide> notesSlide = slide->AddNotesSlide();

	//Add paragraphs to the notes slide and set the content of the speaker notes
	intrusive_ptr⁢TextParagraph> paragraph = new TextParagraph();
	paragraph->SetText(L"Tips for making effective presentations:");
	notesSlide->GetNotesTextFrame()->GetParagraphs()->Append(paragraph);

	paragraph = new TextParagraph();
	paragraph->SetText(L"Use the slide master feature to create a consistent and simple design template.");
	notesSlide->GetNotesTextFrame()->GetParagraphs()->Append(paragraph);

	paragraph = new TextParagraph();
	paragraph->SetText(L"Simplify and limit the number of words on each screen.");
	notesSlide->GetNotesTextFrame()->GetParagraphs()->Append(paragraph);

	paragraph = new TextParagraph();
	paragraph->SetText(L"Use contrasting colors for text and background.");
	notesSlide->GetNotesTextFrame()->GetParagraphs()->Append(paragraph);

	//Set the bullet type and bullet style for specific paragraphs on the notes slide
	for (int i = 1; i < notesSlide->GetNotesTextFrame()->GetParagraphs()->GetCount(); i++)
	{
		notesSlide->GetNotesTextFrame()->GetParagraphs()->GetItem(i)->SetBulletType(TextBulletType::Numbered);
		notesSlide->GetNotesTextFrame()->GetParagraphs()->GetItem(i)->SetBulletStyle(NumberedBulletStyle::BulletArabicPeriod);
	}

	//Save the result file
	ppt->SaveToFile(outputFile.c_str(), FileFormat::Pptx2013);
	ppt->Dispose();
}

C++: Add, Read or Delete Speaker Notes in PowerPoint

Read Speaker Notes in PowerPoint in C++

To get speaker notes from a notes slide, Spire.Presentation for C++ offers the NotesSlide->GetNotesTextFrame()->GetText() method. The following are the detailed steps.

  • Create a Presentation instance and load a PowerPoint document using Presentation->LoadFromFile() method.
  • Get a specified slide using Presentation->GetSlides()->GetItem(slideIndex) method.
  • Get the notes slide from the slide using ISlide->GetNotesSlide() method.
  • Get the speaker notes from the notes slide using NotesSlide->GetNotesTextFrame()->GetText() method, and then save them to a .txt file.
  • C++
#include "Spire.Presentation.o.h";

using namespace Spire::Presentation;
using namespace std;

int main()
{
	//Specify the input and output file paths
	std::wstring inputFile = L"SpeakerNotes.pptx";
	std::wstring outputFile = L"GetSpeakerNotes.txt";

	//Create a Presentation instance
	intrusive_ptr⁢Presentation> presentation = new Presentation();

	//Load a sample PowerPoint document
	presentation->LoadFromFile(inputFile.c_str());

	//Get the second slide
	intrusive_ptr<ISlide> slide = presentation->GetSlides()->GetItem(1);

	//Get the notes slide from the second slide
	intrusive_ptr<NotesSlide> notesSlide = slide->GetNotesSlide();

	//Get the speaker notes and save to txt file
	wofstream desFile(outputFile, ios::out);
	desFile << notesSlide->GetNotesTextFrame()->GetText() << endl;
	desFile.close();
	presentation->Dispose();
}

C++: Add, Read or Delete Speaker Notes in PowerPoint

Delete Speaker Notes in PowerPoint in C++

With Spire.Presentation for C++, you are also allowed to remove all speaker notes at once or just remove a specified speaker note from the notes slide. The following are the detailed steps.

  • Create a Presentation instance and load a PowerPoint document using Presentation->LoadFromFile() method.
  • Get a specified slide using Presentation->GetSlides()->GetItem(slideIndex) method.
  • Get the notes slide from the slide using ISlide->GetNotesSlide() method.
  • Remove all speaker notes from the notes slide using NotesSlide->GetNotesTextFrame()->GetParagraphs()->Clear() method or remove a specific speaker note from the notes slide using NotesSlide->GetNotesTextFrame()->GetParagraphs()->RemoveAt(paragraphIndex) method.
  • Save the result document using Presentation->SaveToFile() method.
  • C++
#include "Spire.Presentation.o.h";

using namespace Spire::Presentation;
using namespace std;

int main()
{
	//Specify the input and output file paths
	std::wstring inputFile = L"SpeakerNotes.pptx";
	std::wstring outputFile = L"RemoveSpeakerNotes.pptx";

	//Create a Presentation instance
	intrusive_ptr<Presentation> presentation = new Presentation();


	//Load a sample PowerPoint document
	presentation->LoadFromFile(inputFile.c_str());

	//Get the second slide
	intrusive_ptr<ISlide> slide = presentation->GetSlides()->GetItem(1);

	//Get the notes slide from the second slide
	intrusive_ptr<NotesSlide> notesSlide = slide->GetNotesSlide();

	//Remove all the speaker notes from notes slide
	notesSlide->GetNotesTextFrame()->GetParagraphs()->Clear();

	//Remove a specific speak note from notes slide
	//notesSlide->GetNotesTextFrame()->GetParagraphs()->RemoveAt(1);

	//Save the result file
	presentation->SaveToFile(outputFile.c_str(), FileFormat::Pptx2013);
	presentation->Dispose();
}

C++: Add, Read or Delete Speaker Notes in PowerPoint

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.

page 86