|
4 | 4 | import org.springframework.boot.SpringApplication; |
5 | 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
6 | 6 |
|
| 7 | +import java.io.ByteArrayOutputStream; |
| 8 | +import java.nio.charset.StandardCharsets; |
| 9 | +import com.syncfusion.licensing.SyncfusionLicenseProvider; |
| 10 | +import com.syncfusion.docio.*; |
| 11 | + |
7 | 12 | @SpringBootApplication |
8 | 13 | public class DemoApplication { |
9 | 14 |
|
10 | 15 | @Value("${app.key}") |
11 | 16 | private static String licKey; |
12 | 17 |
|
13 | | - public static void main(String[] args) { |
14 | | - licKey = "1234567989"; |
15 | | - System.out.println("License Key: " + licKey); |
16 | | - System.out.println("Syncfusion"); |
| 18 | + public static void main(String[] args) throws Exception { |
| 19 | + |
| 20 | + SyncfusionLicenseProvider.registerLicense("GTIlMmhhZH1ifWdraGBifGJhfGpqampzYWBpZmppZmpoJTY9ODoTMTwrNTo/Nn06PQ=="); |
| 21 | + |
| 22 | + try (//Creates an instance of WordDocument Instance (Empty Word Document). |
| 23 | + WordDocument document = new WordDocument()) { |
| 24 | + document.ensureMinimal(); |
| 25 | + //Append text to the last paragraph of the document. |
| 26 | + document.getLastParagraph().appendText("Hello World"); |
| 27 | + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 28 | + document.save(byteArrayOutputStream, FormatType.Txt); |
| 29 | + // Read text from ByteArrayOutputStream |
| 30 | + String textFromStream = readTextFromStream(byteArrayOutputStream); |
| 31 | + // Print the extracted text |
| 32 | + System.out.println("Text read from ByteArrayOutputStream:"); |
| 33 | + System.out.println(textFromStream); |
| 34 | + } |
| 35 | + System.out.print("Completed"); |
17 | 36 | SpringApplication.run(DemoApplication.class, args); |
18 | 37 | } |
19 | | - |
| 38 | + //Helper method to read text from ByteArrayOutputStream |
| 39 | + private static String readTextFromStream(ByteArrayOutputStream byteArrayOutputStream) { |
| 40 | + // Convert the byte array to a String |
| 41 | + return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); |
| 42 | + } |
20 | 43 | } |
0 commit comments