MS Excel Çalışma Kitabının PDF ye dönüştürülürken Harici Kaynakların Yüklenmesini Kontrol Etme
Olası Kullanım Senaryoları
Excel dosyanız harici kaynaklar içerebilir, örneğin bağlı resimler veya nesneler. Excel dosyanızı PDF’e dönüştürdüğünüzde, Aspose.Cells bu harici kaynakları alır ve bunları PDF’e dönüştürür. Ancak bazen bu harici kaynakları yüklemek istemeyebilirsiniz ve daha da önemlisi, bunları yönetmek isteyebilirsiniz. Bunun için PdfSaveOptions.StreamProvider kullanabilirsiniz ve IStreamProvider arayüzünü uygular.
MS Excel Çalışma Kitabında Harici Kaynakların Yüklenmesine Kontrol Etmek
Aşağıdaki örnek kod, harici kaynakların yüklenmesini kontrol etmek ve bunları manipüle etmek için PdfSaveOptions.StreamProvider nasıl kullanılacağını açıklar. Kod içinde kullanılan örnek Excel dosyasını ve kod tarafından üretilen çıktı PDF’sini kontrol edin. Ekran görüntüsü old external image(50528356.png) örnek Excel dosyasında nasıl yeni bir görüntü olan new image ile değiştirildiğini gösterir.
Örnek Kod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Implement IStreamProvider | |
class MyStreamProvider implements IStreamProvider { | |
public void closeStream(StreamProviderOptions options) throws Exception { | |
System.out.println("-----Close Stream-----"); | |
} | |
public void initStream(StreamProviderOptions options) throws Exception { | |
System.out.println("-----Init Stream-----"); | |
// Read the new image in a memory stream and assign it to Stream property | |
File imgFile = new File( srcDir + "newPdfSaveOptions_StreamProvider.png"); | |
byte[] bts = new byte[(int) imgFile.length()]; | |
FileInputStream fin = new FileInputStream(imgFile); | |
fin.read(bts); | |
fin.close(); | |
ByteArrayOutputStream baout = new ByteArrayOutputStream(); | |
baout.write(bts); | |
baout.close(); | |
options.setStream(baout); | |
} | |
}//MyStreamProvider | |
// ------------------------------------------------ | |
// ------------------------------------------------ | |
void Run() throws Exception { | |
// Load source Excel file containing external image | |
Workbook wb = new Workbook(srcDir + "samplePdfSaveOptions_StreamProvider.xlsx"); | |
// Specify Pdf Save Options - Stream Provider | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.setOnePagePerSheet(true); | |
opts.setStreamProvider(new MyStreamProvider()); | |
// Save the workbook to Pdf | |
wb.save(outDir + "outputPdfSaveOptions_StreamProvider.pdf", opts); | |
} |