本文整理汇总了Java中com.itextpdf.text.Document类的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Document类属于com.itextpdf.text包,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPDF
import com.itextpdf.text.Document; //导入依赖的package包/类
public void createPDF(String outputFile, ArrayList<Question> qlist, boolean showCorrectAnswer,
PageCounter pagecounter, int maximumPageNumber, String inputFolder) throws DocumentException, IOException
{
_inputFolder = inputFolder;
Document document = new Document(PageSize.A4, 50, 50, 70, 50);
PdfWriter pdfwriter = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
pdfwriter.setBoxSize("art", new Rectangle(36, 54, 559, 788));
pdfwriter.setPageEvent(new HeaderFooter(maximumPageNumber));
if (pagecounter != null)
{
pdfwriter.setPageEvent(pagecounter);
}
document.open();
Paragraph p = new Paragraph();
// p.setSpacingBefore(SPACING);
p.setSpacingAfter(SPACING);
p.setIndentationLeft(INDENTATION);
writeQuestions(p, document, showCorrectAnswer, qlist);
document.close();
}
示例2: renderMergedOutputModel
import com.itextpdf.text.Document; //导入依赖的package包/类
@Override
protected void renderMergedOutputModel(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// IE workaround: write into byte array first.
ByteArrayOutputStream baos = createTemporaryOutputStream();
// Apply preferences and build metadata.
Document document = newDocument();
PdfWriter writer = newWriter(document, baos);
prepareWriter(model, writer, request);
buildPdfMetadata(model, document, request);
// Build PDF document.
document.open();
buildPdfDocument(model, document, writer, request, response);
document.close();
// Flush to HTTP response.
writeToResponse(response, baos);
}
示例3: addMetaData
import com.itextpdf.text.Document; //导入依赖的package包/类
private static void addMetaData(Document document) {
document.addTitle("My first PDF");
document.addSubject("Using iText");
document.addKeywords("Java, PDF, iText");
document.addAuthor("Lars Vogel");
document.addCreator("Lars Vogel");
}
示例4: addTitlePage
import com.itextpdf.text.Document; //导入依赖的package包/类
private static void addTitlePage(Document document,Resolucion res)
throws DocumentException {
Paragraph preface = new Paragraph();
// We add one empty line
addEmptyLine(preface, 1);
// Lets write a big header
preface.add(new Paragraph("Consejo Profesional de Informatica de Santiago del Estero", catFont));
addEmptyLine(preface, 1);
// Will create: Report generated by: _name, _date
preface.add(new Paragraph( "Comision Directiva del Consejo, " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
smallBold));
addEmptyLine(preface, 2);
preface.add(new Paragraph("Resolucion N°"+res.getNumero_resolucion()+"",
smallBold));
addEmptyLine(preface, 3);
preface.add(new Paragraph("Esta Resolucion de tipo "+res.getTipo()+" formulada para notificar al socio con legajo: "+res.getLegajo_socio()+" de su actual estado como socio del Consejo.\n"
+ res.getDescripcion_solicitud()+" "+res.getDescripcion_resolucion()+" en la fecha "+res.getFecha(),
cuerpo));
document.add(preface);
// Start a new page
document.newPage();
}
示例5: print
import com.itextpdf.text.Document; //导入依赖的package包/类
public void print(String plot_pdf) {
try {
float width = jframe.getSize().width,
height = jframe.getSize().height;
Document document = new Document(new Rectangle(width, height));
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
document.open();
PdfContentByte canvas = writer.getDirectContent();
PdfTemplate template = canvas.createTemplate(width, height);
Graphics2D g2d = new PdfGraphics2D(template, width, height);
jframe.paint(g2d);
g2d.dispose();
canvas.addTemplate(template, 0, 0);
document.close();
} catch (FileNotFoundException | DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例6: showBlank
import com.itextpdf.text.Document; //导入依赖的package包/类
/** Shows a blank document, in case of a problem in generating the PDF */
private byte[] showBlank() throws DocumentException {
final Document document = new Document(PageSize.LETTER); // FIXME - get PageSize from label definition
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("No data have been uploaded. The time is: " + new Date()));
final Barcode128 code128 = new Barcode128();
code128.setGenerateChecksum(true);
code128.setCode(new Date().toString());
document.add(code128.createImageWithBarcode(writer.getDirectContent(), null, null));
document.close();
return baos.toByteArray();
}
示例7: testRotateAndZoomUpperHalfPage
import com.itextpdf.text.Document; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/35374110/how-do-i-use-itext-to-have-a-landscaped-pdf-on-half-of-a-a4-back-to-portrait-and">
* How do i use iText to have a landscaped PDF on half of a A4 back to portrait and full size on A4
* </a>
* <p>
* This sample shows how to rotate and enlarge the upper half of an A4 page to fit into a new A4 page.
* </p>
*/
@Test
public void testRotateAndZoomUpperHalfPage() throws IOException, DocumentException
{
try ( InputStream resource = getClass().getResourceAsStream("/mkl/testarea/itext5/extract/test.pdf");
OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "test-upperHalf.pdf")) )
{
PdfReader reader = new PdfReader(resource);
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, result);
document.open();
double sqrt2 = Math.sqrt(2);
Rectangle pageSize = reader.getPageSize(1);
PdfImportedPage importedPage = writer.getImportedPage(reader, 1);
writer.getDirectContent().addTemplate(importedPage, 0, sqrt2, -sqrt2, 0, pageSize.getTop() * sqrt2, -pageSize.getLeft() * sqrt2);
document.close();
}
}
示例8: createMultiUseIndirectTextPdf
import com.itextpdf.text.Document; //导入依赖的package包/类
static byte[] createMultiUseIndirectTextPdf() throws DocumentException, IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
PdfReader reader = new PdfReader(createSimpleTextPdf());
PdfImportedPage template = writer.getImportedPage(reader, 1);
Rectangle pageSize = reader.getPageSize(1);
writer.getDirectContent().addTemplate(template, 0, .7f, -.7f, 0, pageSize.getRight(), (pageSize.getTop() + pageSize.getBottom()) / 2);
writer.getDirectContent().addTemplate(template, 0, .7f, -.7f, 0, pageSize.getRight(), pageSize.getBottom());
document.newPage();
writer.getDirectContent().addTemplate(template, pageSize.getLeft(), pageSize.getBottom());
document.close();
return baos.toByteArray();
}
示例9: onEndPage
import com.itextpdf.text.Document; //导入依赖的package包/类
@Override
public void onEndPage(PdfWriter writer, Document document) {
List<Page> pages=report.getPages();
int pageNumber=writer.getPageNumber();
if(pageNumber>pages.size()){
return;
}
Page page=pages.get(pageNumber-1);
HeaderFooter header=page.getHeader();
HeaderFooter footer=page.getFooter();
if(header!=null){
buildTable(writer,header,true,report);
}
if(footer!=null){
buildTable(writer,footer,false,report);
}
}
示例10: extractBlogInfo
import com.itextpdf.text.Document; //导入依赖的package包/类
/**
* 根据URL提前blog的基本信息,返回结果>>:[主题 ,分类,日期,内容]等.
*
* @param blogURL
* @return
* @throws Exception
*/
public static String[] extractBlogInfo(String blogURL) throws Exception {
String[] info = new String[4];
org.jsoup.nodes.Document doc = Jsoup.connect(blogURL).get();
org.jsoup.nodes.Element e_title = doc.select("h2.title").first();
info[0] = e_title.text();
org.jsoup.nodes.Element e_category = doc.select("a[rel=category tag]")
.first();
info[1] = e_category.attr("href").replace("http://www.micmiu.com/", "");
org.jsoup.nodes.Element e_date = doc.select("span.post-info-date")
.first();
String dateStr = e_date.text().split("日期")[1].trim();
info[2] = dateStr;
org.jsoup.nodes.Element entry = doc.select("div.entry").first();
info[3] = formatContentTag(entry);
return info;
}
示例11: writeSimplePdf
import com.itextpdf.text.Document; //导入依赖的package包/类
public static void writeSimplePdf() throws Exception{
//1.新建document对象
//第一个参数是页面大小。接下来的参数分别是左、右、上和下页边距。
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
//2.建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
//创建 PdfWriter 对象 第一个参数是对文档对象的引用,第二个参数是文件的实际名称,在该名称中还会给出其输出路径。
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\Documents\\ITextTest.pdf"));
//3.打开文档
document.open();
//4.向文档中添加内容
//通过 com.lowagie.text.Paragraph 来添加文本。可以用文本及其默认的字体、颜色、大小等等设置来创建一个默认段落
BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(bfChinese, 22, Font.BOLD, BaseColor.BLACK);
document.add(new Paragraph("sdfsdfsd全是中文显示了没.fsdfsfs",fontChinese));
document.add(new Paragraph("Some more text on the first page with different color and font type.",
FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new BaseColor(255, 150, 200))));
Paragraph pragraph=new Paragraph("你这里有中亠好", fontChinese);
document.add(pragraph);
//图像支持格式 GIF, Jpeg, PNG, wmf
Image gif = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
gif.setBorder(5);
gif.scaleAbsolute(30,30);
gif.setAlignment(Image.RIGHT|Image.TEXTWRAP);
document.add(gif);
Paragraph pragraph11=new Paragraph("你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好", fontChinese);
document.add(pragraph11);
Image gif15 = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
// gif15.setBorder(50);
gif15.setBorder(Image.BOX);
gif15.setBorderColor(BaseColor.RED);
// gif15.setBorderColorBottom(borderColorBottom)
gif15.setBorderWidth(1);
gif15.scalePercent(50);
document.add(gif15);
//5.关闭文档
document.close();
}
示例12: onEndPage
import com.itextpdf.text.Document; //导入依赖的package包/类
/**
* Adds a header to every page
* @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
* com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
*/
public void onEndPage(PdfWriter writer, Document document) {
PdfPTable table = new PdfPTable(3);
try {
table.setWidths(new int[]{40,5,10});
table.setTotalWidth(100);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
Font font=new Font(chineseFont,8);
font.setColor(new BaseColor(55,55,55));
Paragraph paragraph=new Paragraph("第 "+writer.getPageNumber()+" 页 共",font);
paragraph.setAlignment(Element.ALIGN_RIGHT);
table.addCell(paragraph);
Image img=Image.getInstance(total);
img.scaleAbsolute(28, 28);
PdfPCell cell = new PdfPCell(img);
cell.setBorder(Rectangle.NO_BORDER);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
PdfPCell c = new PdfPCell(new Paragraph("页",font));
c.setHorizontalAlignment(Element.ALIGN_LEFT);
c.setBorder(Rectangle.NO_BORDER);
table.addCell(c);
float center=(document.getPageSize().getWidth())/2-120/2;
table.writeSelectedRows(0, -1,center,30, writer.getDirectContent());
}
catch(DocumentException de) {
throw new ExceptionConverter(de);
}
}
示例13: renderMergedOutputModel
import com.itextpdf.text.Document; //导入依赖的package包/类
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
// IE workaround: write into byte array first.
ByteArrayOutputStream baos = createTemporaryOutputStream();
// Apply preferences and build metadata.
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, baos);
prepareWriter(model, writer, request);
buildPdfMetadata(model, document, request);
// Build PDF document.
writer.setInitialLeading(16);
document.open();
buildPdfDocument(model, document, writer, request, response);
document.close();
// Flush to HTTP response.
writeToResponse(response, baos);
}
示例14: renderMergedOutputModel
import com.itextpdf.text.Document; //导入依赖的package包/类
@Override
protected void renderMergedOutputModel(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// IE workaround: write into byte array first.
ByteArrayOutputStream baos = createTemporaryOutputStream();
// Apply preferences and build metadata.
Document document = newDocument();
PdfWriter writer = newWriter(document, baos);
prepareWriter(model, writer, request);
buildPdfMetadata(model, document, request);
// Build PDF document.
document.open();
buildPdfDocument(model, document, writer, request, response);
document.close();
// Flush to HTTP response.
writeToResponse(response, baos);
}
示例15: createDocument
import com.itextpdf.text.Document; //导入依赖的package包/类
public Document createDocument(File pdfFile) throws DocumentException, IOException{
Document document = new Document(new Rectangle(pageWidth, pageHeight));
document.setPageSize(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
//写入页尾
this.setFooter(writer);
writer.setFullCompression();
writer.setPdfVersion(PdfWriter.VERSION_1_4);
document.open();
// //加入二维码图片
// Image image = Image.getInstance(System.getProperty(appConfig.getValue("app.root"))+"/images/logoqrcode.png");
// image.scaleAbsolute(40,40);//控制图片大小
// image.setAlignment(Image.LEFT);
// document.add(image);
return document;
}