Ayrıştırma verilerini PDF formatlarında kullanırken PDF dışındaki belgeleri değiştirmeye ihtiyaç duyulan birkaç durum vardır. Bu nedenle, bu tür uygulamalar için iki senaryo olacaktır: ya çözümlerine PDF ayrıştırma işlevselliğini eklerler ya da verileri desteklenen biçimler olarak değiştirmek için PDF dönüştürme işlevini eklerler. İkinci senaryo içinPDF’yi Word, Excel’e, HTML’ye, Görüntülere veya herhangi bir gerekli biçime dönüştürmek içinPHP okuyucu ve PDF kodunu Java tabanlı kod içinde uygulamak basittir. Burada birkaç vakayı tartışıyoruz, böylece programcılar bu dönüşüm kodu parçacıklarını gereksinimlerine göre değiştirebilirler.
PDF'den Microsoft Word'e Dönüştürme
// Include the required libraries
require_once ("java/Java.inc");
require_once ("lib/aspose.pdf.php");
// Import the necessary classes from the Aspose.PDF for Java library
use com\aspose\pdf\License;
use com\aspose\pdf\Document;
use com\aspose\pdf\DocSaveOptions;
use com\aspose\pdf\DocSaveOptions_DocFormat;
use com\aspose\pdf\DocSaveOptions_RecognitionMode;
// Set the license file for Aspose.PDF for Java
$license = "Aspose.PDF.PHPviaJava.lic";
$licenceObject = new License();
$licenceObject->setLicense($license);
// Set the input and output file paths
$dataDir = getcwd() . DIRECTORY_SEPARATOR . "samples";
$inputFile = $dataDir . DIRECTORY_SEPARATOR . "sample.pdf";
$outputFile = $dataDir . DIRECTORY_SEPARATOR . 'result-pdf-to-docx.docx';
// Load the PDF document
$document = new Document($inputFile);
// Create the save options for converting to DOCX format
$saveOption = new DocSaveOptions();
$saveOption->setMode(DocSaveOptions_RecognitionMode::$EnhancedFlow);
$saveOption->setFormat(DocSaveOptions_DocFormat::$DocX);
// Save the document in DOCX format
$document->save($outputFile, $saveOption);
PHP kütüphanesi için Aspose.PDF, tüm PDF’den Word’e dönüşümleri destekler. Microsoft Word belgelerini herhangi bir özel ayar olmadan dönüştürüyorsak, PDF dosyasını Document sınıfından Kaydet yöntemini kullanarak yükleriz ve çıktı Word belge yolu ve parametre olarak SaveFormat ile kullanırız. Çizgi mesafesini, görüntü çözünürlüğünü ve daha fazla ayarı geliştirmeye ihtiyaç duyulan özel durumlar için API, tüm bu ayarları ortaya çıkaran DocSaveOptions sınıfına sahiptir.
PDF'yi Excel Dosyaları Olarak Kaydet
// Include the required libraries
require_once ("java/Java.inc");
require_once ("lib/aspose.pdf.php");
// Import the necessary classes from the Aspose.PDF for Java library
use com\aspose\pdf\Document;
use com\aspose\pdf\ExcelSaveOptions;
use com\aspose\pdf\ExcelSaveOptions_ExcelFormat;
use com\aspose\pdf\License;
// Set the path to the Aspose.PDF license file
$license = "Aspose.PDF.PHPviaJava.lic";
// Create a new License object and set the license file
$licenceObject = new License();
$licenceObject->setLicense($license);
// Set the path to the input PDF file
$dataDir = getcwd() . DIRECTORY_SEPARATOR . "samples";
$inputFile = $dataDir . DIRECTORY_SEPARATOR . "sample.pdf";
// Set the path to the output Excel file
$outputFile = $dataDir . DIRECTORY_SEPARATOR . 'sample.xlsx';
// Create a new Document object and load the input PDF file
$document = new Document($inputFile);
// Create a new ExcelSaveOptions object
$saveOption = new ExcelSaveOptions();
// Set the output format to XLSX
$saveOption->setFormat(ExcelSaveOptions_ExcelFormat::$XLSX);
// Save the document as an Excel file using the specified save options
$document->save($outputFile, $saveOption);
Özelleştirilmiş SaveFormat.excel PDF’yi belirli Microsoft Excel XLS XLSX çıktı biçimlerine kaydetmek için numaralandırma kullanılabilir. Dahası, PHP/Java PDF Kütüphanesi ayrıca, yalnızca Excel formatlarına kaydetmekle kalmayıp aynı zamanda tam çıktı biçimi, çalışma sayfalarının sayısını en aza indirme ve daha fazlası gibi farklı nitelikleri ayarlamak için farklı işlevler ve özellikler sağlayan özel bir ExcelSaveOptions sınıfı sahiptir.
PDF'yi PowerPoint Sunumlarına Dönüştür
// Include the required Java and Aspose.PDF for PHP libraries
require_once ("java/Java.inc");
require_once ("lib/aspose.pdf.php");
// Import the necessary classes from the Aspose.PDF for PHP library
use com\aspose\pdf\Document;
use com\aspose\pdf\PptxSaveOptions;
use com\aspose\pdf\License;
// Set the path to the Aspose.PDF license file
$license = "Aspose.PDF.PHPviaJava.lic";
// Create a new License object and set the license file
$licenceObject = new License();
$licenceObject->setLicense($license);
// Set the path to the input PDF file
$dataDir = getcwd() . DIRECTORY_SEPARATOR . "samples";
$inputFile = $dataDir . DIRECTORY_SEPARATOR . "sample.pdf";
// Set the path to the output PPTX file
$outputFile = $dataDir . DIRECTORY_SEPARATOR . "results" . DIRECTORY_SEPARATOR . 'sample.pptx';
// Load the input PDF document
$document = new Document($inputFile);
// Create an instance of PptxSaveOptions
$saveOption = new PptxSaveOptions();
// Save the PDF document as a PPTX file
$document->save($outputFile, $saveOption);
PHP API, slaytları resim olarak oluşturarak PDF sayfalarını seçilebilir metin veya resimlerle PowerPoint Sunum Slaytlarına dönüştürmeyi destekler. Taşınabilir Belge Formatını PowerPoint’e kaydetme modeli neredeyse aynıdır, Document sınıfını kullanarak dosyayı yükleme ve ardından çıktı dosyası yolu ile Kaydet yöntemini ve parametre olarak saveFormat çağırır. Özel sunum seçenekleriyle oluşturma durumunda, Programcılar ilgili belirli oluşturma seçenekleriyle pptxSaveOptions sınıfı kullanabilir. Kaydet yöntemini çağırmak ve seçenekleri parametre olarak iletmek.
PDF'den HTML'ye Dönüştürme
// Include the required libraries
require_once ("java/Java.inc");
require_once ("lib/aspose.pdf.php");
// Import the necessary classes from the Aspose.PDF library
use com\aspose\pdf\Document;
use com\aspose\pdf\HtmlSaveOptions;
use com\aspose\pdf\License;
// Set the path to the license file
$licensePath = "Aspose.PDF.PHPviaJava.lic";
// Create a new License object and set the license using the provided file path
$license = new License();
$license->setLicense($licensePath);
// Set the path to the input PDF file
$dataDir = getcwd() . DIRECTORY_SEPARATOR . "samples";
$inputFile = $dataDir . DIRECTORY_SEPARATOR . "sample.pdf";
// Set the path to the output HTML file
$outputFile = $dataDir . DIRECTORY_SEPARATOR . 'pdf-to-html.html';
// Create a new Document object and load the input PDF file
$document = new Document($inputFile);
// Create a new HtmlSaveOptions object for saving the document as HTML
$saveOption = new HtmlSaveOptions();
// Save the document as HTML using the specified save options
$document->save($outputFile, $saveOption);
PDF Ayrıştırma Kitaplığı, PDF’yi bir bütün olarak HTML’ye ve görüntüler dahil gömülü kaynaklarla kaydetmeyi destekler. Dönüştürme prosedürü, kaynak belgenin yüklenmesi ve çıktı HTML dosyası yolu ve parametreler olarak SaveFormat.Html ile Kaydet yöntemini çağırması gibi genel durumlar için diğer biçimlere PDF ile aynıdır. Gömülü kaynaklarla kaydetme durumunda, dönüştürme sırasında görüntüleri belirli bir klasöre kaydetmek, elde edilen HTML’yi birden çok sayfaya bölmek ve daha fazlası gibi birden fazla seçeneğe sahip bir HTMLSaveOptions sınıfı vardır.
PDF'yi Resimlere Dönüştür
// Include the required libraries
require_once ("java/Java.inc");
require_once ("lib/aspose.pdf.php");
// Import the necessary classes from the Aspose.PDF for PHP via Java library
use com\aspose\pdf\Document;
use com\aspose\pdf\devices_Resolution;
use com\aspose\pdf\devices_JpegDevice;
use com\aspose\pdf\License;
// Create a License object and set the license file
$licenceObject = new License();
$licenceObject->setLicense("Aspose.PDF.PHPviaJava.lic");
// Set the path to the input PDF file
$dataDir = getcwd() . DIRECTORY_SEPARATOR . "samples";
$inputFile = $dataDir . DIRECTORY_SEPARATOR . "sample.pdf";
// Set the path and template for the output JPEG files
$imageFileNameTemplate = $dataDir . DIRECTORY_SEPARATOR . 'pdf-to-jpeg-';
// Open the target document
$document = new Document($inputFile);
$pages = $document->getPages();
$count = $pages->size();
// Create a Resolution object with a resolution of 300 dpi
$resolution = new devices_Resolution(300);
// Create a JpegDevice object with the specified resolution
$imageDevice = new devices_JpegDevice($resolution);
// Loop through each page of the document
for ($pageCount = 1; $pageCount <= $document->getPages()->size(); $pageCount++) {
// Convert a particular page and save the image to a file
$imageFileName = $imageFileNameTemplate . $pageCount . '.jpg';
$page = $document->getPages()->get_Item($pageCount);
$imageDevice->process($page, $imageFileName);
}
Aşağıda listelenen kod parçacıklarını kullanarak Java tabanlı uygulamalarda PDF sayfalarını PNG, JPEG, TIFF, BMP vb. gibi görüntülere dönüştürmek kolaydır. Geliştiriciler, dosyayı yükledikten sonra PDF sayfalarında döngü yapabilir ve Sayfa Sayfasını gerekli görüntü biçimine dönüştürebilir. Geliştiriciler, [Çözünürlük sınıfı] kullanarak görüntülerin yatay ve dikey çözünürlüğünü ayarlayabilir (https://apireference.aspose.com/pdf/php-java/aspose.pdf.devices/resolution)