2012-11-01 83 views
1

當我運行此代碼時,我在文檔的頂部獲得了一個邊距。iText xmlWorker top margin

image

而且我對如何擺脫它不知道。我正在運行最新版本的iText和XMLWorker。

Document document = new Document(PageSize.A5.rotate(), 0f, 0f, 0f, 0f); 
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:/itext/test.pdf")); 
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null); 

htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory()); 

CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(false); 

cssResolver.addCss("p{color: #a00; font-size: 20pt; margin: 0; padding: 0;}", true); 

Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer))); 

XMLWorker worker = new XMLWorker(pipeline, true); 
XMLParser xmlParser = new XMLParser(worker); 

document.open(); 

String htmlData = "<html> <p>Lorem ipsum</p> </html>"; 

xmlParser.parse(new StringReader(htmlData)); 

document.close(); 

回答

2

的HTML <p>標籤通常具有上方和下方填充。如果您使用<div>標籤,也許您會得到您要查找的結果?