जावा के लिए Aspose.Words में लोड विकल्प का उपयोग करना

जावा के लिए Aspose.Words में लोड विकल्पों के साथ काम करने का परिचय

इस ट्यूटोरियल में, हम जानेंगे कि जावा के लिए Aspose.Words में लोड विकल्पों के साथ कैसे काम किया जाए। लोड विकल्प आपको दस्तावेज़ों को लोड करने और संसाधित करने के तरीके को अनुकूलित करने की अनुमति देते हैं। हम विभिन्न परिदृश्यों को कवर करेंगे, जिनमें गंदे फ़ील्ड को अपडेट करना, एन्क्रिप्टेड दस्तावेज़ों को लोड करना, आकृतियों को ऑफिस मैथ में परिवर्तित करना, एमएस वर्ड संस्करण सेट करना, एक अस्थायी फ़ोल्डर निर्दिष्ट करना, चेतावनियों को संभालना और मेटाफ़ाइल्स को पीएनजी में परिवर्तित करना शामिल है। आइए चरण दर चरण गोता लगाएँ।

डर्टी फील्ड्स को अपडेट करें

LoadOptions loadOptions = new LoadOptions();
loadOptions.setUpdateDirtyFields(true);

Document doc = new Document("Your Directory Path" + "Dirty field.docx", loadOptions);
doc.save("Your Directory Path" + "WorkingWithLoadOptions.UpdateDirtyFields.docx");

यह कोड स्निपेट दर्शाता है कि किसी दस्तावेज़ में गंदे फ़ील्ड को कैसे अपडेट किया जाए।setUpdateDirtyFields(true) यह सुनिश्चित करने के लिए विधि का उपयोग किया जाता है कि दस्तावेज़ लोडिंग के दौरान गंदे फ़ील्ड अपडेट किए जाते हैं।

एन्क्रिप्टेड दस्तावेज़ लोड करें

@Test
public void loadEncryptedDocument() throws Exception {
    Document doc = new Document("Your Directory Path" + "Encrypted.docx", new LoadOptions("docPassword"));
    doc.save("Your Directory Path" + "WorkingWithLoadOptions.LoadAndSaveEncryptedOdt.odt", new OdtSaveOptions("newPassword"));
}

यहां, हम पासवर्ड का उपयोग करके एक एन्क्रिप्टेड दस्तावेज़ लोड करते हैं।LoadOptions कंस्ट्रक्टर दस्तावेज़ पासवर्ड स्वीकार करता है, और आप दस्तावेज़ का उपयोग करते समय एक नया पासवर्ड भी निर्दिष्ट कर सकते हैंOdtSaveOptions.

आकार को कार्यालय गणित में बदलें

LoadOptions loadOptions = new LoadOptions();
loadOptions.setConvertShapeToOfficeMath(true);

Document doc = new Document("Your Directory Path" + "Office math.docx", loadOptions);
doc.save("Your Directory Path" + "WorkingWithLoadOptions.ConvertShapeToOfficeMath.docx", SaveFormat.DOCX);

यह कोड दर्शाता है कि दस्तावेज़ लोडिंग के दौरान आकृतियों को Office Math ऑब्जेक्ट में कैसे परिवर्तित किया जाए।setConvertShapeToOfficeMath(true)विधि इस रूपांतरण को सक्षम बनाती है।

एमएस वर्ड संस्करण सेट करें

@Test
public void setMsWordVersion() throws Exception {
    LoadOptions loadOptions = new LoadOptions();
    loadOptions.setMswVersion(MsWordVersion.WORD_2010);

    Document doc = new Document("Your Directory Path" + "Document.docx", loadOptions);
    doc.save("Your Directory Path" + "WorkingWithLoadOptions.SetMsWordVersion.docx");
}

आप दस्तावेज़ लोडिंग के लिए एमएस वर्ड संस्करण निर्दिष्ट कर सकते हैं। इस उदाहरण में, हमने संस्करण को Microsoft Word 2010 का उपयोग करके सेट किया हैsetMswVersion.

