PDFTable表格生成PDF


package com.xishui.action;

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.taglibs.standard.lang.jstl.EmptyOperator;

import com.itextpdf.text.Element;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class iTextTablePage1 {

public static void main(String[] args) {

Document document = new Document();
try {

PdfWriter.getInstance(
new FileOutputStream("c:\\iTextTablePage1.pdf"));

document.open();

float[] widths = { 1f };
PdfPTable table = new PdfPTable(widths);

table.setTotalWidth(800);// Total的高度,但不起作用j
PdfPCell cell = new PdfPCell(new Paragraph(
"Student Basic Data................\n\n"));

cell.setFixedHeight(75);// 设置第一个表的高度
table.setWidthPercentage(100);// 设置第一个表的宽度
document.add(table);
table.addCell(cell);
document.add(table);
document.add(new Paragraph("\n\n"));

// 第二个table开始
float[] widths2 = { 0.3f };
PdfPTable table2 = new PdfPTable(widths2);

PdfPCell cell2 = new PdfPCell(new Paragraph("SWOT Analysis\n\n\n"
+ "Strength:\n\n\n\n" + "IELTSWeakness:\n\n\n"
+ "Opportunity:\n\n\n" + "Threat:\n\n\n"
+ "Memo of the meeting:\n\n\n"));

cell2.setFixedHeight(588);// 设置第二个表格的高度

table2.setWidthPercentage(58);// 设置第二个表的宽度
document.add(table2);

document.add(table2);

table2.addCell(cell2);
document.add(table2);

// /
// 第三个测试开始

float[] widths3 = { 1f };
PdfPTable table3 = new PdfPTable(widths3);

PdfPCell cell3 = new PdfPCell(new Paragraph("SWOT Analysis\n\n\n"
+ "Strength:\n\n\n\n" + "IELTSWeakness:\n\n\n"
+ "Opportunity:\n\n\n" + "Threat:\n\n\n"
+ "Memo of the meeting:\n\n\n"));

cell3.setFixedHeight(80);// 设置第三个表格的高度

table3.setWidthPercentage(39);// 设置第三个表的宽度


table3.setHorizontalAlignment(Element.ALIGN_RIGHT); table3.addCell(cell3);
document.add(table3);
document.add(new Paragraph("\n\n"));
float[] widths4 = { 0.5f, 2f, 2f };
PdfPTable table4 = new PdfPTable(widths4);
PdfPCell cell4 = new PdfPCell(new Paragraph("Bath"));

table4.addCell("1");
table4.addCell("Accounting an ");
table4.addCell("City University");
table4.addCell("2");
table4.addCell("City University");
table4.addCell("City University");
table4.addCell("3");
table4.addCell("2.2");
table4.addCell("3.2");
table4.addCell("4");
table4.addCell("City University");
table4.addCell("City University");

table4.setHorizontalAlignment(Element.ALIGN_RIGHT);
table4.setWidths(widths4);
document.add(table4);


document.add(new Paragraph("\n\n"));
//

/* 第2页 */
PdfPTable tb1 = new PdfPTable(3);
cell = new PdfPCell(
new Paragraph(
"CASS Business School, City University - Quantitative Finance!(1)\n\n"));

cell.setColspan(3); // 设为几,就是几列,另加之前设置的表格数量
tb1.setWidthPercentage(100);
tb1.addCell(cell);// 此cell占用3个table

tb1.addCell("3.1\n\n");
tb1.addCell("3.2\n\n");
tb1.addCell("3.3\n\n");

cell = new PdfPCell(new Paragraph(
"profession describe (3) !!\n\n\n\n\n\n\n\n\n\n\n"));
cell.setColspan(3);
tb1.addCell(cell);
document.add(tb1);
document.add(new Paragraph("\n\n"));

PdfPTable tb2 = new PdfPTable(3);
cell = new PdfPCell(
new Paragraph(
"CASS Business School, City University - Quantitative Finance(2)\n\n"));

cell.setColspan(3); // 设为几,就是几列,另加之前设置的表格数量
tb2.setWidthPercentage(100);
tb2.addCell(cell);// 此cell占用3个table

tb2.addCell("2.1\n\n");
tb2.addCell("2.2\n\n");
tb2.addCell("2.3\n\n");

cell = new PdfPCell(new Paragraph(
"profession describe (2) \n\n\n\n\n\n\n\n\n\n\n"));
cell.setColspan(3);
tb2.addCell(cell);
document.add(tb2);
document.add(new Paragraph("\n\n"));

PdfPTable tb3 = new PdfPTable(3);
cell = new PdfPCell(
new Paragraph(
"CASS Business School, City University - Quantitative Finance!(3)\n\n"));

cell.setColspan(3); // 设为几,就是几列,另加之前设置的表格数量
tb3.setWidthPercentage(100);
tb3.addCell(cell);// 此cell占用3个table

tb3.addCell("3.1\n\n");
tb3.addCell("3.2\n\n");
tb3.addCell("3.3\n\n");

cell = new PdfPCell(new Paragraph(
"profession describe (3) !!\n\n\n\n\n\n\n\n\n\n\n"));
cell.setColspan(3);
tb3.addCell(cell);
document.add(tb3);
document.add(new Paragraph("\n\n"));


} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}

System.out.println("iTextTablePage1.pdf to c:\\");

document.close();

}
}


