当前位置: 首页>>代码示例>>Java>>正文


Java Document.getNumberOfPages方法代码示例

本文整理汇总了Java中org.icepdf.core.pobjects.Document.getNumberOfPages方法的典型用法代码示例。如果您正苦于以下问题:Java Document.getNumberOfPages方法的具体用法?Java Document.getNumberOfPages怎么用?Java Document.getNumberOfPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.icepdf.core.pobjects.Document的用法示例。


在下文中一共展示了Document.getNumberOfPages方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeImages

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
@Override
public void writeImages(byte[] input, Set pages, Resource outputDirectory,
		String prefix, String format, int scale, boolean overwrite,
		boolean goodQuality, boolean transparent) throws PageException,
		IOException {
	if(scale<1) 
		throw new ExpressionException("invalid scale definition ["+Caster.toString(scale)+"], value should be in range from 1 to n");
       
	Document document = toDocument(input);
       try{	
		Resource res;
		int count = document.getNumberOfPages();
		for(int page=1;page<=count;page++) {
			if(pages!=null && !pages.contains(Integer.valueOf(page)))continue;
			res=createDestinationResource(outputDirectory,prefix,page,format,overwrite);
			//res=outputDirectory.getRealResource(prefix+"_page_"+page+"."+format);
			writeImage(document,page,res,format,scale,overwrite,goodQuality, transparent);
		}
	}
	finally{
		
	}
       document.dispose();
	
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:26,代码来源:PDF2ImageICEpdf.java

示例2: TextExtractionTask

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
/**
 * Create a new instance of the TextExtraction object.
 *
 * @param document document whose text will be extracted.
 * @param file     output file for extracted text.
 */
public TextExtractionTask(Document document, File file, ResourceBundle messageBundle) {
    this.document = document;
    this.file = file;
    lengthOfTask = document.getNumberOfPages();
    this.messageBundle = messageBundle;
}
 
开发者ID:pdf4j,项目名称:icepdf,代码行数:13,代码来源:TextExtractionTask.java

示例3: createSVG

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
/**
 * Creates a SVG character stream for the given <code>Document</code> and
 * <code>PageNumber</code>.
 *
 * @param pdfDocument Document containing the PDF data
 * @param pageNumber  page number of PDF content that will be rendered to SVG.
 *                    Zero-based index
 * @param out         character stream that the SVG data will be written to
 */
public static void createSVG(Document pdfDocument, int pageNumber, Writer out) {
    try {

        if (pdfDocument != null &&
                (pageNumber >= 0 && pageNumber < pdfDocument.getNumberOfPages())) {
            // Get a DOMImplementation
            DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
            // Create an instance of org.w3c.dom.Document
            org.w3c.dom.Document document = domImpl.createDocument(null, "svg",
                    null);
            // Create an instance of the SVG Generator
            SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
            // Ask the test to render into the SVG Graphics2D implementation

            float userRotation = 0;
            float userZoom = 1;
            PDimension pdfDimension = pdfDocument.getPageDimension(pageNumber, userRotation, userZoom);
            svgGenerator.setSVGCanvasSize(pdfDimension.toDimension());

            pdfDocument.paintPage(pageNumber, svgGenerator,
                    GraphicsRenderingHints.PRINT,
                    Page.BOUNDARY_CROPBOX,
                    userRotation, userZoom);

            // Finally, stream out SVG to the standard output using UTF-8
            // character to byte encoding
            boolean useCSS = true;              // we want to use CSS style attribute
            //            File f=new File("a.svg");
            //            Writer out = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
            svgGenerator.stream(out, useCSS);
        }
    } catch (org.apache.batik.svggen.SVGGraphics2DIOException e) {
        logger.log(Level.SEVERE, "Error creating svg document.", e);
    }
}
 
开发者ID:pdf4j,项目名称:icepdf,代码行数:45,代码来源:SVG.java

示例4: DocumentViewModelImpl

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
public DocumentViewModelImpl(Document document, JScrollPane parentScrollPane) {
    // construct abstract parent
    super(document);

    // load the page components into the layout
    PageViewComponentImpl pageViewComponentImpl = null;
    PageTree pageTree = document.getPageTree();
    int numberOfPages = document.getNumberOfPages();
    int avgPageWidth = 0;
    int avgPageHeight = 0;

    // add components for every page in the document
    pageComponents = new ArrayList<AbstractPageViewComponent>(numberOfPages);
    for (int i = 0; i < numberOfPages; i++) {
        // also a way to pass in an average document size.
        if (i < MAX_PAGE_SIZE_READ_AHEAD) {
            pageViewComponentImpl =
                    new PageViewComponentImpl(this, pageTree, i, parentScrollPane);
            avgPageWidth += pageViewComponentImpl.getPreferredSize().width;
            avgPageHeight += pageViewComponentImpl.getPreferredSize().height;
        } else if (i > MAX_PAGE_SIZE_READ_AHEAD) {
            pageViewComponentImpl =
                    new PageViewComponentImpl(this, pageTree, i,
                            parentScrollPane,
                            avgPageWidth, avgPageHeight);
        }
        // calculate average page size
        else if (i == MAX_PAGE_SIZE_READ_AHEAD) {
            avgPageWidth /= (MAX_PAGE_SIZE_READ_AHEAD);
            avgPageHeight /= (MAX_PAGE_SIZE_READ_AHEAD);
            pageViewComponentImpl =
                    new PageViewComponentImpl(this, pageTree, i,
                            parentScrollPane,
                            avgPageWidth, avgPageHeight);
        }
        pageComponents.add(pageViewComponentImpl);
    }
}
 
开发者ID:pdf4j,项目名称:icepdf,代码行数:39,代码来源:DocumentViewModelImpl.java

示例5: loadDocument

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
public void loadDocument(byte[] document, String name, String type) throws IOException { //have to be run from edt to prevent congruentmodification exception
    while (pagesPanel.getLock().isLocked()) {
        try {
            Thread.sleep(30);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    try {
        pagesPanel.removeAllPages();
        Document doc = new Document();
        doc.setByteArray(document, 0, document.length, "");
        int pageCount = doc.getNumberOfPages();
        int height = 0;
        for (int i = 0; i < pageCount; i++) {
            ScrollablePDPage spdpage = new ScrollablePDPage(doc, i, pagesPanel);
            height += spdpage.height + 10;
            pagesPanel.addPage(spdpage);
        }
        if (fitToView) {
            pagesPanel.fitPagesInViewWidth();
        } else {
            pagesPanel.scalePages(new Long(Math.round(pagesPanel.getZoomFactor() * 100d)).intValue());
        }
    } catch (Exception e) {
        throw new IOException("Exception during pdf-load! - " + e.getMessage());
    }
}
 
开发者ID:ruhr-universitaet-bochum,项目名称:jpdfsigner,代码行数:29,代码来源:JPodViewer.java

示例6: extractContent

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
private void extractContent(ParserResultItem result, Document pdf)
		throws IOException, InterruptedException {
	PInfo info = pdf.getInfo();
	if (info != null) {
		result.addField(ParserFieldEnum.title, info.getTitle());
		result.addField(ParserFieldEnum.subject, info.getSubject());
		result.addField(ParserFieldEnum.author, info.getAuthor());
		result.addField(ParserFieldEnum.producer, info.getProducer());
		result.addField(ParserFieldEnum.keywords, info.getKeywords());
		result.addField(ParserFieldEnum.creator, info.getCreator());
		result.addField(ParserFieldEnum.creation_date,
				info.getCreationDate());
		result.addField(ParserFieldEnum.modification_date,
				info.getModDate());
	}

	int pages = pdf.getNumberOfPages();
	result.addField(ParserFieldEnum.number_of_pages, pages);

	for (int page = 0; page < pages; page++) {
		PageText pageText = pdf.getPageText(page);
		if (pageText != null && pageText.getPageLines() != null) {
			List<LineText> lineTextArray = pageText.getPageLines();
			if (lineTextArray != null)
				for (LineText lineText : lineTextArray) {
					StringBuilder sb = new StringBuilder();
					List<WordText> words = lineText.getWords();
					if (words != null)
						for (WordText word : words)
							sb.append(word.getText());
					if (sb.length() > 0)
						result.addField(
								ParserFieldEnum.content,
								StringUtils.replaceConsecutiveSpaces(
										sb.toString(), " ").trim());
				}
		}
	}
	result.langDetection(10000, ParserFieldEnum.content);
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:41,代码来源:IcePdfParser.java

示例7: extractImagesForOCR

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
private void extractImagesForOCR(ParserResultItem result, Document pdf,
		LanguageEnum lang) throws IOException, SearchLibException,
		InterruptedException {
	OcrManager ocr = ClientCatalog.getOcrManager();
	if (ocr == null || ocr.isDisabled())
		return;
	HocrPdf hocrPdf = new HocrPdf();
	if (!getFieldMap().isMapped(ParserFieldEnum.ocr_content)
			&& !getFieldMap().isMapped(ParserFieldEnum.image_ocr_boxes))
		return;
	int emptyPageImages = 0;
	for (int i = 0; i < pdf.getNumberOfPages(); i++) {
		List<Image> images = pdf.getPageImages(i);
		if (images == null || images.size() == 0)
			continue;
		float rotation = pdf.getPageTree().getPage(i).getTotalRotation(0);
		BufferedImage image = ImageUtils.toBufferedImage(pdf.getPageImage(
				i, GraphicsRenderingHints.PRINT, Page.BOUNDARY_CROPBOX,
				0.0f, 4.0F));
		if (ImageUtils.checkIfManyColors(image)) {
			HocrPage hocrPage = hocrPdf.createPage(i, image.getWidth(),
					image.getHeight());
			hocrPage.addImage(imageOcr(image, 360 - rotation, lang, ocr));
		} else
			emptyPageImages++;
	}
	if (pdf.getNumberOfPages() > 0
			&& emptyPageImages == pdf.getNumberOfPages())
		throw new SearchLibException("All pages are blank "
				+ pdf.getNumberOfPages());
	if (getFieldMap().isMapped(ParserFieldEnum.image_ocr_boxes))
		hocrPdf.putHocrToParserField(result,
				ParserFieldEnum.image_ocr_boxes);
	if (getFieldMap().isMapped(ParserFieldEnum.ocr_content))
		hocrPdf.putTextToParserField(result, ParserFieldEnum.ocr_content);
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:37,代码来源:IcePdfParser.java

示例8: main

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
public static void main(String[] args) {

        if (args.length < 2) {
            System.out.println("At least two command line arguments must " +
                    "be specified. ");
            System.out.println("<filename> <term1> ... <termN>");
        }

        // Get a file from the command line to open
        String filePath = args[0];

        // get search terms from command line
        String[] terms = new String[args.length - 1];
        for (int i = 1, max = args.length; i < max; i++) {
            terms[i - 1] = args[i];
        }

        // build a component controller
        SwingController controller = new SwingController();

        SwingViewBuilder factory = new SwingViewBuilder(controller);

        JPanel viewerComponentPanel = factory.buildViewerPanel();

        JFrame applicationFrame = new JFrame();
        applicationFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        applicationFrame.getContentPane().add(viewerComponentPanel);

        // Now that the GUI is all in place, we can try opening the PDF
        controller.openDocument(filePath);

        // show the component
        applicationFrame.pack();
        applicationFrame.setVisible(true);

        /**
         * Start of a simple search for the loaded file
         */
        // get the search controller
        DocumentSearchController searchController =
                controller.getDocumentSearchController();
        // add a specified search terms.
        for (String term : terms) {
            searchController.addSearchTerm(term, false, false);
        }
        // search the pages in the document or a subset
        Document document = controller.getDocument();
        // list of founds words to print out
        ArrayList<WordText> foundWords;
        for (int pageIndex = 0; pageIndex < document.getNumberOfPages();
             pageIndex++) {
            foundWords = searchController.searchPage(pageIndex);
            System.out.println("Page " + pageIndex);
            if (foundWords != null) {
                for (WordText wordText : foundWords) {
                    System.out.println("    found hit: " + wordText.toString());
                }
            }
        }

    }
 
开发者ID:pdf4j,项目名称:icepdf,代码行数:62,代码来源:SearchController.java

示例9: install

import org.icepdf.core.pobjects.Document; //导入方法依赖的package包/类
/**
 * Installs the component key binding on the specified JComponent.
 *
 * @param controller      SwingController used by various keyboard commands
 * @param viewerContainer view container to add keyboard mappings too
 */
public static void install(final SwingController controller, final JComponent viewerContainer) {
    Action copyText = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Document document = controller.getDocument();
            DocumentViewController documentViewController =
                    controller.getDocumentViewController();
            if (document != null &&
                    controller.havePermissionToExtractContent() &&
                    !(documentViewController.getDocumentViewModel().isSelectAll() &&
                            document.getNumberOfPages() > 250)) {
                // get the text.
                StringSelection stringSelection = new StringSelection(
                        documentViewController.getSelectedText());
                Toolkit.getDefaultToolkit().getSystemClipboard().
                        setContents(stringSelection, null);
            } else {
                Runnable doSwingWork = new Runnable() {
                    public void run() {
                        org.icepdf.ri.util.Resources.showMessageDialog(
                                viewerContainer,
                                JOptionPane.INFORMATION_MESSAGE,
                                controller.getMessageBundle(),
                                "viewer.dialog.information.copyAll.title",
                                "viewer.dialog.information.copyAll.msg",
                                250);
                    }
                };
                SwingUtilities.invokeLater(doSwingWork);
            }
        }
    };

    // add copy text command to input map
    InputMap inputMap = viewerContainer.getInputMap(
            JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK),
            "copyText");
    viewerContainer.getActionMap().put("copyText",
            copyText);
}
 
开发者ID:pdf4j,项目名称:icepdf,代码行数:47,代码来源:ComponentKeyBinding.java


注:本文中的org.icepdf.core.pobjects.Document.getNumberOfPages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。