本文整理汇总了Java中com.lowagie.text.Document.open方法的典型用法代码示例。如果您正苦于以下问题:Java Document.open方法的具体用法?Java Document.open怎么用?Java Document.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.Document
的用法示例。
在下文中一共展示了Document.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportVectorGraphics
import com.lowagie.text.Document; //导入方法依赖的package包/类
private void exportVectorGraphics(String formatName, File outputFile) throws ImageExportException {
Component component = printableComponent.getExportComponent();
int width = component.getWidth();
int height = component.getHeight();
try (FileOutputStream fs = new FileOutputStream(outputFile)) {
switch (formatName) {
case PDF:
// create pdf document with slightly increased width and height
// (otherwise the image gets cut off)
Document document = new Document(new Rectangle(width + 5, height + 5));
PdfWriter writer = PdfWriter.getInstance(document, fs);
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
component.print(g2);
g2.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
break;
case SVG:
exportFreeHep(component, fs, new SVGGraphics2D(fs, new Dimension(width, height)));
break;
case EPS:
exportFreeHep(component, fs, new PSGraphics2D(fs, new Dimension(width, height)));
break;
default:
// cannot happen
break;
}
} catch (Exception e) {
throw new ImageExportException(I18N.getMessage(I18N.getUserErrorMessagesBundle(),
"error.image_export.export_failed"), e);
}
}
示例2: close
import com.lowagie.text.Document; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
try {
float width = 0;
float[] w = new float[iMaxWidth.length - iHiddenColumns.size()]; int wi = 0;
for (int i = 0; i < iMaxWidth.length; i++)
if (!iHiddenColumns.contains(i)) { width += 15f + iMaxWidth[i]; w[wi++] = iMaxWidth[i]; }
Document document = new Document(new Rectangle(60f + width, 60f + width * 0.75f), 30f, 30f, 30f, 30f);
PdfWriter writer = PdfWriter.getInstance(document, iOutput);
writer.setPageEvent(new PdfEventHandler());
document.open();
iTable.setWidths(w);
document.add(iTable);
document.close();
} catch (DocumentException e) {
throw new IOException(e.getMessage(), e);
}
}
示例3: createDoc
import com.lowagie.text.Document; //导入方法依赖的package包/类
public void createDoc() throws FileNotFoundException{
/** 创建Document对象(word文档) */
Rectangle rectPageSize = new Rectangle(PageSize.A4);
rectPageSize = rectPageSize.rotate();
// 创建word文档,并设置纸张的大小
doc = new Document(PageSize.A4);
file=new File(path+docFileName);
fileOutputStream=new FileOutputStream(file);
/** 建立一个书写器与document对象关联,通过书写器可以将文档写入到输出流中 */
RtfWriter2.getInstance(doc, fileOutputStream );
doc.open();
//设置页边距,上、下25.4毫米,即为72f,左、右31.8毫米,即为90f
doc.setMargins(90f, 90f, 72f, 72f);
//设置标题字体样式,粗体、二号、华文中宋
tfont = DocStyleUtils.setFontStyle("华文中宋", 22f, Font.BOLD);
//设置正文内容的字体样式,常规、三号、仿宋_GB2312
bfont = DocStyleUtils.setFontStyle("仿宋_GB2312", 16f, Font.NORMAL);
}
示例4: createDocument
import com.lowagie.text.Document; //导入方法依赖的package包/类
@Override
public void createDocument(String documentName, String content) throws CitizenException {
String realPath = FILE_PATH + documentName + ".pdf";
Document doc = new Document();
try {
PdfWriter.getInstance(doc, new FileOutputStream(realPath));
doc.open();
addMetaData(doc);
addTitlePage(doc);
addContent(doc, content);
} catch (DocumentException | FileNotFoundException e) {
throw new CitizenException("Error al generar documento pdf" +
" ["+ FILE_PATH+documentName+".pdf] | ["+this.getClass().getName()+"]");
} finally {
if (doc != null) {
doc.close();
}
}
}
示例5: convertWriteToPdf
import com.lowagie.text.Document; //导入方法依赖的package包/类
public static void convertWriteToPdf(BufferedImage bufeBufferedImage, String path) {
try {
//Image img = Image.getInstance("C:\\Users\\SOFTWARE1\\Desktop\\boshtwain4JImages\\testcapture1507134499431.jpg");
Image img = Image.getInstance(bufeBufferedImage, null);
Document document = new Document(img);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
//--
document.open();
img.setAbsolutePosition(0, 0);
//--
document.add(img);
//--
document.close();
} catch (DocumentException | IOException e) {
System.out.println("Intern Log : " + e.getMessage());
}
}
示例6: open
import com.lowagie.text.Document; //导入方法依赖的package包/类
public void open(OutputStream out, int mode) throws DocumentException, IOException {
iOut = out;
if (mode==sModeText) {
iPrint = new PrintWriter(iOut);
} else {
iNrLines = (mode==sModeLedger?116:50);
iDoc = new Document(mode==sModeLedger?PageSize.LEDGER.rotate():PageSize.LETTER.rotate());
PdfWriter.getInstance(iDoc, iOut);
iDoc.addTitle(iTitle);
iDoc.addAuthor("UniTime "+Constants.getVersion()+", www.unitime.org");
iDoc.addSubject(iSubject);
iDoc.addCreator("UniTime "+Constants.getVersion()+", www.unitime.org");
iDoc.open();
}
iEmpty = true;
iPageNo = 0; iLineNo = 0;
}
示例7: main
import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
* Generates a document with a header containing Page x of y and with a Watermark on every page.
*/
@Test
public void main() throws Exception {
// step 1: creating the document
Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
// step 2: creating the writer
PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf"));
// step 3: initialisations + opening the document
writer.setPageEvent(new PageNumbersWatermarkTest());
doc.open();
// step 4: adding content
String text = "some padding text ";
for (int k = 0; k < 10; ++k) {
text += text;
}
Paragraph p = new Paragraph(text);
p.setAlignment(Element.ALIGN_JUSTIFIED);
doc.add(p);
// step 5: closing the document
doc.close();
}
示例8: main
import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
* Specifying an encoding.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2: creation of the writer
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontencoding.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content to the document
BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
Font font = new Font(helvetica, 12, Font.NORMAL);
Chunk chunk = new Chunk("Sponsor this example and send me 1\u20ac. These are some special characters: \u0152\u0153\u0160\u0161\u0178\u017D\u0192\u02DC\u2020\u2021\u2030", font);
document.add(chunk);
// step 5: we close the document
document.close();
}
示例9: main
import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
* Using a True Type Font.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document,PdfTestBase.getOutputStream("truetype.pdf"));
// step 3: we open the document
document.open();
String f = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf/LiberationMono-Regular.ttf").getAbsolutePath();
// step 4: we add content to the document
BaseFont bfComic = BaseFont.createFont(f, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font font = new Font(bfComic, 12);
String text1 = "This is the quite popular Liberation Mono.";
document.add(new Paragraph(text1, font));
// step 5: we close the document
document.close();
}
示例10: main
import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
* Adds an Image at an absolute position.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("absolutepositions.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content
Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
png.setAbsolutePosition(171, 250);
document.add(png);
png.setAbsolutePosition(342, 500);
document.add(png);
// step 5: we close the document
document.close();
}
示例11: renderMergedOutputModel
import com.lowagie.text.Document; //导入方法依赖的package包/类
@Override
protected final 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);
}
示例12: main
import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
* Extended font example.
*
*
*/
@Test
public void main() throws Exception {
Document document = new Document();
RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedFont.rtf"));
document.open();
// Create a RtfFont with the desired font name.
RtfFont msComicSans = new RtfFont("Comic Sans MS");
// Use the RtfFont like any other Font.
document.add(new Paragraph("This paragraph uses the" + " Comic Sans MS font.", msComicSans));
// Font size, font style and font colour can also be specified.
RtfFont bigBoldGreenArial = new RtfFont("Arial", 36, Font.BOLD, Color.GREEN);
document.add(new Paragraph("This is a really big bold green Arial text", bigBoldGreenArial));
document.close();
}
示例13: OscarChartPrinter
import com.lowagie.text.Document; //导入方法依赖的package包/类
public OscarChartPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
this.request = request;
this.os = os;
document = new Document();
// writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
writer = PdfWriter.getInstance(document,os);
writer.setPageEvent(new EndPage());
document.setPageSize(PageSize.LETTER);
document.open();
//Create the font we are going to print to
bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
font = new Font(bf, FONTSIZE, Font.NORMAL);
boldFont = new Font(bf,FONTSIZE,Font.BOLD);
}
示例14: PdfWorksheet
import com.lowagie.text.Document; //导入方法依赖的package包/类
private PdfWorksheet(OutputStream out, Collection<SubjectArea> subjectAreas, String courseNumber) throws IOException, DocumentException {
iUseCommitedAssignments = ApplicationProperty.WorksheetPdfUseCommittedAssignments.isTrue();
iSubjectAreas = new TreeSet<SubjectArea>(new Comparator<SubjectArea>() {
@Override
public int compare(SubjectArea s1, SubjectArea s2) {
return s1.getSubjectAreaAbbreviation().compareTo(s2.getSubjectAreaAbbreviation());
}
});
iSubjectAreas.addAll(subjectAreas);
iCourseNumber = courseNumber;
if (iCourseNumber!=null && (iCourseNumber.trim().length()==0 || "*".equals(iCourseNumber.trim().length())))
iCourseNumber = null;
iDoc = new Document(PageSize.LETTER.rotate());
iOut = out;
PdfWriter.getInstance(iDoc, iOut);
String session = null;
String subjects = "";
for (SubjectArea sa: iSubjectAreas) {
if (subjects.isEmpty()) subjects += ", ";
subjects += sa.getSubjectAreaAbbreviation();
if (session == null) session += sa.getSession().getLabel();
}
iDoc.addTitle(subjects + (iCourseNumber==null?"":" "+iCourseNumber) + " Worksheet");
iDoc.addAuthor(ApplicationProperty.WorksheetPdfAuthor.value().replace("%", Constants.getVersion()));
iDoc.addSubject(subjects + (session == null ? "" : " -- " + session));
iDoc.addCreator("UniTime "+Constants.getVersion()+", www.unitime.org");
if (!iSubjectAreas.isEmpty())
iCurrentSubjectArea = iSubjectAreas.first();
iDoc.open();
printHeader();
}
示例15: main
import com.lowagie.text.Document; //导入方法依赖的package包/类
/**
* Demonstrates some PageLabel functionality.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("PageLabels.pdf"));
// step 3:
writer.setViewerPreferences(PdfWriter.PageModeUseThumbs);
document.open();
// step 4:
// we add some content
for (int k = 1; k <= 10; ++k) {
document.add(new Paragraph(
"This document has the logical page numbers: i,ii,iii,iv,1,2,3,A-8,A-9,A-10\nReal page " + k));
document.newPage();
}
PdfPageLabels pageLabels = new PdfPageLabels();
pageLabels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);
pageLabels.addPageLabel(5, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);
pageLabels.addPageLabel(8, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, "A-", 8);
writer.setPageLabels(pageLabels);
// step 5: we close the document
document.close();
}