Skip to content

Commit 1bf9421

Browse files
Updated files
1 parent 522355a commit 1bf9421

22 files changed

Lines changed: 1012 additions & 1272 deletions

File tree

  • content
    • chinese/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • czech/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • dutch/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • english/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • french/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • german/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • greek/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • hindi/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • hongkong/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • hungarian/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • indonesian/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • italian/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • japanese/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • korean/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • polish/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • portuguese/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • russian/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • spanish/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • swedish/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • thai/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • turkish/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion
    • vietnamese/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion

‎content/chinese/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion/_index.md‎

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ url: /zh/java/word-processing-formats/master-text-document-handling-java-groupdo
149149
weight: 1
150150
---
151151

152-
{{< blocks/products/pf/main-wrap-class >}}
153-
{{< blocks/products/pf/main-container >}}
154-
{{< blocks/products/pf/tutorial-page-section >}}
155-
156152
# 如何在 Java 中使用 GroupDocs.Conversion 将 txt 转换为 pdf
157153

158154
将纯文本文件转换为精美的 PDF 是在希望在所有设备上保持信息外观一致时的常见需求。在本教程中,您将学习如何在 Java 中使用强大的 GroupDocs.Conversion 库 **create pdf from txt**,处理自定义字符编码,并应用性能优化设置。完成后,您将能够将任何 `.txt`(无论是 UTF‑8、Shift_JIS 还是 ISO‑8859‑1)输入可靠的转换管道,输出可直接分享的 PDF。
@@ -231,11 +227,12 @@ Converter converter = new Converter();
231227
1. **导入必要的类**
232228
`TxtLoadOptions` 让您指定源文件的字符集。
233229

234-
```java
235-
// Definition anchor: TxtLoadOptions configures how a text file is read before conversion.
236-
TxtLoadOptions loadOptions = new TxtLoadOptions();
237-
```
238-
```java
230+
```java
231+
// Definition anchor: TxtLoadOptions configures how a text file is read before conversion.
232+
TxtLoadOptions loadOptions = new TxtLoadOptions();
233+
```
234+
235+
```java
239236
import com.groupdocs.conversion.License;
240237

241238
License license = new License();
@@ -245,23 +242,25 @@ license.setLicense("path/to/your/license.lic");
245242
2. **指定输入文件的路径**
246243
将 `YOUR_DOCUMENT_DIRECTORY` 替换为 `.txt` 文件的绝对路径。
247244

248-
```java
249-
String inputPath = "YOUR_DOCUMENT_DIRECTORY/sample.txt";
250-
```
251-
```java
252-
import com.groupdocs.conversion.options.load.TxtLoadOptions;
253-
import java.nio.charset.Charset;
254-
```
245+
```java
246+
String inputPath = "YOUR_DOCUMENT_DIRECTORY/sample.txt";
247+
```
248+
249+
```java
250+
import com.groupdocs.conversion.options.load.TxtLoadOptions;
251+
import java.nio.charset.Charset;
252+
```
255253

256254
3. **创建并配置 TxtLoadOptions**
257255
设置所需的编码,例如针对日本旧版文件的 Shift_JIS。
258256

259-
```java
260-
loadOptions.setEncoding("Shift_JIS"); // Change to "UTF-8" or other charset as needed
261-
```
262-
```java
263-
String txtFilePath = "YOUR_DOCUMENT_DIRECTORY/yourfile.txt"; // Input file path
264-
```
257+
```java
258+
loadOptions.setEncoding("Shift_JIS"); // Change to "UTF-8" or other charset as needed
259+
```
260+
261+
```java
262+
String txtFilePath = "YOUR_DOCUMENT_DIRECTORY/yourfile.txt"; // Input file path
263+
```
265264

266265
### Txt 文档转换
267266
文本文件正确加载后,转换为 PDF 只需一次方法调用。
@@ -273,36 +272,39 @@ license.setLicense("path/to/your/license.lic");
273272
1. **导入转换类**
274273
`PdfConvertOptions` 允许您微调 PDF 输出(例如页面大小、边距)。
275274

