Trích xuất Hình ảnh
The Documentize PDF Extractor for .NET plugin enables you to effortlessly extract images from PDF documents. It scans your PDF files, identifies embedded images, and extracts them while maintaining their original quality and format. This tool enhances the accessibility of visual content and streamlines the process of retrieving images from PDFs.
Cách trích xuất hình ảnh từ PDF
Để trích xuất hình ảnh từ một tệp PDF, làm theo các bước sau:
- Tạo một thể hiện của lớp
ExtractImagesOptions. - Thêm đường dẫn tệp đầu vào vào tùy chọn bằng phương thức
AddInput. - Đặt đường dẫn thư mục đầu ra cho các hình ảnh bằng phương thức
AddOutput. - Xử lý việc trích xuất hình ảnh bằng plugin.
- Lấy các hình ảnh đã trích xuất từ container kết quả.
1// Create ExtractImagesOptions to set instructions
2var options = new ExtractImagesOptions();
3// Add input file path
4options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
5// Set output Directory path
6options.AddOutput(new DirectoryDataSource("path_to_results_directory"));
7// Perform the process
8var results = PdfExtractor.Extract(options);
9// Get path to image result
10var imageExtracted = results.ResultCollection[0].ToFile();Trích xuất hình ảnh từ tệp PDF sang Stream mà không cần thư mục
The PdfExtractor plugin supports saving to streams, which allows you to extract images from PDF files into streams without using temporary folders.
1// Create ExtractImagesOptions to set instructions
2var options = new ExtractImagesOptions();
3// Add input file path
4options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
5// Not set output - it will write results to streams
6// Perform the process
7var results = PdfExtractor.Extract(options);
8// Get Stream
9var ms = results.ResultCollection[0].ToStream();
10// Copy data to file for demo
11ms.Seek(0, SeekOrigin.Begin);
12using (var fs = File.Create("test_file.png"))
13{
14 ms.CopyTo(fs);
15}Các tính năng chính:
- Extract Embedded Images: Identify and extract images from PDF documents.
- Preserve Image Quality: Ensures extracted images retain their original quality.
- Flexible Output: Save extracted images in your preferred format or location.