本文整理汇总了Java中com.itextpdf.text.Document.open方法的典型用法代码示例。如果您正苦于以下问题:Java Document.open方法的具体用法?Java Document.open怎么用?Java Document.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.itextpdf.text.Document
的用法示例。
在下文中一共展示了Document.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildPdfDocument
import com.itextpdf.text.Document; //导入方法依赖的package包/类
public void buildPdfDocument(OutputStream toWrite, final String name, final int treeCount, String[] codeFragments, String imagePath) throws Exception {
// create pdf
final Document doc = new Document();
final PdfWriter pdfWriter = PdfWriter.getInstance(doc, toWrite);
pdfWriter.setEncryption(null, null, PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);
_imagePath = imagePath;
doc.open();
PdfContentByte cb = pdfWriter.getDirectContent();
PdfHelper.createHeaderBlock(cb,1,1);
PdfHelper.createCircleAndText(cb, "Gutschein", 298f, 705f, 75, textFontForCircle, 0x7F, 0xAD, 0x09);
createBlueBlock(cb, treeCount);
createGreyBlock(cb, codeFragments);
pdfHelper.addLogo(cb, _imagePath, 262f, 35f);
doc.close();
}
示例2: 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();
}
示例3: 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);
}
示例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: createDocument
import com.itextpdf.text.Document; //导入方法依赖的package包/类
public Document createDocument(File pdfFile) throws DocumentException, IOException{
Document document = new Document(new Rectangle(pageWidth, pageHeight));
document.setPageSize(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
//写入页尾
this.setFooter(writer);
writer.setFullCompression();
writer.setPdfVersion(PdfWriter.VERSION_1_4);
document.open();
// //加入二维码图片
// Image image = Image.getInstance(System.getProperty(appConfig.getValue("app.root"))+"/images/logoqrcode.png");
// image.scaleAbsolute(40,40);//控制图片大小
// image.setAlignment(Image.LEFT);
// document.add(image);
return document;
}
示例8: main
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* Generates a document with a header containing Page x of y and with a Watermark on every page.
* @param args no arguments needed
*/
public static void main(String args[]) {
try {
// 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, new FileOutputStream("pageNumbersWatermark.pdf"));
// step 3: initialisations + opening the document
writer.setPageEvent(new PageNumbersWatermark());
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();
}
catch ( Exception e ) {
e.printStackTrace();
}
}
示例9: ExtractPages
import com.itextpdf.text.Document; //导入方法依赖的package包/类
public static byte[] ExtractPages(String pdfDocument, int startPage, int endPage) throws IOException, DocumentException
{
try (InputStream pdfDocumentStream = SmartMerging.class.getResourceAsStream(pdfDocument))
{
PdfReader reader = new PdfReader(pdfDocumentStream);
int numberOfPages = reader.getNumberOfPages();
int endPageResolved = endPage > 0 ? endPage : numberOfPages;
if (startPage > numberOfPages || endPageResolved > numberOfPages)
System.err.printf("Error: page indices (%s, %s) out of bounds. Document has {2} pages.", startPage, endPageResolved, numberOfPages);
byte[] outputDocument;
try (ByteArrayOutputStream msOut = new ByteArrayOutputStream())
{
Document doc = new Document();
PdfCopy pdfCopyProvider = new PdfCopy(doc, msOut);
doc.open();
for (int i = startPage; i <= endPageResolved; i++)
{
PdfImportedPage page = pdfCopyProvider.getImportedPage(reader, i);
pdfCopyProvider.addPage(page);
}
doc.close();
reader.close();
outputDocument = msOut.toByteArray();
}
return outputDocument;
}
}
示例10: makePDF
import com.itextpdf.text.Document; //导入方法依赖的package包/类
private static void makePDF(Bitmap bmp, File file) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(file));
document.addAuthor(FullscreenActivity.mAuthor.toString());
document.addTitle(FullscreenActivity.mTitle.toString());
document.addCreator("OpenSongApp");
if (bmp!=null && bmp.getWidth()>bmp.getHeight()) {
document.setPageSize(PageSize.A4.rotate());
} else {
document.setPageSize(PageSize.A4);
}
document.addTitle(FullscreenActivity.mTitle.toString());
document.open();//document.add(new Header("Song title",FullscreenActivity.mTitle.toString()));
BaseFont urName = BaseFont.createFont("assets/fonts/Lato-Reg.ttf", "UTF-8",BaseFont.EMBEDDED);
Font TitleFontName = new Font(urName, 14);
Font AuthorFontName = new Font(urName, 10);
document.add(new Paragraph(FullscreenActivity.mTitle.toString(),TitleFontName));
document.add(new Paragraph(FullscreenActivity.mAuthor.toString(),AuthorFontName));
addImage(document,bmp);
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: testCopyReadOnlyFields
import com.itextpdf.text.Document; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/32710839/itextsharp-pdfcopy-makes-read-only-fields-editable">
* iTextSharp PdfCopy makes read-only fields editable
* </a>
* <br/>
* <a href="https://www.dropbox.com/s/nhy7av9b37uwowl/in1.pdf?dl=0">
* in1.pdf
* </a>
* <p>
* Indeed, the issue can be reproduced. A possible explanation in a SO answer.
* </p>
*/
@Test
public void testCopyReadOnlyFields() throws IOException, DocumentException
{
Document document = new Document();
try ( OutputStream fileStream = new FileOutputStream(new File(RESULT_FOLDER, "in1Copy.pdf"));
InputStream resource = getClass().getResourceAsStream("in1.pdf") )
{
PdfCopy copier = new PdfCopy(document, fileStream);
PdfReader reader = new PdfReader(resource);
copier.setMergeFields();
document.open();
copier.addDocument(reader);
copier.addJavaScript(reader.getJavaScript());
document.close();
}
}
示例12: testParagraphBackgroundEventListener
import com.itextpdf.text.Document; //导入方法依赖的package包/类
@Test
public void testParagraphBackgroundEventListener() throws DocumentException, FileNotFoundException
{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "document-with-paragraph-backgrounds.pdf")));
ParagraphBackground border = new ParagraphBackground();
writer.setPageEvent(border);
document.open();
document.add(new Paragraph("Hello,"));
document.add(new Paragraph("In this document, we'll add several paragraphs that will trigger page events. As long as the event isn't activated, nothing special happens, but let's make the event active and see what happens:"));
border.setActive(true);
document.add(new Paragraph("This paragraph now has a background. Isn't that fantastic? By changing the event, we can even draw a border, change the line width of the border and many other things. Now let's deactivate the event."));
border.setActive(false);
document.add(new Paragraph("This paragraph no longer has a background."));
document.close();
}
示例13: createRotatedIndirectTextPdf
import com.itextpdf.text.Document; //导入方法依赖的package包/类
static byte[] createRotatedIndirectTextPdf() throws DocumentException, IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
PdfReader reader = new PdfReader(createSimpleTextPdf());
PdfImportedPage template = writer.getImportedPage(reader, 1);
Rectangle pageSize = reader.getPageSize(1);
writer.getDirectContent().addTemplate(template, .7f, .7f, -.7f, .7f, 400, -200);
document.newPage();
writer.getDirectContent().addTemplate(template, pageSize.getLeft(), pageSize.getBottom());
document.close();
return baos.toByteArray();
}
示例14: IMGToPDF
import com.itextpdf.text.Document; //导入方法依赖的package包/类
public void IMGToPDF(String RESOURCES, String result) throws DocumentException, FileNotFoundException, BadElementException, IOException{
ProgressBar progrsbar=new ProgressBar();
progrsbar.showProgress();
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(result));
// step 3
document.open();
// step 4
Image img;
img = Image.getInstance(RESOURCES);
Image.getInstance(img);
document.add(img);
progrsbar.updatePercent(100);
document.close();
}
示例15: 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();
}