PowerPoint প্রেজেন্টেশনের Properties বা বৈশিষ্ট্যগুলি যেমন টাইটেল, লেখক, বিষয়, কীওয়ার্ড, তৈরি এবং পরিবর্তনের তারিখ ইত্যাদি, প্রেজেন্টেশন ফাইলের মেটাডেটা হিসেবে সংরক্ষিত থাকে। Apache POI লাইব্রেরি ব্যবহার করে আপনি এই মেটাডেটা পড়তে এবং পরিবর্তন করতে পারবেন। এই বৈশিষ্ট্যগুলির মধ্যে সাধারণত Author, Title, Subject, Keywords, এবং Creation Date অন্তর্ভুক্ত থাকে।
এখানে আমরা দেখব কিভাবে Presentation Properties পড়া এবং সেট করা যায় Apache POI ব্যবহার করে।
PowerPoint প্রেজেন্টেশন ফাইলের Properties পড়ার জন্য, আপনি POI's XSLF API ব্যবহার করতে পারেন। নিচে একটি উদাহরণ দেওয়া হলো, যা PowerPoint ফাইলের মেটাডেটা যেমন Title, Author, Subject, এবং Keywords পড়তে দেখাবে।
প্রথমে, Apache POI-এর প্রয়োজনীয় ডিপেনডেন্সি আপনার Maven প্রোজেক্টে যুক্ত করুন:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version> <!-- উপযুক্ত ভার্সন -->
</dependency>
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.xmlbeans.XmlCursor;
import java.io.FileInputStream;
import java.io.IOException;
public class ReadPresentationProperties {
public static void main(String[] args) throws IOException {
// PowerPoint ফাইলটি পড়া
FileInputStream fis = new FileInputStream("presentation.pptx");
XMLSlideShow ppt = new XMLSlideShow(fis);
// মেটাডেটা পড়া
CoreProperties properties = ppt.getProperties().getCoreProperties();
// মেটাডেটার বিভিন্ন তথ্য এক্সট্র্যাক্ট করা
System.out.println("Title: " + properties.getTitle());
System.out.println("Author: " + properties.getCreator());
System.out.println("Subject: " + properties.getSubject());
System.out.println("Keywords: " + properties.getKeywords());
System.out.println("Created: " + properties.getCreated());
System.out.println("Last Modified: " + properties.getModified());
fis.close();
}
}
এই কোডে, CoreProperties অবজেক্টটি ব্যবহার করে আমরা PowerPoint ফাইলের মেটাডেটা (যেমন টাইটেল, লেখক, বিষয়, কীওয়ার্ড ইত্যাদি) পড়তে সক্ষম।
PowerPoint ফাইলের Properties পরিবর্তন করার জন্যও POI's XSLF API ব্যবহার করা যায়। আপনি যেমন Title, Author, Keywords ইত্যাদি সেট করতে পারবেন। নিচে উদাহরণ দেয়া হলো।
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import java.io.FileOutputStream;
import java.io.IOException;
public class SetPresentationProperties {
public static void main(String[] args) throws IOException {
// নতুন PowerPoint প্রেজেন্টেশন তৈরি
XMLSlideShow ppt = new XMLSlideShow();
// মেটাডেটা সেট করা
CoreProperties properties = ppt.getProperties().getCoreProperties();
properties.setTitle("New Presentation Title");
properties.setCreator("Your Name");
properties.setSubject("PowerPoint Metadata Example");
properties.setKeywords("Apache POI, PowerPoint, Metadata");
// PowerPoint ফাইলের কন্টেন্ট যোগ করা
XSLFSlide slide = ppt.createSlide();
XSLFTextBox title = slide.createTextBox();
title.setText("PowerPoint Presentation with Set Properties");
// ফাইল আউটপুট
try (FileOutputStream out = new FileOutputStream("presentation_with_properties.pptx")) {
ppt.write(out);
}
System.out.println("PowerPoint ফাইল তৈরি হয়েছে এবং মেটাডেটা সেট করা হয়েছে!");
}
}
এই কোডে, getCoreProperties()
মেথডটি ব্যবহার করে আমরা PowerPoint প্রেজেন্টেশনের মেটাডেটা (যেমন Title, Creator, Subject, Keywords) সেট করেছি।
PowerPoint প্রেজেন্টেশনের Creator (লেখক), Title (শিরোনাম), Subject (বিষয়) এবং Keywords (কীওয়ার্ড) পরিবর্তন করা খুবই সহজ:
properties.setTitle("New Presentation Title");
properties.setCreator("New Author");
properties.setSubject("Subject of the Presentation");
properties.setKeywords("Keyword1, Keyword2");
PowerPoint প্রেজেন্টেশনের Creation Date এবং Last Modified Date সাধারণত CoreProperties-এ সংরক্ষিত থাকে। আপনি এই ডেটা মান পরিবর্তন করতে পারেন, তবে এটি নির্ভর করে PowerPoint প্রেজেন্টেশন ফাইলের মেটাডেটা প্রোপার্টি সিস্টেমের উপরে।
properties.setCreated(new java.util.Date());
properties.setModified(new java.util.Date());
Apache POI ব্যবহার করে আপনি PowerPoint ফাইলের Properties বা মেটাডেটা যেমন Title, Author, Keywords, Subject, এবং Created/Modified Date পড়তে এবং সেট করতে পারেন। CoreProperties
ক্লাসটি ব্যবহার করে এই বৈশিষ্ট্যগুলির মান পরিবর্তন করা এবং পড়া যায়। তবে, আপনি প্রেজেন্টেশন ভিউ বা স্লাইড শো মোডের কাস্টমাইজেশন POI এর মাধ্যমে সরাসরি করতে পারবেন না।
common.read_more