التحكم في تحميل الموارد الخارجية في مصنف MS Excel أثناء التقديم إلى PDF
Contents
[
Hide
]
سيناريوهات الاستخدام الممكنة
قد يحتوي ملف Excel الخاص بك على موارد خارجية مثل الصور أو الكائنات المرتبطة. عند تحويل ملف Excel إلى PDF ، يقوم Aspose.Cells باسترداد هذه الموارد الخارجية وتقديمها إلى PDF. لكن في بعض الأحيان ، لا تريد تحميل هذه الموارد الخارجية وأكثر من ذلك ، فأنت تريد التلاعب بها. يمكنك القيام بذلك باستخدامPdfSaveOptions.StreamProviderالذي ينفذIStreamProviderواجهه المستخدم.
التحكم في تحميل الموارد الخارجية في مصنف MS Excel أثناء التقديم إلى PDF
يشرح نموذج التعليمات البرمجية التالي كيفية الاستفادة منPdfSaveOptions.StreamProviderللتحكم في تحميل الموارد الخارجية والتلاعب بها. رجاء تاكد مننموذج لملف Excelالمستخدمة داخل الكود والإخراج PDFالتي تم إنشاؤها بواسطة الكود. اللقطة شاشةيوضح كيفالصورة الخارجية القديمةفي نموذج ملف Excel تم استبداله بامتدادصورة جديدةفي الإخراج PDF.
عينة من الرموز
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |