首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >iText -如果特定行位于页面底部,则在下一页中设置特定行。

iText -如果特定行位于页面底部,则在下一页中设置特定行。
EN

Stack Overflow用户
提问于 2015-10-17 06:31:05
回答 1查看 925关注 0票数 1

下面有一个工作代码。不幸的是,某些行(Title Row)有时可能位于页面底部,这在显示期间不太好。如果行位于页面底部,是否可以在下一页设置特定行?提前谢谢。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package eklinik;
import java.sql.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.List;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.itextpdf.text.BaseColor;
//import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.html.WebColors;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

import java.awt.Desktop;

public class itextTest{

public static void main(String[] args) {
    try {
        Document document = new Document();
        PdfWriter.getInstance(document,
                new FileOutputStream("Report.pdf"));
        document.open(); 

        PdfPTable table = new PdfPTable(6);
        table.getDefaultCell().setBorder(0);
        table.setWidths(new float[]{ 1.5f, 3, 3.5f, 3, 30, 3});
        PdfPCell cell;

        int i = 0;
        int x = 0;

        for (i = 01; i <= 22; i++){ // loop it 22 times to represent 22 chapter

            int chapter_num = x; //to get chapter number
            int description_num =x + 1; // to get chapter description
            x = x+2; //current number + 2 to skip to next chapter number & description
            //x++;


              //chapter row
              cell = new PdfPCell(new Phrase("cell1"));
              cell.setColspan(1);
              table.addCell(cell);
              cell = new PdfPCell(new Phrase("Title 1"));
              cell.setColspan(4);
              table.addCell(cell);
              cell = new PdfPCell(new Phrase("cell3"));
              cell.setColspan(1);
              table.addCell(cell);



                  //block row
                  cell = new PdfPCell(new Phrase(""));
                  //cell.setColspan(5);
                  cell.setBorder(Rectangle.NO_BORDER); 
                  table.addCell(cell);
                  cell = new PdfPCell(new Phrase("Title 2"));
                  cell.setColspan(6);
                  table.addCell(cell);



                      cell = new PdfPCell(new Phrase(""));
                      cell.setColspan(1);
                      cell.setBorder(Rectangle.NO_BORDER);
                      table.addCell(cell);
                      cell = new PdfPCell(new Phrase("cell4"));
                      cell.setColspan(1);
                      table.addCell(cell);
                      cell = new PdfPCell(new Phrase("cell5"));
                      cell.setColspan(3);
                      table.addCell(cell);
                      cell = new PdfPCell(new Phrase("cell6"));
                      cell.setColspan(1);
                      table.addCell(cell);


                      // code row
                      cell = new PdfPCell(new Phrase(""));
                      cell.setColspan(2);
                      cell.setBorder(Rectangle.NO_BORDER); 
                      table.addCell(cell);
                      cell = new PdfPCell(new Phrase("Title 3"));
                      cell.setColspan(4);
                      table.addCell(cell);



                          cell = new PdfPCell(new Phrase(""));
                          cell.setColspan(2);
                          cell.setBorder(Rectangle.NO_BORDER); 
                          table.addCell(cell);
                          cell = new PdfPCell(new Phrase("cell9"));
                          cell.setColspan(1);
                          table.addCell(cell);
                          cell = new PdfPCell(new Phrase("cell10"));
                          cell.setColspan(2);
                          table.addCell(cell);
                          cell = new PdfPCell(new Phrase("cell11"));
                          cell.setColspan(1);
                          table.addCell(cell);



        } // for loop end       

        table.setWidthPercentage(100);
        document.add(table);

        document.close();


    }
    catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());
    }





    }



}
EN

回答 1

Stack Overflow用户

发布于 2015-10-17 07:32:22

您可以使用table.keepRowsTogether()指定不希望分页的行:keepRowsTogether API

如果您希望将每个5行的“块”放在一起,那么将这些块创建为单独的子表并在每个子表上使用subtable.setKeepTogether(true)可能更容易一些。可以将子表添加到1个主表中,也可以将它们直接添加到文档中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33187733

