通过 C++ 以 PDF 格式制作邮票

使用 C++ 加盖印章 PDF 文档。使用 Aspose.PDF 以编程方式修改 PDF 文档

如何使用 C++ 庫將圖章添加到 PDF

為了在 PDF 檔案中處理圖章,我們將使用 Aspose.PDF for C++ API,這是一個功能豐富、強大且易於使用的文件操作 API,適用於 cpp 平台。開啟 NuGet 套件管理器,搜尋 Aspose.PDF 並安裝。您也可以在套件管理器控制台中使用下列命令。

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

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


您需要 Aspose.PDF for C++ 才能在您的環境中測試程式碼。

  1. 使用 Document 實例載入 PDF。
  2. 使用 Document.Info 屬性取得 DocumentInfo。
  3. 存取並顯示不同的 Document.Info 屬性。

將圖章添加到 PDF - C++


    String _dataDir("C:\\Samples\\");

    // String for input file name
    String inputFileName("AddTextStamp.pdf");
    String outputFileName("AddTextStamp_out.pdf");

    // 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);