本文整理汇总了Java中org.apache.pdfbox.pdmodel.edit.PDPageContentStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java PDPageContentStream.close方法的具体用法?Java PDPageContentStream.close怎么用?Java PDPageContentStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.edit.PDPageContentStream
的用法示例。
在下文中一共展示了PDPageContentStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create100Pages
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
public PDDocument create100Pages() throws IOException
{
PDDocument document = new PDDocument();
for (int i = 0; i < 100; i++)
{
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream content = new PDPageContentStream(document, page);
content.beginText();
content.setFont(PDType1Font.HELVETICA_BOLD, 100);
content.moveTextPositionByAmount(100, 300);
content.drawString(String.format("-%s-", i + 1));
content.endText();
content.close();
}
return document;
}
示例2: test
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
@Test
public void test() throws IOException, COSVisitorException {
PDDocument doc = new PDDocument();
PDPage page = new PDPage();
doc.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(doc, page);
String[][] content = { { "Team", "Captain" },
{ "Hull City", "Robert Koren" },
{ "Aston Villa", "Ron Vlaar" },
{ "Manchester United", "Nemanja Vidic" },
{ "Manchester City", "Vincent Kompany" } };
drawTable(page, contentStream, 700, 100, content);
contentStream.close();
Path outputFilePath = Files.createTempFile("Test-CaptainTeam-Table", ".pdf");
doc.save(outputFilePath.toFile());
logger.info("test# "+ outputFilePath.toAbsolutePath().toString());
}
示例3: createTestDocument
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
byte[] createTestDocument() throws IOException, COSVisitorException
{
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream();
PDDocument doc = new PDDocument() )
{
PDPage page = new PDPage(new PDRectangle(792, 612));
doc.addPage(page);
PDFont font = PDType1Font.COURIER;
PDPageContentStream contents = new PDPageContentStream(doc, page);
contents.beginText();
contents.setFont(font, 9);
contents.moveTextPositionByAmount(100, 500);
contents.drawString(" 2 Netto 5,00 EUR 3,00");
contents.moveTextPositionByAmount(0, 0);
contents.drawString(" 2882892 ENERGIZE LR6 Industrial 2,50 EUR 1");
contents.endText();
contents.close();
doc.save(baos);
return baos.toByteArray();
}
}
示例4: writeImageToPDF
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
private void writeImageToPDF(PDJpeg img, int c, int size) throws IOException {
PDPageContentStream cs = new PDPageContentStream(document, page, true, false);
float x = getLeftX();
float y = page.getYCursor()-img.getHeight();
if (c>0&&(c%2==0)) {
x+=350;
}
if (size > 0) {
y = page.getYCursor()-400;
}
if (isFullPage())
y = page.getLowY();
cs.drawImage(img, x, y);
cs.close();
}
示例5: create
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
public void create(PDDocument document, PDFPage page) throws IOException {
PDPageContentStream cs = new PDPageContentStream(document, page, true, false);
PDRectangle pageSize = page.getBleedBox();
float pageWidth = pageSize.getWidth();
page.translateAndRotateIfNecessary(cs, pageWidth, 0);
cs.beginText();
PDFont font = PDType1Font.HELVETICA_BOLD;
cs.setFont(font, 20);
cs.moveTextPositionByAmount(page.getLeftX(), page.getTopY());
cs.drawString(title);
cs.endText();
cs.drawLine(page.getLeftX(), page.getTopY()-height, page.getRightX(), page.getTopY()-height);
cs.close();
}
示例6: addTitleRow
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
public void addTitleRow(String[] titles) throws IOException {
if (hideTable)
return;
int size = 16;
float cellSize = (getWidth()/titles.length);
PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream cs = new PDPageContentStream(document, page, true, false);
cs.setFont(font, size);
float leftX = getLeftX()+30;
for (String title : titles) {
cs.beginText();
cs.moveTextPositionByAmount(leftX, page.getYCursor());
cs.drawString(title);
cs.endText();
if (cellSize != -1)
leftX += cellSize;
else
leftX += (font.getStringWidth(title) / 1000 * size)+5;
}
cs.drawLine(getLeftX(), page.getYCursor() - 5, getRightX(), page.getYCursor() - 5);
cs.close();
scrolldown();
}
示例7: checkPDFTemplateFileName
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
private static String checkPDFTemplateFileName(String PDFTemplateFileName, String path) throws IOException, IllegalArgumentException {
String template;
if (PDFTemplateFileName != null && PDFTemplateFileName.length() > 0) {
File file = new File(PDFTemplateFileName);
if (file.exists()) {
if (file.isFile()) {
if (file.canRead()) {
PDDocument doc = null;
try {
doc = PDDocument.load(file);
PDPage page = (PDPage) doc.getDocumentCatalog().getAllPages().get(0);
PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true);
contentStream.close();
template = file.getCanonicalPath();
} catch (Exception e) {
throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_INVALID_PDF_ERROR,
DefaultMessages.PDF_TEMPLATE_FILE_INVALID_PDF_ERROR, PDFTemplateFileName), e);
} finally {
if (doc != null) {
doc.close();
}
}
} else {
throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_ACCESS_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_ACCESS_ERROR,
PDFTemplateFileName));
}
} else {
throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_NOTAFILE_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_NOTAFILE_ERROR,
PDFTemplateFileName));
}
} else {
throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.PDF_TEMPLATE_FILE_DOES_NOT_EXIST_ERROR, DefaultMessages.PDF_TEMPLATE_FILE_DOES_NOT_EXIST_ERROR,
PDFTemplateFileName));
}
} else {
template = "";
}
return template;
}
示例8: createRollover
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
void createRollover(PDAnnotation annotation, String filename) throws IOException, COSVisitorException
{
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
List<PDAnnotation> annotations = page.getAnnotations();
float x = 100;
float y = 500;
String text = "PDFBox";
PDFont font = PDType1Font.HELVETICA_BOLD;
float textWidth = font.getStringWidth(text) / 1000 * 18;
PDPageContentStream contents = new PDPageContentStream(document, page);
contents.beginText();
contents.setFont(font, 18);
contents.moveTextPositionByAmount(x, y);
contents.drawString(text);
contents.endText();
contents.close();
PDAppearanceDictionary appearanceDictionary = new PDAppearanceDictionary();
PDAppearanceStream normal = createAppearanceStream(document, textWidth, font, "0.5 0.5 0.5 rg");
PDAppearanceStream rollover = createAppearanceStream(document, textWidth, font, "1 0.7 0.5 rg");
PDAppearanceStream down = createAppearanceStream(document, textWidth, font, "0 0 0 rg");
appearanceDictionary.setNormalAppearance(normal);
appearanceDictionary.setRolloverAppearance(rollover);
appearanceDictionary.setDownAppearance(down);
annotation.setAppearance(appearanceDictionary);
PDRectangle position = new PDRectangle();
position.setLowerLeftX(x);
position.setLowerLeftY(y - 5);
position.setUpperRightX(x + textWidth);
position.setUpperRightY(y + 20);
annotation.setRectangle(position);
annotations.add(annotation);
document.save(new File(RESULT_FOLDER, filename));
document.close();
}
示例9: overlayWithDarkenBlendMode
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
void overlayWithDarkenBlendMode(PDDocument document, PDDocument overlay) throws IOException
{
PDXObjectForm xobject = importAsXObject(document, (PDPage) overlay.getDocumentCatalog().getAllPages().get(0));
PDExtendedGraphicsState darken = new PDExtendedGraphicsState();
darken.getCOSDictionary().setName("BM", "Darken");
List<PDPage> pages = document.getDocumentCatalog().getAllPages();
for (PDPage page: pages)
{
Map<String, PDExtendedGraphicsState> states = page.getResources().getGraphicsStates();
if (states == null)
states = new HashMap<String, PDExtendedGraphicsState>();
String darkenKey = MapUtil.getNextUniqueKey(states, "Dkn");
states.put(darkenKey, darken);
page.getResources().setGraphicsStates(states);
PDPageContentStream stream = new PDPageContentStream(document, page, true, false, true);
stream.appendRawCommands(String.format("/%s gs ", darkenKey));
stream.drawXObject(xobject, 0, 0, 1, 1);
stream.close();
}
}
示例10: clipPage
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
void clipPage(PDDocument document, PDPage page, BoundingBox clipBox) throws IOException
{
PDPageContentStream pageContentStream = new PDPageContentStream(document, page, true, false);
pageContentStream.addRect(clipBox.getLowerLeftX(), clipBox.getLowerLeftY(), clipBox.getWidth(), clipBox.getHeight());
pageContentStream.clipPath(PathIterator.WIND_NON_ZERO);
pageContentStream.close();
COSArray newContents = new COSArray();
COSStreamArray contents = (COSStreamArray) page.getContents().getStream();
newContents.add(contents.get(contents.getStreamCount()-1));
for (int i = 0; i < contents.getStreamCount()-1; i++)
{
newContents.add(contents.get(i));
}
page.setContents(new PDStream(new COSStreamArray(newContents)));
}
示例11: testDrawEuro
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/22260344/pdfbox-encode-symbol-currency-euro">
* PdfBox encode symbol currency euro
* </a>
* <p>
* Three ways of trying to draw a '�' symbol, the first one fails.
* </p>
*/
@Test
public void testDrawEuro() throws IOException, COSVisitorException
{
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contents = new PDPageContentStream(document, page);
PDFont font = PDType1Font.HELVETICA_BOLD;
contents.beginText();
contents.setFont(font, 18);
contents.moveTextPositionByAmount(30, 600);
contents.drawString("�");
contents.moveTextPositionByAmount(0, -30);
contents.drawString(String.valueOf(Character.toChars(EncodingManager.INSTANCE.getEncoding(COSName.WIN_ANSI_ENCODING).getCode("Euro"))));
contents.moveTextPositionByAmount(0, -30);
byte[] commands = "(x) Tj ".getBytes();
commands[1] = (byte) 128;
contents.appendRawCommands(commands);
contents.endText();
contents.close();
document.save(new File(RESULT_FOLDER, "Euro.pdf"));
document.close();
}
示例12: testDrawTmSignLetters
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
@Test
public void testDrawTmSignLetters() throws IOException, COSVisitorException
{
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contents = new PDPageContentStream(document, page);
PDFont font = PDType1Font.HELVETICA_BOLD;
contents.beginText();
contents.setFont(font, 18);
contents.moveTextPositionByAmount(30, 600);
contents.drawString("90000039-PREDISOL � C YELLOW 13 SNDOT");
contents.appendRawCommands("\n6 Ts\n".getBytes());
contents.setFont(font, 10);
contents.drawString("TM");
contents.appendRawCommands("\n0 Ts\n".getBytes());
contents.setFont(font, 18);
contents.drawString("M");
contents.endText();
contents.close();
document.save(new File(RESULT_FOLDER, "TM_letters.pdf"));
document.close();
}
示例13: PdfMaker
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
public PdfMaker(Project _project, EntityManager _entityManager) {
this.project = _project;
this.entityManager = _entityManager;
if (_project == null) {
doc = null;
} else {
try {
doc = new PDDocument();
ProjectService projectService = ProjectService.instance();
projectService.setEntityManager(entityManager);
List<ProjectEntry> projectEntriesInOrder = projectService.getProjectEntriesInOrder(project.getId());
for (ProjectEntry projectEntry : projectEntriesInOrder) {
PDPage page = new PDPage();
doc.addPage(page);
PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream content = new PDPageContentStream(doc, page);
content.beginText();
content.setFont(font, 12);
content.drawString(projectEntry.getName());
for (Transcription transcription : projectEntry.getTranscriptions()) {
content.drawString(transcription.getTextLayer());
content.drawString(transcription.getBody());
}
content.endText();
content.close();
}
} catch (Exception e) {
System.out.println("Exception");
}
}
}
示例14: addTitleAndSubtitle
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
private void addTitleAndSubtitle(int offset) throws IOException {
PDPageContentStream cs = new PDPageContentStream(document, this, true, false);
cs.beginText();
cs.setFont(PDType1Font.HELVETICA_BOLD, 30);
float xPosition = getLeftX()+50;
float yPosition = ((getTopY()/2)-borders-offset);
cs.moveTextPositionByAmount(xPosition, yPosition);
cs.drawString(title);
cs.endText();
cs.beginText();
cs.setFont(PDType1Font.HELVETICA_OBLIQUE, 20);
yPosition -= 40;
cs.moveTextPositionByAmount(xPosition, yPosition);
cs.drawString(subtitle);
cs.endText();
cs.close();
}
示例15: flushTableRow
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
protected void flushTableRow(String[] elements, PDFont font, int size, float cellSize) throws IOException {
PDPageContentStream cs = new PDPageContentStream(document, page, true, false);
cs.setFont(font, size);
float leftX = getLeftX();
for (String element : elements) {
cs.beginText();
cs.moveTextPositionByAmount(leftX, page.getYCursor());
cs.drawString(element);
cs.endText();
if (cellSize != -1)
leftX += cellSize;
else
leftX += (font.getStringWidth(element) / 1000 * size)+5;
}
cs.drawLine(getLeftX(), page.getYCursor() - 5, getRightX(), page.getYCursor() - 5);
cs.close();
}