Xml解析和itext [英] Xml parsing and itext

查看:204
本文介绍了Xml解析和itext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否有可能改变字体,颜色,字体大小,而解析HTML到PDF使用xmlWorker.parser
目前,我能够解析我所给的任何输入。所以我想如果可能,更改字体,字体大小,字体颜色等。
谢谢

解决方案

您可以创建自己的 CSS 样式并将其添加到您的HTML代码。 CSS样式将根据下面给出的优先级来应用,其中优先级不高于4。
$ b 1)浏览器默认
2)外部样式表
)内部样式表
4)内联样式

示例:

$ pre code> document.open();
String finall =< style> h1 {color:orange;}< / style>< body>< h1>这是一个Demo< / h1>< / body>
InputStream is = new ByteArrayInputStream(finall.getBytes());
XMLWorkerHelper.getInstance()。parseXHtml(pdfWriter,document,is);
document.close();

在示例中,橙色将被设置为标题。

Just wanted to know if it is possible to change the font,color,font size while parsing html to pdf using xmlWorker.parser Currently I am able to parse whatever I have given as the input.So I wanted to change the font,font size, font color etc if possible. Thank you

解决方案

You can create your own CSS style and add it to your HTML code. The CSS style will be applied according the priority given below where no 4 is the higher priority.

1)Browser default 2)External style sheet 3)Internal style sheet 4)Inline style

Example:

document.open();
String finall=  "<style>h1{color:orange;} </style><body><h1>This is a Demo</h1></body>";
InputStream is = new ByteArrayInputStream(finall.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(pdfWriter,document, is);
document.close();

In the Example Orange color will be set to the header.

这篇关于Xml解析和itext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