Package org.apache.pdfbox.pdmodel.interactive.annotation

Examples of org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream


                    widget.setAppearance(appearance);
                }

                PDAppearanceEntry normalAppearance = appearance.getNormalAppearance();
                // TODO support more than one appearance stream
                PDAppearanceStream appearanceStream =
                        normalAppearance.isStream() ? normalAppearance.getAppearanceStream() : null;
                if (appearanceStream == null)
                {
                    COSStream cosStream = acroForm.getDocument().getDocument().createCOSStream();
                    appearanceStream = new PDAppearanceStream(cosStream);
                    appearanceStream.setBBox(widget.getRectangle()
                            .createRetranslatedRectangle());
                    appearance.setNormalAppearance(appearanceStream);
                }

                List<Object> tokens = getStreamTokens(appearanceStream);
                List<Object> daTokens = getStreamTokens(getDefaultAppearance());
                PDFont pdFont = getFontAndUpdateResources(tokens, appearanceStream);

                if (!containsMarkedContent(tokens))
                {
                    ByteArrayOutputStream output = new ByteArrayOutputStream();
                    // BJL 9/25/2004 Must prepend existing stream
                    // because it might have operators to draw things like
                    // rectangles and such
                    ContentStreamWriter writer = new ContentStreamWriter(output);
                    writer.writeTokens(tokens);
                    output.write(" /Tx BMC\n".getBytes("ISO-8859-1"));
                    insertGeneratedAppearance(widget, output, pdFont, tokens, appearanceStream);
                    output.write(" EMC".getBytes("ISO-8859-1"));
                    writeToStream(output.toByteArray(), appearanceStream);
                }
                else
                {
                    if (tokens != null)
                    {
                        if (daTokens != null)
                        {
                            int bmcIndex = tokens.indexOf(Operator.getOperator("BMC"));
                            int emcIndex = tokens.indexOf(Operator.getOperator("EMC"));
                            if (bmcIndex != -1 && emcIndex != -1 && emcIndex == bmcIndex + 1)
                            {
                                // if the EMC immediately follows the BMC index then should
                                // insert the daTokens inbetween the two markers.
                                tokens.addAll(emcIndex, daTokens);
                            }
                        }
                        ByteArrayOutputStream output = new ByteArrayOutputStream();
                        ContentStreamWriter writer = new ContentStreamWriter(output);
                        float fontSize = calculateFontSize(pdFont,
                                appearanceStream.getBBox(), tokens, daTokens);
                        int setFontIndex = tokens.indexOf(Operator.getOperator("Tf"));
                        tokens.set(setFontIndex - 1, new COSFloat(fontSize));

                        int bmcIndex = tokens.indexOf(Operator.getOperator("BMC"));
                        int emcIndex = tokens.indexOf(Operator.getOperator("EMC"));
View Full Code Here


                                           PDSignatureField signatureField) throws IOException
    {
        PDAppearanceDictionary appearance = new PDAppearanceDictionary();
        appearance.getCOSObject().setDirect(true);

        PDAppearanceStream appearanceStream = new PDAppearanceStream(holderForml.getCOSStream());

        appearance.setNormalAppearance(appearanceStream);
        signatureField.getWidget().setAppearance(appearance);

        pdfStructure.setAppearanceDictionary(appearance);
View Full Code Here

                    // adjust the image to the target rectangle and add it to the stream
                    drawXObject(ximage, form.getResources(), os, lowerLeftX, lowerLeftY, imgWidth, imgHeight);
                    os.close();

                    PDAppearanceStream myDic = new PDAppearanceStream(form.getCOSStream());
                    PDAppearanceDictionary appearance = new PDAppearanceDictionary(new COSDictionary());
                    appearance.setNormalAppearance(myDic);
                    rubberStamp.setAppearance(appearance);
                    rubberStamp.setRectangle(rect);
View Full Code Here

     * @param annotation An annotation on the current page.
     * @throws IOException If an error occurred reading the annotation
     */
    public void showAnnotation(PDAnnotation annotation) throws IOException
    {
        PDAppearanceStream appearanceStream = getAppearance(annotation);
        if (appearanceStream != null)
        {
            processAnnotation(annotation, appearanceStream);
        }
    }
View Full Code Here

            // Set empty Appearance-Dictionary
            PDAppearanceDictionary ap = new PDAppearanceDictionary();

            COSStream apsStream = getDocument().createCOSStream();
            apsStream.createUnfilteredStream();
            PDAppearanceStream aps = new PDAppearanceStream(apsStream);
            COSDictionary cosObject = (COSDictionary) aps.getCOSObject();
            cosObject.setItem(COSName.SUBTYPE, COSName.FORM);
            cosObject.setItem(COSName.BBOX, new PDRectangle());

            ap.setNormalAppearance(aps);
            ap.getCOSObject().setDirect(true);
View Full Code Here

    private void testContentStreamContains( PDDocument doc, PDFieldTreeNode field, String expected ) throws Exception
    {
        PDAnnotationWidget widget = field.getWidget();
        PDAppearanceEntry normalAppearance = widget.getAppearance().getNormalAppearance();
        PDAppearanceStream appearanceStream = normalAppearance.getAppearanceStream();
        COSStream actual = appearanceStream.getCOSStream();

        List<Object> actualTokens = getStreamTokens( doc, actual );
        assertTrue( actualTokens.contains( new COSString( expected ) ) );
    }
View Full Code Here

    private void testContentStreams( PDDocument doc, PDFieldTreeNode field, String expected ) throws Exception
    {
        PDAnnotationWidget widget = field.getWidget();
        PDAppearanceEntry normalAppearance = widget.getAppearance().getNormalAppearance();
        PDAppearanceStream appearanceStream = normalAppearance.getAppearanceStream();
        COSStream actual = appearanceStream.getCOSStream();

        List<Object> actualTokens = getStreamTokens( doc, actual );
        List<Object> expectedTokens = getStreamTokens( doc, expected );
        assertEquals( actualTokens.size(), expectedTokens.size() );
        for( int i=0; i<actualTokens.size(); i++ )
View Full Code Here

                    appearanceName = "default";
                }
                Map<String, PDAppearanceStream> appearanceMap = appearDictionary.getNormalAppearance();
                if (appearanceMap != null)
                {
                    PDAppearanceStream appearance =
                        (PDAppearanceStream)appearanceMap.get( appearanceName );
                    if( appearance != null )
                    {
                        Point2D point = new Point2D.Float(rect.getLowerLeftX(), rect.getLowerLeftY());
                        Matrix matrix = appearance.getMatrix();
                        if (matrix != null)
                        {
                            // transform the rectangle using the given matrix
                            AffineTransform at = matrix.createAffineTransform();
                            at.transform(point, point);
                        }
                        g.translate( (int)point.getX(), -(int)point.getY() );
                        processSubStream( page, appearance.getResources(), appearance.getStream() );
                        g.translate( -(int)point.getX(), (int)point.getY() );
                    }
                }
            }
        }
