私は誰かが私を助けることができるホッピングです...私は何をしようとしているようですが、かなりシンプルでなければなりませんが、私は今一日以上この事を戦っていて、 。私はStackOverflowとインターネットに関する多くの情報を見つけましたが、この問題を解決するのに役立つものは何もありません。フライングソーサーで@ font-face
core-renderer-R8と共にitext-2.0.8を使用して、埋め込みフォントでPDFを作成しようとしています。私は、有効なXHTMLからPDFを生成しようとしており、@ font-faceスタイルタグを使ってフォントを埋め込んでいます。私は@ font-faceタグがブラウザでファイルを開くことによってフォントを含んでいることを確認しました。そして、私はいつもTTFの関係をXHTML/CSSの文書と比べて保つように注意しています。
これを試してみるために、私は小さな「Hello World」タイプのプログラムを作成してフォントを埋め込みました。私は2つの別々のアプローチを取っており、どちらも望みの結果を生み出すことができません。私はこの小さなEclipseプログラムのコピーをhttp://christopherluft.com/FlyingSaucer.zip
に置いています。プログラムはどちらのインスタンスでもPDFを生成しますが、どちらのPDFも期待どおりに埋め込まれていません。 setDocumentでファイルを使用する最初の方法ではエラーは発生せず、フォントも生成されません。 2番目の方法ではPDFが生成されますが、デバッグ出力にjava.net.MalformedURLExceptionが表示されます。
私は様々なパスとURLの多数の順列を試しました。しかしながら、所望の結果が得られないものはない。私の疑問は、ITextRenderer.setDocumentについて何かを理解していないことです。しかし、私は実際の使用事例に特有の適切な文書を見つけるのに苦労しました。
私がしようとしています最初の方法は次のとおりです。
public static void main(String[] args) throws IOException, DocumentException {
System.getProperties().setProperty("xr.util-logging.loggingEnabled",
"true");
XRLog.setLoggingEnabled(true);
String inputFile = "sample.xhtml";
String url = new File(inputFile).toURI().toURL().toString();
String outputFile = "firstdoc.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
}
そして、私は(我々は我々のアプリでそれを使用する実際の方法に近いです)使用しています第2の方法は次のとおりです。
public static void main(String[] args) throws IOException, DocumentException {
System.getProperties().setProperty("xr.util-logging.loggingEnabled", "true");
XRLog.setLoggingEnabled(true);
String inputFile = "sample.xhtml";
String url = new File(inputFile).toURI().toURL().toString();
DocumentBuilder documentBuilder;
org.w3c.dom.Document xhtmlContent;
try
{
documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
documentBuilder.setEntityResolver(new XhtmlEntityResolver(new SuppressingEntityResolver()));
xhtmlContent = documentBuilder.parse(url);
System.out.println(url);
String outputFile = "firstdoc.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(xhtmlContent,".");
renderer.layout();
renderer.createPDF(os);
System.out.println("Finishing up....");
os.close();
}
catch (SAXException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ParserConfigurationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
XHTMLに@ font-faceを含めると、次のようになります。
今私はこれが本当に一般的な私はこれを働かせるために簡単な一歩を踏み出すことに失敗したと想像しています...問題は、私がこれにしばらく滞在していて、木々の中で森を見ることができないと思うことです。誰かが私に提供できる助けがあれば、大歓迎です。あなたの時間をありがとう。
Mavenでフォントが壊れていないことを確認してください。 http://stackoverflow.com/a/35367727/2420718 –