In Word, a watermark is a semi-transparent text or image that you can place in the background. Typically, watermarks are used to emphasize something important about a document. For example, you can use it to remind the user that the content is confidential or a draft. Or other times, you may want to add a washout mark to include the company logo in the document. In this article, you will learn how to insert text or image watermarks to Word documents in C++ using Spire.Doc for C++.

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

Insert a Text Watermark to Word in C++

Spire.Doc for C++ offers the TextWatermark class to represent a text watermark. The content and appearance of the watermark can be set using the methods under it. Once a text watermark is created, you can apply it to the whole document by using Document->SetWatermark() method. The following are the detailed steps.

  • Create a Document object.
  • Load a Word file using Document->LoadFromFile() method.
  • Create a TextWatermark object.
  • Se the content and appearance of the watermark using the methods under the TextWatermark object.
  • Apply the text watermark to the document using Document->SetWatermrak() method.
  • Save the document using Document->SaveToFile() method.
  • C++
#include "Spire.Doc.o.h";

using namespace Spire::Doc;
using namespace std;

int main() {

    //Create a Document object
    intrusive_ptr<Document> document = new Document();

    //Load a Word file
    document->LoadFromFile(L"C:\\Users\\Administrator\\Desktop\\sample.docx");

    //Create a TextWatermark object
    intrusive_ptr<TextWatermark> txtWatermark = new TextWatermark();

    //Set the content and format of the text watermark
    txtWatermark->SetText(L"CONFIDENTIAL");
    txtWatermark->SetFontSize(40);
    txtWatermark->SetSemitransparent(90);
    txtWatermark->SetFontName(L"Arial Black");
    txtWatermark->SetColor(Color::GetBlue());
    txtWatermark->SetLayout(WatermarkLayout::Diagonal);

    //Apply the text watermark to the document
    document->SetWatermark(txtWatermark);

    //Save the document
    document->SaveToFile(L"Output/TextWatermark.docx", FileFormat::Docx2013);
    document->Close();
}

C++: Insert Text or Image Watermarks to Word

Insert an Image Watermark to Word in C++

Likewise, an image watermark can be created using PictureWatermark class. Once created, you can apply it to a Word document using Document->SetWatermark() method. Here are the detailed steps.

  • Create a Document object.
  • Load a Word file using Document->LoadFromFile() method.
  • Create a PictureWatermark object.
  • Set the image and appearance of the watermark using the methods under the PictureWatermark object.
  • Apply the image watermark to the document using Document->SetWatermrak() method.
  • Save the document using Document->SaveToFile() method.
  • C++
#include "Spire.Doc.o.h";

using namespace Spire::Doc;
using namespace std;

int main() {

    //Create a Document object
    intrusive_ptr<Document> document = new Document();

    //Load a Word file
    document->LoadFromFile(L"C:\\Users\\Administrator\\Desktop\\sample.docx");

    //Create a PictureWatermark object
    intrusive_ptr<PictureWatermark> pictureWatermark = new PictureWatermark();

    //Specify image for the watermark
    pictureWatermark->SetPicture(L"C:\\Users\\Administrator\\Desktop\\company-png.png");
    pictureWatermark->SetScaling(100);
    pictureWatermark->SetIsWashout(false);

    //Apply the image watermark to the document
    document->SetWatermark(pictureWatermark);

    //Save the document 
    document->SaveToFile(L"Output/ImageWatermark.docx", FileFormat::Docx2013);
    document->Close();
}

C++: Insert Text or Image Watermarks to Word

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 is a popular and widely used file format, but when it comes to giving presentations to others in meetings, classes or other scenarios, PowerPoint is always preferred over PDF files because it contains rich presentation effects that can better capture the attention of your audience. In this article, you will learn how to convert an existing PDF file to a PowerPoint presentation using Spire.PDF for Java.

Install Spire.PDF for Java

First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.pdf</artifactId>
        <version>12.6.4</version>
    </dependency>
</dependencies>

Convert PDF to PowerPoint Presentation in Java

From Version 9.2.1, Spire.PDF for Java supports converting PDF to PPTX using PdfDocument.saveToFile() method. With this method, each page of your PDF file will be converted to a single slide in PowerPoint. Below are the steps to convert a PDF file to an editable PowerPoint document.

  • Create a PdfDocument instance.
  • Load a sample PDF document using PdfDocument.loadFromFile() method.
  • Save the document as a PowerPoint document using PdfDocument.saveToFile(String filename, FileFormat.PPTX) method.
  • Java
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;

public class PDFtoPowerPoint {
    public static void main(String[] args) {

        //Create a PdfDocument instance
        PdfDocument pdfDocument = new PdfDocument();

        //Load a sample PDF document
        pdfDocument.loadFromFile("sample.pdf");

        //Convert PDF to PPTX document
        pdfDocument.saveToFile("PDFtoPowerPoint.pptx", FileFormat.PPTX);
    }
}

Java: Convert PDF to PowerPoint Presentation

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.

C++: Remove Paragraphs in Word

2023-03-28 01:06:57 Written by Administrator