276-
```java
277-
// Definition anchor: PdfConvertOptions holds optional settings for PDF generation.
278-
PdfConvertOptions pdfOptions = new PdfConvertOptions();
279-
```
280-
```java
281-
TxtLoadOptions loadOptions = new TxtLoadOptions();
282-
loadOptions.setEncoding(Charset.forName("shift_jis"));
283-
```
275+
```java
276+
// Definition anchor: PdfConvertOptions holds optional settings for PDF generation.
277+
PdfConvertOptions pdfOptions = new PdfConvertOptions();
278+
```
279+
280+
```java
281+
TxtLoadOptions loadOptions = new TxtLoadOptions();
282+
loadOptions.setEncoding(Charset.forName("shift_jis"));
283+
```
284284

285285
2. **指定输出文件路径**
286286
调整 `YOUR_OUTPUT_DIRECTORY` 为您希望保存 PDF 的位置。
287287

288-
```java
289-
String outputPath = "YOUR_OUTPUT_DIRECTORY/sample.pdf";
290-
```
291-
```java
292-
import com.groupdocs.conversion.Converter;
293-
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
294-
```
288+
```java
289+
String outputPath = "YOUR_OUTPUT_DIRECTORY/sample.pdf";
290+
```
291+
292+
```java
293+
import com.groupdocs.conversion.Converter;
294+
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
295+
```
295296

296297
3. **初始化转换器并执行转换**
297298
传入 `TxtLoadOptions` 以确保在转换过程中应用正确的编码。
298299

299-
```java
300-
// Direct answer: Call converter.convert(inputPath, loadOptions, outputPath, pdfOptions) to produce the PDF.
301-
converter.convert(inputPath, loadOptions, outputPath, pdfOptions);
302-
```
303-
```java
304-
String convertedFile = "YOUR_OUTPUT_DIRECTORY/ConvertedFile.pdf"; // Output file path
305-
```
300+
```java
301+
// Direct answer: Call converter.convert(inputPath, loadOptions, outputPath, pdfOptions) to produce the PDF.
302+
converter.convert(inputPath, loadOptions, outputPath, pdfOptions);
303+
```
304+
305+
```java
306+
String convertedFile = "YOUR_OUTPUT_DIRECTORY/ConvertedFile.pdf"; // Output file path
307+
```
306308

