本文整理汇总了Java中com.lowagie.text.pdf.PdfWriter.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java PdfWriter.getInstance方法的具体用法?Java PdfWriter.getInstance怎么用?Java PdfWriter.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lowagie.text.pdf.PdfWriter
的用法示例。
在下文中一共展示了PdfWriter.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportVectorGraphics
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的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.pdf.PdfWriter; //导入方法依赖的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: createDocument
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的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();
}
}
}
示例4: convertWriteToPdf
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的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());
}
}
示例5: open
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的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;
}
示例6: main
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
* Draws arabic text using java.awt.Graphics2D.
*/
@Test
public void main() throws Exception {
// step 1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// step 2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "arabictext.pdf"));
// step 3
document.open();
// step 4
String text1 = "This text has \u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631 123,456 \u0645\u0646 (Arabic)";
java.awt.Font font = new java.awt.Font("arial", 0, 18);
PdfContentByte cb = writer.getDirectContent();
java.awt.Graphics2D g2 = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight());
g2.setFont(font);
g2.drawString(text1, 100, 100);
g2.dispose();
cb.sanityCheck();
// step 5
document.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
示例7: generate
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void generate(OutputStream os) throws Exception
{
document = new Document(PageSize.A4, 36, 36, 36, 50);
writer = PdfWriter.getInstance(document,os);
writer.setEncryption(null, null, PdfWriter.AllowCopy | PdfWriter.AllowPrinting, PdfWriter.STRENGTH40BITS);
writer.setPageEvent(new EndPage(this.getCabecera(),this.getPie(),this.getBarcode(),this.isPaginar()));
document.open();
//Pintar la cabecera que proceda: No pitar, cabecera normal o cabecera peque�a
if(!noCabecera) {
if (tipocabecera.equals(TYPE_HEAD_SMALL)) writeCabecera2();
else writeCabecera();
}
for(int i=0; i<secciones.size(); i++)
{
Seccion obj = (Seccion)secciones.get(i);
obj.write(this);
}
document.close();
}
示例8: OscarChartPrinter
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的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);
}
示例9: main
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
@Test
public void main() throws Exception {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "shading.pdf"));
document.open();
PdfFunction function1 = PdfFunction.type2(writer, new float[] { 0, 1 },
null, new float[] { .929f, .357f, 1, .298f }, new float[] {
.631f, .278f, 1, .027f }, 1.048f);
PdfFunction function2 = PdfFunction.type2(writer, new float[] { 0, 1 },
null, new float[] { .929f, .357f, 1, .298f }, new float[] {
.941f, .4f, 1, .102f }, 1.374f);
PdfFunction function3 = PdfFunction.type3(writer, new float[] { 0, 1 },
null, new PdfFunction[] { function1, function2 },
new float[] { .708f }, new float[] { 1, 0, 0, 1 });
PdfShading shading = PdfShading.type3(writer,
new CMYKColor(0, 0, 0, 0),
new float[] { 0, 0, .096f, 0, 0, 1 }, null, function3,
new boolean[] { true, true });
PdfContentByte cb = writer.getDirectContent();
cb.moveTo(316.789f, 140.311f);
cb.curveTo(303.222f, 146.388f, 282.966f, 136.518f, 279.122f, 121.983f);
cb.lineTo(277.322f, 120.182f);
cb.curveTo(285.125f, 122.688f, 291.441f, 121.716f, 298.156f, 119.386f);
cb.lineTo(336.448f, 119.386f);
cb.curveTo(331.072f, 128.643f, 323.346f, 137.376f, 316.789f, 140.311f);
cb.clip();
cb.newPath();
cb.saveState();
cb.concatCTM(27.7843f, 0, 0, -27.7843f, 310.2461f, 121.1521f);
cb.paintShading(shading);
cb.restoreState();
cb.sanityCheck();
document.close();
}
示例10: openDocument
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
* Creates a document.
*
* @param outputStream The output stream to write the document content.
* @param pageSize the page size.
* @return A Document.
*/
public static Document openDocument( OutputStream outputStream, Rectangle pageSize )
{
try
{
Document document = new Document( pageSize );
PdfWriter.getInstance( document, outputStream );
document.open();
return document;
}
catch ( DocumentException ex )
{
throw new RuntimeException( "Failed to open PDF document", ex );
}
}
示例11: main
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
* Break a large table up into several smaller tables for memory management
* purposes.
*
*/
@Test
public void main() throws Exception {
// step1
Document document = new Document(PageSize.A4, 10, 10, 10, 10);
// step2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SplitTable.pdf"));
// step3
document.open();
// step4
PdfContentByte cb = writer.getDirectContent();
PdfPTable table = new PdfPTable(10);
for (int k = 1; k <= 100; ++k) {
table.addCell("The number " + k);
}
table.setTotalWidth(800);
table.writeSelectedRows(0, 5, 0, -1, 50, 650, cb);
document.newPage();
table.writeSelectedRows(5, -1, 0, -1, 50, 650, cb);
document.close();
// step5
document.close();
}
示例12: initFooter
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
* Initialize Pdf footer
* @param document
* @param outputStream
* @return PdfWriter
*/
public static PdfWriter initFooter(Document document, OutputStream outputStream)
throws DocumentException, IOException {
PdfWriter iWriter = PdfWriter.getInstance(document, outputStream);
iWriter.setPageEvent(new PdfEventHandler());
return iWriter;
}
示例13: PdfWorksheet
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的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();
}
示例14: main
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
* Creates a PDF document with a certain pagesize
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Rectangle pageSize = new Rectangle(216, 720);
pageSize.setBackgroundColor(new java.awt.Color(0xFF, 0xFF, 0xDE));
Document document = new Document(pageSize);
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CustomPageSize.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some paragraphs to the document
document.add(new Paragraph("The size of this page is 216x720 points."));
document.add(new Paragraph("216pt / 72 points per inch = 3 inch"));
document.add(new Paragraph("720pt / 72 points per inch = 10 inch"));
document.add(new Paragraph("The size of this page is 3x10 inch."));
document.add(new Paragraph("3 inch x 2.54 = 7.62 cm"));
document.add(new Paragraph("10 inch x 2.54 = 25.4 cm"));
document.add(new Paragraph("The size of this page is 7.62x25.4 cm."));
document.add(new Paragraph("The backgroundcolor of the Rectangle used for this PageSize, is #FFFFDE."));
document.add(new Paragraph("That's why the background of this document is yellowish..."));
// step 5: we close the document
document.close();
}
示例15: createPDF
import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
private void createPDF(OutputStream out, IDocument doc, WebInput wi)
throws IOException, ServletException {
this.setContentType("application/pdf");
ByteArrayOutputStream baos = new ByteArrayOutputStream(INITIAL_SIZE);
Document document = new Document(PageSize.A4);
DocInfo di;
try {
PdfWriter.getInstance(document, baos);
di = new DocInfo(IDocument.TYPE_PDF);
di.setPdfDocument(document);
// ͨ��ҳ���������ĵ�������Ϣ
doc.createAttribute(wi, di);
document.open();
// �������
doc.createContent(wi, di);
document.close();
this.setContentLength(baos.size());
baos.writeTo(out);
} catch (Exception ex1) {
throw new ServletException(ex1);
} finally {
if (out != null) {
out.flush();
out.close();
out = null;
}
if (baos != null) {
baos.close();
baos = null;
}
document = null;
di = null;
doc = null;
}
}