अस्थायी फ़ोल्डर का प्रयोग करें

@Test
public void useTempFolder() throws Exception {
    LoadOptions loadOptions = new LoadOptions();
    loadOptions.setTempFolder("Your Directory Path");

    Document doc = new Document("Your Directory Path" + "Document.docx", loadOptions);
}

का उपयोग करके अस्थायी फ़ोल्डर सेट करकेsetTempFolder, आप यह नियंत्रित कर सकते हैं कि दस्तावेज़ प्रसंस्करण के दौरान अस्थायी फ़ाइलें कहाँ संग्रहीत की जाती हैं।

चेतावनी कॉलबैक

@Test
public void warningCallback() throws Exception {
    LoadOptions loadOptions = new LoadOptions();
    loadOptions.setWarningCallback(new DocumentLoadingWarningCallback());

    Document doc = new Document("Your Directory Path" + "Document.docx", loadOptions);
}

public static class DocumentLoadingWarningCallback implements IWarningCallback {
    public void warning(WarningInfo info) {
        // दस्तावेज़ लोडिंग के दौरान चेतावनियाँ आने पर उन्हें संभालें।
        System.out.println(MessageFormat.format("WARNING: {0}, source: {1}", info.getWarningType(), info.getSource()));
        System.out.println(MessageFormat.format("\tDescription: {0}", info.getDescription()));
    }
}

यह कोड दर्शाता है कि दस्तावेज़ लोडिंग के दौरान चेतावनियों को संभालने के लिए चेतावनी कॉलबैक कैसे सेट अप करें। चेतावनियाँ आने पर आप अपने एप्लिकेशन के व्यवहार को अनुकूलित कर सकते हैं।

मेटाफ़ाइल्स को पीएनजी में कनवर्ट करें

@Test
public void convertMetafilesToPng() throws Exception {
    LoadOptions loadOptions = new LoadOptions();
    loadOptions.setConvertMetafilesToPng(true);

    Document doc = new Document("Your Directory Path" + "WMF with image.docx", loadOptions);
}

दस्तावेज़ लोडिंग के दौरान मेटाफ़ाइल्स (उदाहरण के लिए, डब्लूएमएफ) को पीएनजी छवियों में परिवर्तित करने के लिए, आप इसका उपयोग कर सकते हैंsetConvertMetafilesToPng(true) तरीका।

जावा के लिए Aspose.Words में लोड विकल्पों के साथ काम करने के लिए संपूर्ण स्रोत कोड

