Hi Lee
What
does “no styles” actually mean? If it’s a font issue, one bug I’ve found
is if your font name is enclosed in quotes, i.e. ‘Century Gothic’, as
per the CSS standard, XMLworker will ignore it and use a built in font
(Arial, Helvetica), so simply remove the quotes. If the “style” issue is
something else, please be specific, or show your HTML / stylesheet.
Cheers
Dean
Dean McCarthy | Managing
Director
BCM
International Limited
PO
Box 302 392 | North
Harbour 0751| Auckland | New
Zealand
Building G|4
Orbit Drive |Albany 0632 | Auckland
|New Zealand
Mob
NZ: +64 21 677 966 |
Mob AU: +61 414 994 883
Tel: 0800
BCP PLAN (0800 227 7526) | Tel: +64 9
478 2188 | Fax: +64
9 478 2189
Email:
[email protected]
Web:
http://www.bcmi.co.nz
| http://www.bcmvault.com
P
Please consider the environment before printing this
e-mail
From: Lee Theobald
[mailto:[email protected]]
Sent: Thursday, 15 March 2012
1:03 a.m.
To: Post all your questions about iText here
Subject:
Re: [iText-questions] IText, XMLWorker & CSS
OK. Thanks again. I was trying that default resolver after
spotting it in the API but I'm still not having much luck (PDF's are
still being created with no styles). The HTML does use relative paths
for it's CSS files though so maybe I have the LinkProvider setup
incorrectly. I'll get a few tests going with simple HTML pages with
absolute links and see how it does.
Thanks for the help
Lee,
Op
14/03/2012 12:46, Lee Theobald schreef:
Thanks
for the info. That clears that part up. One more quick question on
this subject, the code your supplied will work when specifying the CSS
files myself but what if I want to use the ones included in the original
HTML (e.g. via <link> elements). Is this something XMLWorker
handles itself and if so, do you have any more guidance on this subject?
If there's a CSS mentioned in the file, then
it will get preference over the default CSS.
That makes things
simpler:
CSSResolver cssResolver =
XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
Note that
the true means that default.css (shipped with XML Worker) will be used
as basis.
If you don't want this, you can set the parameter to false.
I had a look through the mailing list archives and
a few questions said I should use flying saucer with iText but I'm
assuming this solution is a pre-XMLWorker one.
Flying
Saucer is a third party library that uses an old version of iText.
It
predates XML Worker.
We aren't responsible for Flying Saucer, so we
can't comment on its use.
------------------------------------------------------------------------------
Virtualization & Cloud Management Using
Capacity Planning
Cloud computing makes use of
virtualization - but cloud computing
also
focuses on allowing computing to be delivered as a service.
_______________________________________________
iText-questions mailing list
iText(R) is a
registered trademark of 1T3XT BVBA.
Thanks
for the info. That clears that part up. One more quick question on
this subject, the code your supplied will work when specifying the CSS
files myself but what if I want to use the ones included in the original
HTML (e.g. via <link> elements). Is this something XMLWorker
handles itself and if so, do you have any more guidance on this
subject? I had a look through the mailing list archives and a few
questions said I should use flying saucer with iText but I'm assuming
this solution is a pre-XMLWorker one.
Thanks again,
Lee
------------------------------------------------------------------------------
Virtualization
& Cloud Management Using Capacity Planning
Cloud computing makes
use of virtualization - but cloud computing
also focuses on
allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
We're
currently working on examples.
For instance:
//
step 1
Document document = new Document();
// step 2
PdfWriter writer =
PdfWriter.getInstance(document, new FileOutputStream(file));
writer.setInitialLeading(12.5f);
// step 3
document.open();
// step 4
XMLWorkerHelper helper = XMLWorkerHelper.getInstance();
//
CSS
CSSResolver cssResolver = new StyleAttrCSSResolver();
CssFile cssFile = helper.getCSS(new
FileInputStream("resources/demo2/walden.css"));
cssResolver.addCss(cssFile);
// HTML
XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider();
fontProvider.register("C:/windows/fonts/GARA.TTF");
fontProvider.register("C:/windows/fonts/GARAIT.TTF");
fontProvider.register("C:/windows/fonts/GARABD.TTF");
fontProvider.addFontSubstitute("lowagie", "garamond");
CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
// Pipelines
PdfWriterPipeline pdf = new
PdfWriterPipeline(document, writer);
HtmlPipeline html = new
HtmlPipeline(htmlContext, pdf);
CssResolverPipeline css = new
CssResolverPipeline(cssResolver, html);
XMLWorker worker = new XMLWorker(css, true);
XMLParser p =
new XMLParser(worker);
p.parse(new
FileInputStream("results/demo2/walden.html"));
//
step 5
document.close();
------------------------------------------------------------------------------
Virtualization
& Cloud Management Using Capacity Planning
Cloud computing makes
use of virtualization - but cloud computing
also focuses on
allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
Hi
all,
I'm having trying to use iText (v5.2) & the XMLWorker
(v1.1.2) tool to generate a PDF. Trouble is that the resulting PDF
doesn't appear to be using any of the CSS styles defined on the page.
Images are there but no CSS. I've followed the XMLWorker documentation
from http://demo.itextsupport.com/xmlworker/itextdoc/flatsite.html
but it's looking out of date with the current version. The main
problem at the moment at the moment is this line in the documentation:
HtmlPipelineContext
htmlContext = new HtmlPipelineContext();
With the versions I am
using, the constructor of HtmlPipelineContext requires a CssAppliers
class. I'm supplying a null object for now as I have no idea how to get
my hands on a CssAppliers class but could this be what is causing my
PDF to come out with no CSS styles applied? Does anyone have any idea
how I get my hands on a CssAppliers instance? The API docs didn't shed
much light on the situation.
Can anyone help me get past this
step? I've attempted to attach my test class so you can see what I'm
trying to do. No idea how attachments work with this mailing list
though...
Regards,
Lee
------------------------------------------------------------------------------
Virtualization
& Cloud Management Using Capacity Planning
Cloud computing makes
use of virtualization - but cloud computing
also focuses on
allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
OK. Thanks again. I was
trying that default resolver after spotting it in the API but I'm still
not having much luck (PDF's are still being created with no styles).
The HTML does use relative paths for it's CSS files though so maybe I
have the LinkProvider setup incorrectly. I'll get a few tests going
with simple HTML pages with absolute links and see how it does.
Thanks for the help
Lee,
------------------------------------------------------------------------------
Virtualization
& Cloud Management Using Capacity Planning
Cloud computing makes
use of virtualization - but cloud computing
also focuses on
allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
Op 14/03/2012 12:46, Lee Theobald schreef:
Thanks for the info. That clears that part up. One more quick
question on this subject, the code your supplied will work when
specifying the CSS files myself but what if I want to use the ones
included in the original HTML (e.g. via <link> elements).
Is this something XMLWorker handles itself and if so, do you have
any more guidance on this subject?
If there's a CSS mentioned in the file, then it will get preference
over the default CSS.
That makes things simpler:
CSSResolver cssResolver =
XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
Note that the true means that default.css (shipped with XML Worker)
will be used as basis.
If you don't want this, you can set the parameter to false.
I
had a look through the mailing list archives and a few questions
said I should use flying saucer with iText but I'm assuming this
solution is a pre-XMLWorker one.
Flying Saucer is a third party library that uses an old version of
iText.
It predates XML Worker.
We aren't responsible for Flying Saucer, so we can't comment on its
use.
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
Thanks for the info. That
clears that part up. One more quick question on this subject, the code
your supplied will work when specifying the CSS files myself but what
if I want to use the ones included in the original HTML (e.g. via
<link> elements). Is this something XMLWorker handles itself and
if so, do you have any more guidance on this subject? I had a look
through the mailing list archives and a few questions said I should use
flying saucer with iText but I'm assuming this solution is a
pre-XMLWorker one.
Thanks again,
Lee
------------------------------------------------------------------------------
Virtualization
& Cloud Management Using Capacity Planning
Cloud computing makes
use of virtualization - but cloud computing
also focuses on
allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
We're currently working on examples.
For instance:
// step 1
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream(file));
writer.setInitialLeading(12.5f);
// step 3
document.open();
// step 4
XMLWorkerHelper helper = XMLWorkerHelper.getInstance();
// CSS
CSSResolver cssResolver = new StyleAttrCSSResolver();
CssFile cssFile = helper.getCSS(new
FileInputStream("resources/demo2/walden.css"));
cssResolver.addCss(cssFile);
// HTML
XMLWorkerFontProvider fontProvider = new
XMLWorkerFontProvider();
fontProvider.register("C:/windows/fonts/GARA.TTF");
fontProvider.register("C:/windows/fonts/GARAIT.TTF");
fontProvider.register("C:/windows/fonts/GARABD.TTF");
fontProvider.addFontSubstitute("lowagie", "garamond");
CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
HtmlPipelineContext htmlContext = new
HtmlPipelineContext(cssAppliers);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
// Pipelines
PdfWriterPipeline pdf = new PdfWriterPipeline(document,
writer);
HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
CssResolverPipeline css = new
CssResolverPipeline(cssResolver, html);
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
p.parse(new FileInputStream("results/demo2/walden.html"));
// step 5
document.close();
------------------------------------------------------------------------------
Virtualization
& Cloud Management Using Capacity Planning
Cloud computing makes
use of virtualization - but cloud computing
also focuses on
allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/