While editing a Word document, there are numerous reasons to delete certain paragraphs in it. For example, it could be as simple as restructuring the document, or removing incorrect or irrelevant information to ensure document accuracy. In this article, you will learn how to programmatically remove paragraphs in a Word document using Spire.Doc for C++.

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

Remove All Paragraphs in a Word Document in C++

To remove all paragraphs, you need to loop through all sections in a document and then delete all paragraphs in each section using Section->GetParagraphs()->Clear() method. The following are the detailed steps.

  • Create a Document instance.
  • Load a Word document using Document->LoadFromFile() method.
  • Traverse through each section of the document and then remove all paragraphs in the section using Section->GetParagraphs()->Clear() method.
  • Save the result document using Document->SaveToFile() method.
  • C++
#include "Spire.Doc.o.h"

using namespace Spire::Doc;

int main() {
 //Specify the input and output file paths
 std::wstring inputFile = L"Data\\sample.docx";
 std::wstring outputFile = L"Output\\RemoveAllParagraphs.docx";

 //Create a Document instance
 intrusive_ptr<Document> document = new Document();

 //Load a Word document from disk
 document->LoadFromFile(inputFile.c_str());

 //Remove paragraphs from every section in the document
 for (int i = 0; i < document->GetSections()->GetCount(); i++)
 {
  intrusive_ptr<Section> section = document->GetSections()->GetItemInSectionCollection(i);
  section->GetParagraphs()->Clear();
 }

 //Save the result document
 document->SaveToFile(outputFile.c_str(), FileFormat::Docx2013);
 document->Close();
}

C++: Remove Paragraphs in Word

Remove a Specific Paragraph in a Word Document in C++

If you find a paragraph that contains duplicate or useless information, Spire.Doc for C++ allows you to delete the specified paragraph using Section->GetParagraphs()->RemoveAt() method. The following are the detailed steps.

  • Create a Document instance.
  • Load a Word document using Document->LoadFromFile() method.
  • Get a specified section of the document using Document->GetSections()->GetItem() method.
  • Remove a specified paragraph in the section using Section->GetParagraphs()->RemoveAt() method.
  • Save the result document using Document->SaveToFile() method.
  • C++
#include "Spire.Doc.o.h"

using namespace Spire::Doc;

int main() {
 //Specify the input and output file paths
 std::wstring inputFile = L"Data\\sample.docx";
 std::wstring outputFile = L"Output\\RemoveSpecificParagraph.docx";

 //Create a Document instance
 intrusive_ptr<Document> document = new Document();

 //Load a Word document from disk
 document->LoadFromFile(inputFile.c_str());

 //Get the first section of the document
 intrusive_ptr<Section> sec = document->GetSections()->GetItemInSectionCollection(0);

 //Remove the third paragraph in the section
 sec->GetParagraphs()->RemoveAt(2);

 //Save the result document
 document->SaveToFile(outputFile.c_str(), FileFormat::Docx2013);
 document->Close();
}

C++: Remove Paragraphs in Word

Remove Blank Paragraphs in a Word Document in C++

When there are many empty paragraphs/lines in a document, it quite necessary to remove them to improve readability. The following are the steps to remove all blank paragraphs/lines in a Word document.

  • Create a Document instance.
  • Load a Word document using Document->LoadFromFile() method.
  • Traverse through all paragraphs in the document and determine whether the paragraph is a blank paragraph.
  • Remove blank paragraphs from the document using section->GetBody()->GetChildObjects()->Remove() method.
  • Save the result document using Document->SaveToFile() method.
  • C++
#include "Spire.Doc.o.h"

using namespace Spire::Doc;

int main() {
 //Specify the input and output file paths
 std::wstring inputFile = L"Data\\Test.docx";
 std::wstring outputFile = L"Output\\RemoveEmptyLines.docx";

 //Create a Document instance
 intrusive_ptr<Document> document = new Document();

 //Load a Word document from disk
 document->LoadFromFile(inputFile.c_str());

 //Traverse each paragraph in the Word document
 for (int i = 0; i < document->GetSections()->GetCount(); i++)
 {
  intrusive_ptr<Section> section = document->GetSections()->GetItemInSectionCollection(i);

  for (int j = 0; j < section->GetBody()->GetChildObjects()->GetCount(); j++)
  {
   intrusive_ptr<DocumentObject> secChildObject = section->GetBody()->GetChildObjects()->GetItem(j);
   if (secChildObject->GetDocumentObjectType() == DocumentObjectType::Paragraph)
   {
    intrusive_ptr<Paragraph> para = Object::Dynamic_cast<Paragraph>(secChildObject);
    std::wstring paraText = para->GetText();

    //Determine if the paragraph is a blank paragraph
    if (paraText.empty())
    {
     //Remove blank paragraphs
     section->GetBody()->GetChildObjects()->Remove(secChildObject);
     j--;
    }
   }

  }
 }

 //Save the result document
 document->SaveToFile(outputFile.c_str(), FileFormat::Docx2013);
 document->Close();
}

C++: Remove Paragraphs in Word

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 93