public void updateDirtyFields() throws Exception {
	LoadOptions loadOptions = new LoadOptions();
	{
		loadOptions.setUpdateDirtyFields(true);
	}
	Document doc = new Document("Your Directory Path" + "Dirty field.docx", loadOptions);
	doc.save("Your Directory Path" + "WorkingWithLoadOptions.UpdateDirtyFields.docx");
}
@Test
public void loadEncryptedDocument() throws Exception {
	Document doc = new Document("Your Directory Path" + "Encrypted.docx", new LoadOptions("docPassword"));
	doc.save("Your Directory Path" + "WorkingWithLoadOptions.LoadAndSaveEncryptedOdt.odt", new OdtSaveOptions("newPassword"));
}
@Test
public void convertShapeToOfficeMath() throws Exception {
	LoadOptions loadOptions = new LoadOptions();
	{
		loadOptions.setConvertShapeToOfficeMath(true);
	}
	Document doc = new Document("Your Directory Path" + "Office math.docx", loadOptions);
	doc.save("Your Directory Path" + "WorkingWithLoadOptions.ConvertShapeToOfficeMath.docx", SaveFormat.DOCX);
}
@Test
public void setMsWordVersion() throws Exception {
	// एक नया LoadOptions ऑब्जेक्ट बनाएं, जो डिफ़ॉल्ट रूप से MS Word 2019 विनिर्देश के अनुसार दस्तावेज़ लोड करेगा
	// और लोडिंग संस्करण को Microsoft Word 2010 में बदलें।
	LoadOptions loadOptions = new LoadOptions();
	{
		loadOptions.setMswVersion(MsWordVersion.WORD_2010);
	}
	Document doc = new Document("Your Directory Path" + "Document.docx", loadOptions);
	doc.save("Your Directory Path" + "WorkingWithLoadOptions.SetMsWordVersion.docx");
}
@Test
public void useTempFolder() throws Exception {
	LoadOptions loadOptions = new LoadOptions();
	{
		loadOptions.setTempFolder("Your Directory Path");
	}
	Document doc = new Document("Your Directory Path" + "Document.docx", loadOptions);
}
@Test
public void warningCallback() throws Exception {
	LoadOptions loadOptions = new LoadOptions();
	{
		loadOptions.setWarningCallback(new DocumentLoadingWarningCallback());
	}
	Document doc = new Document("Your Directory Path" + "Document.docx", loadOptions);
}
public static class DocumentLoadingWarningCallback implements IWarningCallback {
	public void warning(WarningInfo info) {
		//दस्तावेज़ लोडिंग के दौरान चेतावनियाँ और उनके विवरण प्रिंट होते हैं।
		System.out.println(MessageFormat.format("WARNING: {0}, source: {1}", info.getWarningType(), info.getSource()));
		System.out.println(MessageFormat.format("\tDescription: {0}", info.getDescription()));
	}
}
@Test
public void convertMetafilesToPng() throws Exception {
	LoadOptions loadOptions = new LoadOptions();
	{
		loadOptions.setConvertMetafilesToPng(true);
	}
	Document doc = new Document("Your Directory Path" + "WMF with image.docx", loadOptions);
}
@Test
public void loadChm() throws Exception {
	LoadOptions loadOptions = new LoadOptions();
	{
		loadOptions.setEncoding(Charset.forName("windows-1251"));
	}
	Document doc = new Document("Your Directory Path" + "HTML help.chm", loadOptions);
}

निष्कर्ष

इस ट्यूटोरियल में, हमने जावा के लिए Aspose.Words में लोड विकल्पों के साथ काम करने के विभिन्न पहलुओं पर विस्तार से चर्चा की है। लोड विकल्प दस्तावेज़ों को लोड करने और संसाधित करने के तरीके को अनुकूलित करने में महत्वपूर्ण भूमिका निभाते हैं, जिससे आप अपने दस्तावेज़ प्रसंस्करण को अपनी विशिष्ट आवश्यकताओं के अनुरूप बना सकते हैं। आइए इस गाइड में शामिल मुख्य बिंदुओं पर दोबारा गौर करें:

अक्सर पूछे जाने वाले प्रश्न

मैं दस्तावेज़ लोडिंग के दौरान चेतावनियों को कैसे संभाल सकता हूँ?

आप एक चेतावनी कॉलबैक सेट कर सकते हैं जैसा कि इसमें दिखाया गया हैwarningCallback() उपरोक्त विधि. अनुकूलित करेंDocumentLoadingWarningCallback आपके एप्लिकेशन की आवश्यकताओं के अनुसार चेतावनियों को संभालने के लिए क्लास।

क्या मैं दस्तावेज़ लोड करते समय आकृतियों को Office Math ऑब्जेक्ट में परिवर्तित कर सकता हूँ?

हाँ, आप इसका उपयोग करके आकृतियों को Office Math ऑब्जेक्ट में परिवर्तित कर सकते हैंloadOptions.setConvertShapeToOfficeMath(true).

मैं दस्तावेज़ लोडिंग के लिए एमएस वर्ड संस्करण कैसे निर्दिष्ट करूं?

उपयोगloadOptions.setMswVersion(MsWordVersion.WORD_2010) दस्तावेज़ लोडिंग के लिए एमएस वर्ड संस्करण निर्दिष्ट करने के लिए।

का उद्देश्य क्या हैsetTempFolder method in Load Options?

setTempFolderविधि आपको उस फ़ोल्डर को निर्दिष्ट करने की अनुमति देती है जहां दस्तावेज़ प्रसंस्करण के दौरान अस्थायी फ़ाइलें संग्रहीत की जाती हैं।