本文整理汇总了Java中com.itextpdf.text.Document.setMargins方法的典型用法代码示例。如果您正苦于以下问题:Java Document.setMargins方法的具体用法?Java Document.setMargins怎么用?Java Document.setMargins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.itextpdf.text.Document
的用法示例。
在下文中一共展示了Document.setMargins方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testChangingMargins
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/38057241/itextpdf-different-margin-on-specific-page">
* itextpdf different margin on specific page
* </a>
* <p>
* This test shows how to set different margins to separate pages.
* </p>
*/
@Test
public void testChangingMargins() throws IOException, DocumentException
{
StringBuilder builder = new StringBuilder("test");
for (int i = 0; i < 100; i++)
builder.append(" test");
String test = builder.toString();
try ( OutputStream pdfStream = new FileOutputStream(new File(RESULT_FOLDER, "ChangingMargins.pdf")))
{
Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
PdfWriter.getInstance(pdfDocument, pdfStream);
pdfDocument.open();
for (int m = 0; m < pdfDocument.getPageSize().getWidth() / 2 && m < pdfDocument.getPageSize().getHeight() / 2; m += 100)
{
// pdfDocument.setMargins(m, m, 100, 100);
pdfDocument.setMargins(m, m, m, m);
pdfDocument.newPage();
pdfDocument.add(new Paragraph(test));
}
pdfDocument.close();
}
}
示例2: testCreateLandscapeDocument
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="https://stackoverflow.com/questions/47209312/i-have-a-trouble-with-lowagie-pdf-and-report-making-i-cant-include-headerfooter">
* I have a trouble with lowagie pdf and Report Making. I cant include headerfooter on the first page
* </a>
* <p>
* This example shows how to generate a PDF with page level
* settings (page size, page margins) customized already on
* the first page.
* </p>
*/
@Test
public void testCreateLandscapeDocument() throws FileNotFoundException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "landscape.pdf")));
document.setPageSize(PageSize.A4.rotate());
document.setMargins(60, 30, 30, 30);
document.open();
document.add(new Paragraph("Test string for a landscape PDF."));
document.close();
}
示例3: createPdf
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/43610868/how-to-add-dynamic-variable-to-footer-without-calling-document-newpage-in-itex">
* How to add dynamic variable to footer without calling document.newPage() in iText 5
* </a>
* <p>
* generator method of the OP
* </p>
* @see #testDynamicFooterLikeAyZagen()
*/
public static void createPdf(ArrayList<String> htmlStrings, FooterTable footerEvt, String destinationPath)
throws IOException, DocumentException {
Document document = new Document(PageSize.A4);
document.setMargins(68, 85, 75, 85);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(destinationPath));
if (footerEvt != null)
writer.setPageEvent(footerEvt);
document.open();
CSSResolver cssResolver = new StyleAttrCSSResolver();
CssFile cssFile = XMLWorkerHelper
.getCSS(new ByteArrayInputStream(/*readCSS("resources/content.min.css").getBytes()*/ "".getBytes()));
cssResolver.addCss(cssFile);
XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
fontProvider.register(/*"resources/ARIAL.TTF"*/ "c:/Windows/Fonts/arial.ttf");
CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
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);
int i = 0;
for (String htmlfile : htmlStrings) {
i++;
footerEvt.setTitleIndex("" + i);//or FooterTable.setTitleIndex("" + i);
ByteArrayInputStream stream = new ByteArrayInputStream(htmlfile.getBytes("UTF-8"));
p.parse(stream, Charset.forName("UTF-8"));
}
document.close();
}