เริ่มต้นอย่างรวดเร็ว
เริ่มต้นอย่างรวดเร็ว
หน้านี้แสดงโค้ดขั้นต่ำเพื่อเปิด PDF, ดึงข้อความออก, และเรนเดอร์หน้าหนึ่งเป็นภาพเรสเตอร์โดยใช้ Document, TextAbsorber, และคลาสอุปกรณ์.
ข้อกำหนดเบื้องต้น
ก่อนรันตัวอย่าง ให้ทำให้เสร็จ Installation.
เปิด PDF, ดึงข้อความ, และเรนเดอร์หน้า
เปิดเอกสาร, พิมพ์จำนวนหน้าของมัน, ดึงข้อความทั้งหมดด้วย Aspose::Pdf::Text::TextAbsorber, และเรนเดอร์หน้า 1 เป็น JPEG ที่ 150 DPI ด้วย JpegDevice:
#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() คืนค่า DocumentInfo ที่มีตัวเข้าถึงที่กำหนดประเภทสำหรับรายการพจนานุกรมมาตรฐาน /Info:
#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 — คู่มือวิธีทำสำหรับงานเฉพาะ