Package org.apache.fop.pdf

Examples of org.apache.fop.pdf.PDF3DStream


     * @return 3D stream object
     * @throws IOException
     */
    public PDF3DStream get3DStreamObject(String fileName, boolean forceEmbedding)
            throws IOException {
        PDF3DStream stream = null;
        if (!forceEmbedding && stream3DMap.containsKey(fileName)) {
            stream = (PDF3DStream) stream3DMap.get(fileName);
        } else {
            String testFileName = fileName.trim().toLowerCase();
            if (testFileName.endsWith(".u3d")) {
                stream = getFO3DDocument().getFO3DFactory().makeU3DStream();
            } else if (testFileName.endsWith(".prc")) {
                stream = getFO3DDocument().getFO3DFactory().makePRCStream();
            }
            if (stream == null) {
                throw new IOException("Only *.u3d or *.prc files are "
                        + "supported for PDF 3D streams.");
            }

            IOUtil.readFile(getUserAgent(), fileName, stream
                .getBufferOutputStream());
            stream3DMap.put(fileName, stream);
        }
        return stream;
    }
View Full Code Here


        ImageBuffered img = new ImageBuffered(imgInfo, bi, null);
        PDFImage pdfimage = new ImageRenderedAdapter(img, resName);
        PDFXObject xobj = pdfDoc.addImage(resContext, pdfimage);

        PDF3DStream stream = annot.getStreamSafely();
        stream.addResource(resName, xobj);

        // load JavaScript library code once (per 3D stream)
        // this is because the DOM element could exist multiple times within
        // the extension section.
        if (!libLoadedList.contains(stream.referencePDF())) {
            stream.addJSCode(getLibJSCode());
            libLoadedList.add(stream.referencePDF());
        }

        // Add JavaScript code for initializing a new textsprite
        stream.addJSCode("\naddTextSprite('"
            + JavaScriptUtil.escapeString(resName)
            + "',"
            + pos.toPDF3DJSString()
            + (intDest.length() > 0 ? ",'"
                    + JavaScriptUtil.escapeString(intDest) + "'" : "")
View Full Code Here

        boolean forceEmbedding = DOMUtil.getBooleanAttribute(root,
            "force-embedding", false);

        // Builds a new 3D stream object or returns an existing one from the
        // streamMap
        PDF3DStream stream = renderer.get3DStreamObject(fileName,
            forceEmbedding);

        // Add predefined views to 3D stream (if present in DOM)
        handleViews(root, stream);
View Full Code Here

        }

        // get 3d annotation links
        List links = DOMUtil.getChildElementsByTagName(el, "link");
        if (links.size() > 0) {
            PDF3DStream stream = annot.getStreamSafely();

            FO3DPDFRenderer renderer = (FO3DPDFRenderer) context.getRenderer();
            PDFObject resource = renderer.add3DResourceStream(getClass()
                .getResource(ANNOT_MODEL_FILE).toExternalForm());
            stream.addResource(ANNOT_RESOURCE_NAME, resource);

            // load JavaScript library code once (per 3D stream)
            // this is because the DOM element could exist multiple times within
            // the extension section.
            if (!libLoadedList.contains(stream.referencePDF())) {
                stream.addJSCode(getLibJSCode());
                libLoadedList.add(stream.referencePDF());
            }

            Double scale;
            Color color;
            Vector3 pos;
            String destination;
            for (Iterator it = links.iterator(); it.hasNext();) {
                Element link = (Element) it.next();

                // Link destination
                destination = DOMUtil.getAttribute(link, "href", true);

                // Link position
                pos = DOMUtil.get3DVectorAttribute(link, "at", true);

                // Link color
                color = defColor;
                arg = DOMUtil.getAttribute(link, "color");
                if (arg.length() > 0) {
                    color = ColorUtil.parseColorString(context.getUserAgent(),
                        arg);
                }

                // Link scale
                scale = defScale;
                arg = DOMUtil.getAttribute(link, "scale");
                if (arg.length() > 0) {
                    scale = new Double(arg);
                }

                // add JavaScript code for initializing the 3d link annotation
                stream.addJSCode("\nadd3DLinkAnnotation('"
                        + ANNOT_RESOURCE_NAME + "'," + pos.toPDF3DJSString()
                        + ",'" + destination + "'," + scale + ",new Color("
                        + (color.getRed() / 255d) + ","
                        + (color.getGreen() / 255d) + ","
                        + (color.getBlue() / 255d) + "));");
            }

            // This is a workaround, because Acrobat changes the scene and
            // view settings when we add a new model resource.
            // This should be removed if we have another solution within the
            // JavaScript file.
            stream.addJSCode("\nreInitView(" + stream.getDefaultViewIndex()
                    + ");");
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.fop.pdf.PDF3DStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.