当前位置: 首页>>代码示例>>Java>>正文


Java Document.setMargins方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:34,代码来源:ChangeMargins.java

示例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();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:23,代码来源:LandscapePdf.java

示例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();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:46,代码来源:DynamicFooter.java


注:本文中的com.itextpdf.text.Document.setMargins方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。