クイックスタート
クイックスタート
このページでは、PDF を開き、テキストを抽出し、ページをラスタ画像にレンダリングするための最小限のコードを、Document、TextAbsorber、およびデバイスクラスを使用して示します。
前提条件
例を実行する前に、完了してください Installation.
PDF を開き、テキストを抽出し、ページをレンダリングする
ドキュメントを開き、ページ数を表示し、Aspose::Pdf::Text::TextAbsorber で全テキストを抽出し、JpegDevice を使用してページ 1 を 150 DPI の JPEG にレンダリングします:
#include <aspose/pdf/document.hpp>
#include <aspose/pdf/page_collection.hpp>
#include <aspose/pdf/text_absorber.hpp>
#include <aspose/pdf/jpeg_device.hpp>
#include <aspose/pdf/resolution.hpp>
#include <fstream>
#include <iostream>
int main() {
Aspose::Pdf::Document doc("input.pdf");
std::cout << "Pages: " << doc.Pages().Count() << "\n";
Aspose::Pdf::Text::TextAbsorber absorber;
absorber.Visit(doc);
std::cout << absorber.Text() << "\n";
Aspose::Pdf::Devices::JpegDevice jpeg(Aspose::Pdf::Devices::Resolution(150));
std::ofstream out("page1.jpg", std::ios::binary);
jpeg.Process(doc.Pages()[1], out);
}TextAbsorber::Visit は、全体の Document または単一の Page のいずれかを受け取ります。{Device}::Process はページと出力ストリームを受け取ります — 同じパターンが BmpDevice と TiffDevice にも適用されます。
個々のテキストフラグメントを検索
Aspose::Pdf::Text::TextFragmentAbsorber は単一のフラット文字列ではなく、位置情報付きテキストフラグメントを返します。フラグメントごとの位置やカウントが必要な場合に便利です:
#include <aspose/pdf/document.hpp>
#include <aspose/pdf/text_fragment_absorber.hpp>
#include <iostream>
Aspose::Pdf::Document doc("input.pdf");
Aspose::Pdf::Text::TextFragmentAbsorber fragmentAbsorber;
fragmentAbsorber.Visit(doc);
std::cout << "Fragments: " << fragmentAbsorber.TextFragments().Count() << "\n";ドキュメントメタデータの読み取り
Document::Info() は標準の /Info 辞書エントリ用の型付きアクセサを備えた DocumentInfo を返します:
#include <aspose/pdf/document.hpp>
#include <aspose/pdf/document_info.hpp>
#include <iostream>
Aspose::Pdf::Document doc("input.pdf");
auto& info = doc.Info();
std::cout << "Title: " << info.Title() << "\n";
std::cout << "Author: " << info.Author() << "\n";次のステップ
- 開発者ガイド — レンダリング、暗号化、注釈、およびフォーム
- API Reference — 完全なクラスとメソッドの一覧
- KB 記事 — 特定のタスクに関するハウツーガイド