第二页

package com.xishui.action;

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

public class iTextTablePage2 {

public static void main(String[] args) {

Document document = new Document();
try {
PdfWriter.getInstance(
new FileOutputStream("c:\\iTextTable_Page_2.pdf"));

document.open();
document.add(new Paragraph("Potential programs for you")); // 小标题

PdfPTable table = new PdfPTable(3);
PdfPCell cell = new PdfPCell(
new Paragraph(
"CASS Business School, City University - Quantitative Finance(1)\n\n"));

cell.setColspan(3); // 设为几,就是几列,另加之前设置的表格数量
table.addCell(cell);// 此cell占用3个table

table.addCell("1.1\n\n");
table.addCell("2.1\n\n");
table.addCell("3.1\n\n");

cell = new PdfPCell(new Paragraph(
" profession describe (1) !!\n\n\n\n\n\n\n\n\n\n\n"));
cell.setColspan(3);
table.addCell(cell);
document.add(table);
document.add(new Paragraph("\n\n"));

PdfPTable tb2 = new PdfPTable(3);
cell = new PdfPCell(
new Paragraph(
"CASS Business School, City University - Quantitative Finance(2)\n\n"));

cell.setColspan(3); // 设为几,就是几列,另加之前设置的表格数量
tb2.addCell(cell);// 此cell占用3个table

tb2.addCell("2.1\n\n");
tb2.addCell("2.2\n\n");
tb2.addCell("2.3\n\n");

cell = new PdfPCell(new Paragraph(
"profession describe (2) \n\n\n\n\n\n\n\n\n\n\n"));
cell.setColspan(3);
tb2.addCell(cell);
document.add(tb2);
document.add(new Paragraph("\n\n"));

PdfPTable tb3 = new PdfPTable(3);
cell = new PdfPCell(
new Paragraph(
"CASS Business School, City University - Quantitative Finance!(3)\n\n"));

cell.setColspan(3); // 设为几,就是几列,另加之前设置的表格数量
tb3.addCell(cell);// 此cell占用3个table

tb3.addCell("3.1\n\n");
tb3.addCell("3.2\n\n");
tb3.addCell("3.3\n\n");

cell = new PdfPCell(new Paragraph(
"profession describe (3) !!\n\n\n\n\n\n\n\n\n\n\n"));
cell.setColspan(3);
tb3.addCell(cell);
document.add(tb3);
document.add(new Paragraph("\n\n"));


} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}

System.out.println("iTextTable_Page_2.pdf to c:\\");
// step 5: we close the document

document.close();

}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PDF表转换为Excel,CSV,XML或HTML 使用我们的API自动化。 将PDF表准确转换为Excel,CSV,XML和HTML。 :play_button:手动进行快速高效的复制粘贴或转录大型数据集非常耗时。 使用PDFTables释放数百小时的工作时间。 我们的处理器可以每秒转换多达12页,并立即将输出流回传输,从而为您提供快速的数据。 :play_button:Excel和API可轻松地将PDF在线转换为XLSX,CSV,XML或HTML。 如果您是编码员,请使用PDFTables Web API将其自动化。 :play_button:云和内部部署使用由Amazon Web Services支持的我们的网站,或在您自己的基础架构上安装我们的独立linux二进制文件。 :play_button:免费试用我们为所有访问我们网站的访客提供75个免费页面积分。 如果您需要更多,只需访问我们的定价页面即可充值。 千页起价为30美元。 :play_button:安全和私密所有交易均使用银行使用的相同技术进行端到端加密。 我们还可以签署保密协议。 :play_button:支持在英国的正常工作时间内,可以通过电子邮件或电话获得高级技术支持。 周一至周五上午9点至下午5点(格林尼治标准时间)。 :play_button:可扩展的PDFTables可以根据设计进行扩展,无论您是使用我们的基于云的还是本地的产品。 联系我们以获得个人报价。 :play_button:人造眼睛我们的算法就像您的眼睛一样,能够理解物品之间的间距。 它可以可靠地处理大量数据,从而为您提供最佳输出。 :play_button:数据隐私该服务安全地托管在其自己的虚拟私有云中的Amazon Web Services上。 在浏览器和使用HTTPS处理数据的服务器之间,所有交易都是端到端加密的,这与您与银行进行通信的技术相同。 我们数据中心内的交易也以相同的方式进行加密。 :play_button:数据保留我们将删除您已上传的所有数据,并且在72小时后将不保留其中的任何数据。 安装我们的扩展程序,即表示您同意PDFTables条款(pdftables.com/terms)和隐私政策(pdftables.com/privacy)。 支持语言:English (UK)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值