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