通過C++添加文本圖章 PDF

使用 C++ API 建立帶有文本戳記.PDF。

如何使用 C++ 庫向 PDF 添加文本圖章

為了處理PDF檔中的文本圖章,我們將使用[Aspose.PDF for C++](https://products.aspose.com/pdf/cpp)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於 cpp 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

將文字圖章添加到 PDF 文件 C++


您需要 [Aspose.PDF for C++](https://releases.aspose.com/pdf/cpp) 才能在您的環境中嘗試代碼。

  1. 載入包含文件實例的 PDF。
  2. 使用文件對象打開 PDF 文件。
  3. 建立文字戳並定義其屬性。
  4. 使用添加時間戳方法將文字戳添加到頁面

將文字圖章加入到 PDF - C++。


    // Open document
    auto document = MakeObject<Document>(_dataDir + inputFileName);
    
    // Create text stamp
    auto textStamp =MakeObject<TextStamp>(u"Sample Stamp");

    // Set whether stamp is background
    textStamp->set_Background(true);
    // Set origin
    textStamp->set_XIndent(100);
    textStamp->set_YIndent(100);
    // Rotate stamp
    textStamp->set_Rotate(Rotation::on90);

    // Set text properties
    textStamp->get_TextState()->set_Font(FontRepository::FindFont(u"Arial"));
    textStamp->get_TextState()->set_FontSize(14.0F);
    textStamp->get_TextState()->set_FontStyle(FontStyles::Bold);
    textStamp->get_TextState()->set_FontStyle(FontStyles::Italic);
    textStamp->get_TextState()->set_ForegroundColor(Color::get_Green());
    // Add stamp to particular page
    document->get_Pages()->idx_get(1)->AddStamp(textStamp);

    // Save output document
    document->Save(_dataDir + outputFileName);