iTextには、XML(およびHTMLだと思います)からPDFを生成する機能があります。これがDTDですが、整理するのが難しいことがわかりました。それを除けば、何がサポートされているかについての良いドキュメントは見つかりませんでした。私のアプローチは、SAXiTextHandlerとElementTagsのソースを調べて、何が許容できるかを理解することでした。理想的ではありませんが、それはかなり簡単です。
<itext orientation="portrait" pagesize="LETTER" top="36" bottom="36" left="36" right="36" title="My Example" subject="My Subject" author="Me">
<paragraph size="8" >This is an example</paragraph>
</itext>
...
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.xml.SAXiTextHandler;
...
String inXml = ""; //use xml above as an example
ByteArrayOutputStream temp = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter writer = null;
try
{
writer = PdfWriter.getInstance(document, temp);
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(new ByteArrayInputStream(inXml), new SAXiTextHandler(document));
}
catch (Exception e)
{
// instead, catch the proper exception and do something meaningful
e.printStackTrace();
}
finally
{
if (writer != null)
{
try
{
writer.close();
}
catch (Exception ignore)
{
// ignore
}
} // if
}
//temp holds the PDF