View Full Code Here

                    appearance = new PDAppearanceDictionary();
                    widget.setAppearance( appearance );
                }

                Map normalAppearance = appearance.getNormalAppearance();
                PDAppearanceStream appearanceStream = (PDAppearanceStream)normalAppearance.get( "default" );
                if( appearanceStream == null )
                {
                    COSStream cosStream = acroForm.getDocument().getDocument().createCOSStream();
                    appearanceStream = new PDAppearanceStream( cosStream );
                    appearanceStream.setBoundingBox( widget.getRectangle().createRetranslatedRectangle() );
                    appearance.setNormalAppearance( appearanceStream );
                }

                List tokens = getStreamTokens( appearanceStream );
                List daTokens = getStreamTokens( getDefaultAppearance() );
                PDFont pdFont = getFontAndUpdateResources( tokens, appearanceStream );

                if (!containsMarkedContent( tokens ))
                {
                    ByteArrayOutputStream output = new ByteArrayOutputStream();

                    //BJL 9/25/2004 Must prepend existing stream
                    //because it might have operators to draw things like
                    //rectangles and such
                    ContentStreamWriter writer = new ContentStreamWriter( output );
                    writer.writeTokens( tokens );

                    output.write( " /Tx BMC\n".getBytes("ISO-8859-1") );
                    insertGeneratedAppearance( widget, output, pdFont, tokens, appearanceStream );
                    output.write( " EMC".getBytes("ISO-8859-1") );
                    writeToStream( output.toByteArray(), appearanceStream );
                }
                else
                {
                    if( tokens != null )
                    {
                        if( daTokens != null )
                        {
                            int bmcIndex = tokens.indexOf( PDFOperator.getOperator( "BMC" ));
                            int emcIndex = tokens.indexOf( PDFOperator.getOperator( "EMC" ));
                            if( bmcIndex != -1 && emcIndex != -1 &&
                                emcIndex == bmcIndex+1 )
                            {
                                //if the EMC immediately follows the BMC index then should
                                //insert the daTokens inbetween the two markers.
                                tokens.addAll( emcIndex, daTokens );
                            }
                        }
                        ByteArrayOutputStream output = new ByteArrayOutputStream();
                        ContentStreamWriter writer = new ContentStreamWriter( output );
                        float fontSize = calculateFontSize( pdFont, appearanceStream.getBoundingBox(), tokens, null );
                        boolean foundString = false;
                        for( int i=0; i<tokens.size(); i++ )
                        {
                            if( tokens.get( i ) instanceof COSString )
                            {
View Full Code Here

            acroFormDict.setItem(COSName.DR, null);
            // Set empty Appearance-Dictionary
            PDAppearanceDictionary ap = new PDAppearanceDictionary();
            COSStream apsStream = getDocument().createCOSStream();
            apsStream.createUnfilteredStream();
            PDAppearanceStream aps = new PDAppearanceStream(apsStream);
            COSDictionary cosObject = (COSDictionary)aps.getCOSObject();
            cosObject.setItem(COSName.SUBTYPE, COSName.FORM);
            cosObject.setItem(COSName.BBOX, new PDRectangle());
           
            ap.setNormalAppearance(aps);
            ap.getDictionary().setDirect(true);
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream

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.