非ラテン文字を含む ITextRenderer を使用して PDF ドキュメントを生成しようとしています。私の場合、ここはブルガリア語です。
ITextRendererを呼び出す前に、いくつかのプロセス(tidyでの解析など)の後にそのように見える文字列コンテンツがあります(デバッグを通じてこの値を確認できます)
スティングの内容:
td class="description">Вид на потока</td>
td class="description">Статус на потока</td>
上記は私の文字列の一部です。このコンテンツには、有効な html 構文が含まれています。私はブルガリア語の文字を読むことができるので、この部分までは私のエンコーディングが正しいことを明確にするために、ここにそのほんの一部を入れました.
その後、ドキュメントを作成し、それをitextrendererに入れてpdfファイルを生成する次のコードが実行されます。英語のpdfファイルを正常に生成できたため、このコードはすでにテストされており、文字のコンテンツに対して機能しています。
非ラテン文字を使用して別の言語 (ブルガリア語) に切り替えると、問題が発生します。生成された PDF はすべてのブルガリア文字を無視し、最終結果は多くの空行を含む PDF になります。これは、pdfを生成するコードの一部です
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setNamespaceAware(false);
dbf.setFeature("http://xml.org/sax/features/namespaces", false);
dbf.setFeature("http://xml.org/sax/features/validation", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse(new ByteArrayInputStream(content.getBytes("UTF-8")));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
InputStream is = null;
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont("fonts/TIMES.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.getFontResolver().addFont("fonts/TIMESBD.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.getFontResolver().addFont("fonts/TIMESBI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.getFontResolver().addFont("fonts/TIMESI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.setDocument(doc, null);
renderer.layout();
renderer.createPDF(outputStream);
outputStream.close();
byte[] outputBytes = outputStream.toByteArray();
is = new ByteArrayInputStream(outputBytes);
response.setContentType("application");
response.addHeader("Content-Disposition", "attachment; filename=\"" + "exported.pdf" + "\"");
response.setContentLength(outputBytes.length);
response.getOutputStream().write(inputStreamToBytes(is));
いくつかのこと (主にエンコーディングに関連するもの) を試しましたが、残念ながらまだ解決策が見つかりません。おそらく、ここで明らかな何かが欠けています:)
これが何らかの価値をもたらすかどうかはわかりませんが、私は春を使用しており、このコードはコントローラー内で実行されます
どんな助けでも大歓迎です。
ありがとう