复制
相关文章
python读取特定的行
fr = open(filename) for line in fr.readlines():     if line.startswith("#"):         continue     else:         ## do something with line          ## could use fr.readlines()[1:]  from second line import linecache content_list = linecache.getlines(filenam
py3study
2020/01/13
4K0
python-删除文件的特定行
有一次需要删除一些html文件中的统计链接, 通过用遍历文本的每行,然后正则查找网址,使用下面的函数删除行。
py3study
2020/01/07
4.3K0
R语言:以多列标准筛选特定行
在本期,我们会运用一个病例数据为大家进行讲解示范,这也是大猫课堂第一次针对阅读者提问进行的反馈,也希望大家能提供一些有趣的问题,来和我们一起分享,同时也感谢读者孤鹜惜秋,与我们分享其问题。话不多说,马上进入正题。
用户7652506
2020/08/12
2K0
R语言:以多列标准筛选特定行
如何在 Python 里优雅地读取文件特定行
如果文件非常大,不能读取到内存中,那么你可能会通过for 循环数行数,数到特定行:
青南
2019/09/16
2.3K0
SQL如何只让特定列中只显示一行数据
我们如果在某个表里面,如何让其中某列的其中一行数据,只是显示一次呢? 示例表 StudentID Last_Name First_Name Gender GradeLevel Class Pupil_Email Relationship Pupil_Parent_Email 5013 Wang Zack M Grade 9 Senior SG9 B 5013@example.com 爸爸 5013a@qq.com 5013 Wang Zack M Grade 9 Senior SG9 B 5013@exam
繁华是客
2023/03/03
8.8K0
WordPress 技巧:如何从 WordPress 页面菜单中移除特定页面
从 wp_list_pages() 中生成的页面菜单中移除特定的页面是非常简单的,只需要把下面代码加入到主题的 functions.php 文件中:
Denis
2023/04/15
1.9K0
Python-科学计算-pandas-11-df获取特定行或者列
系统:Windows 7 语言版本:Anaconda3-4.3.0.1-Windows-x86_64 编辑器:pycharm-community-2016.3.2 pandas:0.19.2
zishendianxia
2020/06/16
2.1K0
如何在 Vim 中转到特定行?这个操作一定得会!
Vim 是一个强大的编辑器,当你在 Vim 中高效地完成工作时,你会感觉比任何人都强。
网络技术联盟站
2022/05/24
1.6K0
如何在 Vim 中转到特定行?这个操作一定得会!
Exchange 禁止特定用户发往特定域名邮件
创建集线器传输规则 勾选来自用户、当收件人包含特定词语,输入@qq.com 操作选择删除邮件而不通知任何人 测试下发送情况,往QQ发送了个测试邮件,下面看看传递报告,可以看到发往QQ的邮件邮件被规则阻
李珣
2019/03/14
3.1K0
python中删除特定字符串
import re text = ‘wo,didi;wode,;wode’ text0 = text.replace(‘didi’, ”) print(re.sub(‘[,;]’, ‘ ‘, text0))
全栈程序员站长
2022/09/02
3.4K0
selenium之等待页面(或者特定元素)加载完成
文章目录 需求: 1、显示等待(推荐) 2、隐式等待(也不错) 3、time.sleep(一般不推荐) 需求: 有时候,我们使用selenium用来获取一些元素时,需要等待页面将某些元素加载网站才能够获取我们需要的数据,所以,这时候我们就需要等待页面的功能。
kirin
2021/03/18
5.3K0
Stylish样式如何设置为特定网址不生效?
因为Stylish不支持云端备份恢复,所以换成xStyle。但是xStyle并没有类似Stylish可以特殊设置的地方,所以只能在代码上进行处理了。
吴蛋蛋
2023/03/14
1K0
Stylish样式如何设置为特定网址不生效?
python删除特定文件
python删除特定文件 [Python]代码     #!/usr/bin/python # -*- coding: utf-8 -*- import os def del_files(path): for root , dirs, files in os.walk(path): for name in files: if name.endswith(".CR2"): os.remove(os.path.join(root,
用户7705674
2021/11/01
2.1K0
python删除特定文件
[Python]代码     #!/usr/bin/python # -*- coding: utf-8 -*- import os def del_files(path): for root , dirs, files in os.walk(path): for name in files: if name.endswith(".CR2"): os.remove(os.path.join(root, name))
用户7718188
2021/11/02
2.2K0
C++中如何获取终端输出的行数,C++清除终端输出特定的一行内容
单纯使用C++ 进行编程的时候,很多输出的调试信息都是直接在终端输出的,那么有的时候就会对终端输出的信息有一定的要求,那么如何进行定位终端输出的信息到底输出到了哪一行呢?如何清除特定的一行终端内容呢?
全栈程序员站长
2022/07/11
4.1K0
npm 中如何下载特定的组件版本
IMWeb前端团队
2018/01/08
4.3K0
npm 中如何下载特定的组件版本
ICCII中如何保持特定module的port
在进行后端设计时,为了使得最终的结果更加优化,也就是面积,功耗,性能更好,工具在优化时可能会把module的port改变。但是这样可能会带来一些问题。问题之一就是前端在进行仿真的时候,由于某些module port找不到了,很难找到需要监测的信号。
白山头
2020/09/15
2.6K0
三种方式设置特定设备UWP XAML view
开发者可以设置UWP特定设备xaml view,在桌面,手机,Iot,这个对于设置对不同设备的不同屏幕有用。我们可以使用RelativePanel,VisualStateTriggers,但是这样我们的xaml很大,我们在弄的时候觉得想修改一个东西会让我们把全部删了。 为了让我们可以在不同设备使用不同xaml view,我们可以有下面的方式:
林德熙
2022/08/04
3040
三种方式设置特定设备UWP XAML view
设置特定分类内容不在ZBLOG PHP首页显示方法
比如我们看到有很多的WordPress主题中是自带网站更新的首页可以让一些分类不显示在首页的,这个目的是希望让主页展示需要的内容。比如我们在用ZBLOG PHP做企业网站的时候,直接采用的是首页调用指定的分类内容,但是如果希望全品类调用的时候让某个分类不在首页显示,如何操作呢?
老蒋
2021/12/27
7010
自动生成特定组件
每一次的需求都需要在某个文件夹下面新建一个 pages 然后在创建组件,在创建对应的 scss 文件,而且比如需求的页面和之前类似,又得去 Ant Design Pro Component 复制对应的代码,然后今天在做需求时就想在项目内引用一个通过模版自动生成组件的小工具
离殊
2022/04/01
1.3K0
自动生成特定组件

相似问题

如何将DataGridView定位到特定行(以便所选行位于底部)?

20

在Shell中,删除行位于特定行之后

12

如果下一行包含特定字符串,则在新的文件行中添加字符串。

29

iText下一页pdf文档中的重复行

12

如果满足多个特定条件,则在熊猫中放置行

29
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文