本文整理匯總了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();
}