本文整理匯總了Java中com.itextpdf.text.Document.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.close方法的具體用法?Java Document.close怎麽用?Java Document.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.Document
的用法示例。
在下文中一共展示了Document.close方法的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: 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();
}
}
示例4: 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();
}
示例5: 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);
}
示例6: 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);
}
示例7: closePassedStream
import com.itextpdf.text.Document; //導入方法依賴的package包/類
/**
* The <code>closePassedStream</code> method closes the stream passed.
*
* @param reader {@link PdfReader}
* @param document {@link Document}
* @param contentByte {@link PdfContentByte}
* @param writer {@link PdfWriter}
* @param fileInputStream {@link FileInputStream}
* @param fileOutputStream {@link FileOutputStream}
* @throws IOException {@link} if unable to close input or output stream
*/
private static void closePassedStream(final PdfReader reader, final Document document,
final PdfContentByte contentByte, final PdfWriter writer,
final FileInputStream fileInputStream, final FileOutputStream fileOutputStream) throws IOException {
if (null != reader) {
reader.close();
}
if (null != document) {
document.close();
}
if (null != contentByte) {
contentByte.closePath();
}
if (null != writer) {
writer.close();
}
if (null != fileInputStream) {
fileInputStream.close();
}
if (null != fileOutputStream) {
fileOutputStream.flush();
fileOutputStream.close();
}
}
示例8: testDoubleSpace
import com.itextpdf.text.Document; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/35699167/double-space-not-being-preserved-in-pdf">
* Double space not being preserved in PDF
* </a>
* <p>
* Indeed, the double space collapses into a single one when copying&pasting from the
* generated PDF displayed in Adobe Reader. On the other hand the gap for the double
* space is twice as wide as for the single space. So this essentially is a quirk of
* copy&paste of Adobe Reader (and some other PDF viewers, too).
* </p>
*/
@Test
public void testDoubleSpace() throws DocumentException, IOException
{
try ( OutputStream pdfStream = new FileOutputStream(new File(RESULT_FOLDER, "DoubleSpace.pdf")))
{
PdfPTable table = new PdfPTable(1);
table.getDefaultCell().setBorderWidth(0.5f);
table.getDefaultCell().setBorderColor(BaseColor.LIGHT_GRAY);
table.addCell(new Phrase("SINGLE SPACED", new Font(BaseFont.createFont(), 36)));
table.addCell(new Phrase("DOUBLE SPACED", new Font(BaseFont.createFont(), 36)));
table.addCell(new Phrase("TRIPLE SPACED", new Font(BaseFont.createFont(), 36)));
Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
PdfWriter.getInstance(pdfDocument, pdfStream);
pdfDocument.open();
pdfDocument.add(table);
pdfDocument.close();
}
}
示例9: copyToMultiplePages
import com.itextpdf.text.Document; //導入方法依賴的package包/類
private static File copyToMultiplePages(CropJob cropJob) throws IOException, DocumentException {
PdfReader reader = new PdfReader(cropJob.getSource().getAbsolutePath());
Document document = new Document();
File resultFile = File.createTempFile("cropped", ".pdf");
PdfSmartCopy pdfCopy = new PdfSmartCopy(document, new FileOutputStream(resultFile));
document.open();
PdfImportedPage page;
for (int pageNumber = 1; pageNumber <= cropJob.getSourcePageCount(); pageNumber++) {
SingleCluster currentCluster = cropJob.getClusterCollection().getSingleCluster(pageNumber);
page = pdfCopy.getImportedPage(reader, pageNumber);
pdfCopy.addPage(page);
for (int j = 1; j < currentCluster.getRatiosList().size(); j++) {
pdfCopy.addPage(page);
}
}
document.close();
pdfCopy.close();
reader.close();
return resultFile;
}
示例10: testRowspanWithHeaderRows
import com.itextpdf.text.Document; //導入方法依賴的package包/類
/**
* <a href="http://stackoverflow.com/questions/40947306/strange-setrowspan-error-not-working">
* Strange setRowspan error/not working
* </a>
* <p>
* Selecting 1 header row and having a cell in the first row which spans 2 rows
* does not match. iText ignores the row span resulting in the weird appearance.
* </p>
*/
@Test
public void testRowspanWithHeaderRows() throws IOException, DocumentException
{
File file = new File(RESULT_FOLDER, "rowspanWithHeaderRows.pdf");
OutputStream os = new FileOutputStream(file);
Document document = new Document();
/*PdfWriter writer =*/ PdfWriter.getInstance(document, os);
document.open();
document.add(createHeaderContent());
document.newPage();
document.add(createHeaderContent(new int[] {5,5,5,5,5}));
document.close();
}
示例11: exportInnertion
import com.itextpdf.text.Document; //導入方法依賴的package包/類
/**
*
*/
@Override
public void exportInnertion(OutputStream servletOut, List header, List data)
throws IOException {
// step 1
Document document = new Document();
// step 2
PdfWriter writer;
try {
writer = PdfWriter.getInstance(document, servletOut);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
// step 3
document.open();
// step 4
XMLWorkerHelper.getInstance().parseXHtml(writer, document,
new java.io.StringReader(
HtmlExport.createHTML(header, data)));
// step 5
document.close();
}
示例12: renderGraph
import com.itextpdf.text.Document; //導入方法依賴的package包/類
@Override
public void renderGraph(JGraph<?> graph, File file) throws PortException {
// Get graph bounds. If not available, do nothing (probably empty graph)
Rectangle2D bounds = graph.getGraphBounds();
if (bounds == null) {
return;
}
Rectangle bound = new Rectangle((float) bounds.getWidth(), (float) bounds.getHeight());
try (FileOutputStream fos = new FileOutputStream(file)) {
Document document = new Document(bound);
// Open file, create PDF document
PdfWriter writer = PdfWriter.getInstance(document, fos);
// Set some metadata
document.addCreator(Version.getAbout());
// Open document, get graphics
document.open();
PdfContentByte cb = writer.getDirectContent();
boolean onlyShapes = true;
//The embedded fonts most likely do not contain all necessary glyphs, so using outlines instead
// onlyShapes makes PDF considerably bigger, but no alternative at the moment
PdfGraphics2D pdf2d =
new PdfGraphics2D(cb, (float) bounds.getWidth(), (float) bounds.getHeight(),
new DefaultFontMapper(), onlyShapes, false, (float) 100.0);
// Render
toGraphics(graph, pdf2d);
// Cleanup
pdf2d.dispose();
document.close();
} catch (DocumentException | IOException e) {
throw new PortException(e);
}
}
示例13: htmlToPdf
import com.itextpdf.text.Document; //導入方法依賴的package包/類
public void htmlToPdf(String htmlPath, File pdfFile) throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
document.open();
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(htmlPath), Charset.forName("UTF-8"));
document.close();
}
示例14: main
import com.itextpdf.text.Document; //導入方法依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, DocumentException {
Document d = new Document(PageSize.A4);
FileOutputStream fos = new FileOutputStream("teste.pdf");
PdfWriter.getInstance(d, fos);
d.open();
PdfPTable pTable = new PdfPTable(3);
PdfPCell cell1 = new PdfPCell(new Phrase("111111111"));
PdfPCell cell2 = new PdfPCell(new Phrase("222222222"));
cell2.setRowspan(5);
PdfPCell cell3 = new PdfPCell(new Phrase("333333333"));
pTable.addCell(cell1);
pTable.addCell(cell2);
pTable.addCell(cell3);
pTable.addCell(cell1);
pTable.addCell(cell3);
pTable.addCell(cell1);
pTable.addCell(cell3);
pTable.addCell(cell1);
pTable.addCell(cell3);
pTable.addCell(cell1);
pTable.addCell(cell3);
pTable.addCell(cell1);
pTable.addCell(cell3);
pTable.addCell(cell1);
pTable.addCell(cell3);
d.add(pTable);
d.close();
}
示例15: main
import com.itextpdf.text.Document; //導入方法依賴的package包/類
public static void main(String[] args) throws FileNotFoundException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));
document.open();
document.add(new Paragraph("hello world"));
document.close();
writer.close();
}