我和iText的第一次亲密接触
要生成pdf文件,在网上查了下资料,首选iText,跟着大家走,我也iText一把。
1:把字型编程A4横向
private void concatenateSummary(String[] args, String finalFile){try { int pageOffset = 0; ArrayList master = new ArrayList(); int f = 0; String outFile = finalFile; Document document = null; PdfCopy writer = null; while (f < args.length) { // we create a reader for a certain document PdfReader reader = new PdfReader(args[f]); reader.consolidateNamedDestinations(); // we retrieve the total number of pages int n = reader.getNumberOfPages(); List bookmarks = SimpleBookmark.getBookmark(reader); if (bookmarks != null) { if (pageOffset != 0) SimpleBookmark.shiftPageNumbers(bookmarks, pageOffset, null); master.addAll(bookmarks); } pageOffset += n; if (f == 0) { // step 1: creation of a document-object document = new Document(reader.getPageSizeWithRotation(1)); // step 2: we create a writer that listens to the document writer = new PdfCopy(document, new FileOutputStream(outFile)); // step 3: we open the document document.open(); } // step 4: we add content PdfImportedPage page; for (int i = 0; i < n; ) { ++i; page = writer.getImportedPage(reader, i); writer.addPage(page); } PRAcroForm form = reader.getAcroForm(); if (form != null) writer.copyAcroForm(reader); f++; } if (!master.isEmpty()) writer.setOutlines(master); // step 5: we close the document document.close(); } catch(Exception e) { e.printStackTrace(); }}1 楼 ddandyy 2007-03-01 收藏了 以后或许用得着.........