307309
#### 故障排除提示
308310
- **Encoding mismatch** – 验证字符集字符串与文件实际编码匹配,否则字符会显示为 � 或乱码。
@@ -341,22 +343,8 @@ A: 可以,配置 `PdfConvertOptions`——您可以设置字体族、页面尺
341343
**Q: 在哪里可以找到更详细的示例和 API 文档?**
342344
A: 访问官方文档 [GroupDocs Documentation](https://docs.groupdocs.com/conversion/java/) 和专门的转换指南 [GroupDocs Conversion Java Docs](https://docs.groupdocs.com/conversion/java/)。完整的 API 参考请查看 [GroupDocs API Reference](https://reference.groupdocs.com/conversion/java/)。
343345

344-
```java
345-
Converter converter = new Converter(txtFilePath, () -> loadOptions);
346-
347-
PdfConvertOptions options = new PdfConvertOptions();
348-
converter.convert(convertedFile, options);
349-
```
350-
351346
## 相关教程
352347

353348
- [如何使用 GroupDocs.Conversion for Java 将文档的特定页面转换为 PDF](/conversion/java/pdf-conversion/convert-specific-pages-pdf-groupdocs-java/)
354349
- [隐藏修订痕迹 – GroupDocs.Conversion Java 文档转换选项教程](/conversion/java/conversion-options/)
355350
- [设置 GroupDocs Conversion Maven - 在 Java 中将 CSV 转换为 PDF – 步骤指南](/conversion/java/pdf-conversion/convert-csv-to-pdf-java-groupdocs-conversion-guide/)
356-
357-
{{< /blocks/products/pf/tutorial-page-section >}}
358-
359-
{{< /blocks/products/pf/main-container >}}
360-
{{< /blocks/products/pf/main-wrap-class >}}
361-
362-
{{< blocks/products/products-backtop-button >}}

‎content/czech/java/word-processing-formats/master-text-document-handling-java-groupdocs-conversion/_index.md‎

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ url: /cs/java/word-processing-formats/master-text-document-handling-java-groupdo
152152
weight: 1
153153
---
154154

155-
{{< blocks/products/pf/main-wrap-class >}}
156-
{{< blocks/products/pf/main-container >}}
157-
{{< blocks/products/pf/tutorial-page-section >}}
158-
159155
# Jak vytvořit PDF z TXT v Javě pomocí GroupDocs.Conversion
160156

161157
Převod souboru prostého textu do upraveného PDF je běžná potřeba, když chcete sdílet informace, které vypadají stejně na každém zařízení. V tomto tutoriálu se naučíte, jak **vytvořit PDF z TXT** v Javě pomocí robustní knihovny GroupDocs.Conversion, jak pracovat s vlastními kódováními znaků a jak použít výkonnostně optimalizovaná nastavení. Na konci budete schopni zpracovat libovolný soubor `.txt` — ať už UTF‑8, Shift_JIS nebo ISO‑8859‑1 — v spolehlivém konverzním potrubí, které výstupem poskytne připravené PDF ke sdílení.
@@ -234,11 +230,12 @@ Správné kódování zajišťuje, že každý znak — od latinských abece
234230
1. **Importujte potřebné třídy**
235231
`TxtLoadOptions` vám umožňuje specifikovat znakovou sadu zdrojového souboru.
236232

237-
```java
238-
// Definition anchor: TxtLoadOptions configures how a text file is read before conversion.
239-
TxtLoadOptions loadOptions = new TxtLoadOptions();
240-
```
241-
```java
233+
```java
234+
// Definition anchor: TxtLoadOptions configures how a text file is read before conversion.
235+
TxtLoadOptions loadOptions = new TxtLoadOptions();
236+
```
237+
238+
```java
242239
import com.groupdocs.conversion.License;
243240

244241
License license = new License();
@@ -248,23 +245,25 @@ license.setLicense("path/to/your/license.lic");
248245
2. **Zadejte cestu k vašemu vstupnímu souboru**
249246
Nahraďte `YOUR_DOCUMENT_DIRECTORY` absolutní cestou k vašemu souboru `.txt`.
250247

251-
```java
252-
String inputPath = "YOUR_DOCUMENT_DIRECTORY/sample.txt";
253-
```
254-
```java
255-
import com.groupdocs.conversion.options.load.TxtLoadOptions;
256-
import java.nio.charset.Charset;
257-
```
248+
```java
249+
String inputPath = "YOUR_DOCUMENT_DIRECTORY/sample.txt";
250+
```
251+
252+
```java
253+
import com.groupdocs.conversion.options.load.TxtLoadOptions;
254+
import java.nio.charset.Charset;
255+
```
258256

259257
3. **Vytvořte a nakonfigurujte TxtLoadOptions**
260258
Nastavte požadované kódování, například Shift_JIS pro starší japonské soubory.
261259

262-
```java
263-
loadOptions.setEncoding("Shift_JIS"); // Change to "UTF-8" or other charset as needed
264-
```
265-
```java
266-
String txtFilePath = "YOUR_DOCUMENT_DIRECTORY/yourfile.txt"; // Input file path
267-
```
260+
```java
261+
loadOptions.setEncoding("Shift_JIS"); // Change to "UTF-8" or other charset as needed
262+
```
263+
264+
```java
265+
String txtFilePath = "YOUR_DOCUMENT_DIRECTORY/yourfile.txt"; // Input file path
266+
```
268267

269268
### Konverze dokumentu Txt
270269
Po správném načtení textového souboru se konverze do PDF provede jedním voláním metody.
@@ -276,36 +275,39 @@ Konverze do PDF vytváří zařízení‑nezávislou reprezentaci, ideální pro
276275
1. **Importujte konverzní třídy**
277276
`PdfConvertOptions` vám umožňuje jemně doladit výstup PDF (např. velikost stránky, okraje).
278277

279-
```java
280-
// Definition anchor: PdfConvertOptions holds optional settings for PDF generation.
281-
PdfConvertOptions pdfOptions = new PdfConvertOptions();
282-
```
283-
```java
284-
TxtLoadOptions loadOptions = new TxtLoadOptions();
285-
loadOptions.setEncoding(Charset.forName("shift_jis"));
286-
```
278+
```java
279+
// Definition anchor: PdfConvertOptions holds optional settings for PDF generation.
280+
PdfConvertOptions pdfOptions = new PdfConvertOptions();
281+
```
282+
283+
```java
284+
TxtLoadOptions loadOptions = new TxtLoadOptions();
285+
loadOptions.setEncoding(Charset.forName("shift_jis"));
286+
```
287287

288288
2. **Zadejte cestu k výstupnímu souboru**
289289
Upravit `YOUR_OUTPUT_DIRECTORY` tak, aby ukazoval na místo, kam chcete PDF uložit.
290290

291-
```java
292-
String outputPath = "YOUR_OUTPUT_DIRECTORY/sample.pdf";
293-
```
294-
```java
295-
import com.groupdocs.conversion.Converter;
296-
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
297-
```
291+
```java
292+
String outputPath = "YOUR_OUTPUT_DIRECTORY/sample.pdf";
293+
```
294+
295+
```java
296+
import com.groupdocs.conversion.Converter;
297+
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
298+
```
298299

299300
3. **Inicializujte konvertor a proveďte konverzi**
300301
Předávejte `TxtLoadOptions`, aby bylo během konverze použito správné kódování.
301302

302-
```java
303-
// Direct answer: Call converter.convert(inputPath, loadOptions, outputPath, pdfOptions) to produce the PDF.
304-
converter.convert(inputPath, loadOptions, outputPath, pdfOptions);
305-
```
306-
```java
307-
String convertedFile = "YOUR_OUTPUT_DIRECTORY/ConvertedFile.pdf"; // Output file path
308-
```
303+
```java
304+
// Direct answer: Call converter.convert(inputPath, loadOptions, outputPath, pdfOptions) to produce the PDF.
305+
converter.convert(inputPath, loadOptions, outputPath, pdfOptions);
306+
```
307+
308+
```java
309+
String convertedFile = "YOUR_OUTPUT_DIRECTORY/ConvertedFile.pdf"; // Output file path
310+
```
309311

310312
#### Tipy pro řešení problémů
311313
- **Encoding mismatch** – Ověřte, že řetězec znakové sady odpovídá skutečnému kódování souboru; jinak se znaky zobrazí jako � nebo poškozený text.
@@ -344,22 +346,8 @@ A: Ano, nakonfigurujte `PdfConvertOptions` — můžete nastavit rodiny pís
344346
**Q: Kde najdu podrobnější příklady a API dokumentaci?**
345347
A: Navštivte oficiální dokumentaci na [GroupDocs Documentation](https://docs.groupdocs.com/conversion/java/) a věnovaný průvodce konverzí na [GroupDocs Conversion Java Docs](https://docs.groupdocs.com/conversion/java/). Prozkoumejte kompletní referenci API na [GroupDocs API Reference](https://reference.groupdocs.com/conversion/java/).
346348

347-
```java
348-
Converter converter = new Converter(txtFilePath, () -> loadOptions);
349-
350-
PdfConvertOptions options = new PdfConvertOptions();
351-
converter.convert(convertedFile, options);
352-
```
353-
354349
## Související tutoriály
355350

356351
- [Jak převést konkrétní stránky dokumentu do PDF pomocí GroupDocs.Conversion pro Javu](/conversion/java/pdf-conversion/convert-specific-pages-pdf-groupdocs-java/)
357352
- [Skrýt sledované změny – Tutoriály možností konverze dokumentů pro GroupDocs.Conversion Java](/conversion/java/conversion-options/)
358353
- [Nastavení GroupDocs Conversion Maven – Převod CSV do PDF v Javě – Krok za krokem](/conversion/java/pdf-conversion/convert-csv-to-pdf-java-groupdocs-conversion-guide/)
359-
360-
{{< /blocks/products/pf/tutorial-page-section >}}
361-
362-
{{< /blocks/products/pf/main-container >}}
363-
{{< /blocks/products/pf/main-wrap-class >}}
364-
365-
{{< blocks/products/products-backtop-button >}}

0 commit comments

Comments
 (0)