
Konversikan Word ke Markdown menggunakan Java
- Instalasi pustaka Java Docx
- Konversi Word ke Markdown menggunakan Java
- Konverter Word ke Markdown - opsi lanjutan
Instalasi perpustakaan Java Docx
Ini adalah library kaya fitur yang memungkinkan Anda membangun Word to Markdown converter tingkat perusahaan untuk aplikasi Java Anda. Namun, Anda dapat mengunduh API atau hanya menambahkan konfigurasi berikut di aplikasi Java berbasis Maven Anda.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>21.11</version>
<type>pom</type>
</dependency>
Konversikan Word ke Markdown menggunakan Java
Faktanya, ada banyak metode yang diekspos oleh library Java Docx ini untuk mengonversi dokumen Word ke format file dan gambar populer lainnya secara terprogram. Silakan ikuti langkah-langkah dan cuplikan kode yang disebutkan di bawah ini:
- Muat dokumen Word sumber dengan menginisialisasi konstruktor kelas Document.
- Simpan dokumen ke format Markdown dengan memanggil metode save.
Salin & tempel kode berikut ke file utama Anda:
This file contains 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
// Load a source Word document by initializing the constructor of the Document class. Document doc = new Document("sample.doc"); // Save the document to Markdown format by calling the save method. doc.save( "SaveDocx2Markdown.md");
Konverter Word ke Markdown - opsi lanjutan
Mari kita periksa beberapa fitur menonjol lainnya dari pustaka Java ini. Jadi, kami akan membuat dokumen dengan beberapa gaya dan menyimpannya ke Markdown: Langkah-langkahnya adalah:
- Buat objek dari kelas Document.
- Buat instance dari kelas DocumentBuilder untuk mempermudah penambahan konten ke dokumen.
- Tentukan gaya “Heading 1” untuk paragraf dengan memanggil metode insertParagraph.
- Panggil metode setStyleName untuk menyetel nama gaya paragraf yang diterapkan pada pemformatan ini.
- Masukkan string ke dalam dokumen pada posisi penyisipan saat ini dengan memanggil metode write.
- Buat format font menjadi miring dengan memanggil metode setItalic.
- Panggil metode insertHyperlink untuk menyisipkan hyperlink ke dalam dokumen.
- Aktifkan metode save untuk menyimpan dokumen Anda sebagai file Markdown.
This file contains 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
// Create an object of the Document class. Document doc = new Document(); // Instantiate an instance of the DocumentBuilder class to make it smooth to add content to the document. DocumentBuilder builder = new DocumentBuilder(doc); // Specify the "Heading 1" style for the paragraph by calling the insertParagraph method. builder.insertParagraph(); // Invoke the setStyleName method to set the name of the paragraph style applied to this formatting. builder.getParagraphFormat().setStyleName("Heading 1"); // Insert a string into the document at the current insert position by calling the write method. builder.write("Heading 1"); // Specify the Italic emphasis for the paragraph. builder.insertParagraph(); // Reset styles from the previous paragraph to not combine styles between paragraphs. builder.getParagraphFormat().setStyleName("Normal"); // Make the font format as italic by calling the setItalic method. builder.getFont().setItalic(true); builder.write("Italic Text"); // Reset styles from the previous paragraph to not combine styles between paragraphs. builder.setItalic(false); // Specify a Hyperlink for the desired text. builder.insertParagraph(); // Call the insertHyperlink method to insert a hyperlink into the document. builder.insertHyperlink("Aspose","https://www.aspose.com", false); builder.write("Aspose"); // Invoke the save method to save your document as a Markdown file. doc.save( "example.md");
Dapatkan Lisensi Gratis
Anda dapat memanfaatkan lisensi sementara gratis untuk mencoba API tanpa batasan evaluasi.
Menyimpulkan
Kami dapat mengakhiri tutorial ini di sini dengan harapan Anda telah mempelajari cara mengonversi Word ke Markdown menggunakan Java secara terprogram. Selain itu, Anda juga telah melalui beberapa metode lanjutan yang ditawarkan oleh library Java Docx ini. Selain itu, mohon jangan pergi tanpa mengunjungi dokumentasi perpustakaan ini. Selain itu, kami menyarankan Anda untuk mengikuti [Panduan Memulai] kami18. Terakhir, conholdate.com sedang menulis posting blog baru. Oleh karena itu, harap tetap berhubungan untuk pembaruan rutin.
Berikan pertanyaan
Anda dapat memberi tahu kami tentang pertanyaan atau pertanyaan Anda di forum kami.
FAQ
Bagaimana Anda membuat dokumen HTML dalam aplikasi .NET? Muat dokumen Word sumber dengan menginisialisasi konstruktor kelas Document. Kemudian, simpan dokumen ke format Markdown dengan memanggil metode save.