Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfDictionary


    preferences.setViewerPreferences(prefs);
    // other preferences
    obj = PdfReader.getPdfObjectRelease(catalog
        .get(PdfName.VIEWERPREFERENCES));
    if (obj != null && obj.isDictionary()) {
      PdfDictionary vp = (PdfDictionary) obj;
      for (int i = 0; i < VIEWER_PREFERENCES.length; i++) {
        obj = PdfReader.getPdfObjectRelease(vp.get(VIEWER_PREFERENCES[i]));
        preferences.addViewerPreference(VIEWER_PREFERENCES[i], obj);
      }
    }
    return preferences;
  }
View Full Code Here


    }
   
    public void completeExtraCatalog(PdfDictionary extraCatalog) {
        if (isPdfX() && !isPdfA1()) {
            if (extraCatalog.get(PdfName.OUTPUTINTENTS) == null) {
                PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT);
                out.put(PdfName.OUTPUTCONDITION, new PdfString("SWOP CGATS TR 001-1995"));
                out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("CGATS TR 001"));
                out.put(PdfName.REGISTRYNAME, new PdfString("http://www.color.org"));
                out.put(PdfName.INFO, new PdfString(""));
                out.put(PdfName.S, PdfName.GTS_PDFX);
                extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out));
            }
        }
    }
View Full Code Here

                        }
                        break;
                }
                break;
            case PDFXKEY_GSTATE:
                PdfDictionary gs = (PdfDictionary)obj1;
                PdfObject obj = gs.get(PdfName.BM);
                if (obj != null && !PdfGState.BM_NORMAL.equals(obj) && !PdfGState.BM_COMPATIBLE.equals(obj))
                    throw new PdfXConformanceException("Blend mode " + obj.toString() + " not allowed.");
                obj = gs.get(PdfName.CA);
                double v = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).doubleValue()) != 1.0)
                    throw new PdfXConformanceException("Transparency is not allowed: /CA = " + v);
                obj = gs.get(PdfName.ca);
                v = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).doubleValue()) != 1.0)
                    throw new PdfXConformanceException("Transparency is not allowed: /ca = " + v);
                break;
            case PDFXKEY_LAYER:
View Full Code Here

            else
                return PdfName.DEVICERGB;
        }
        else {
            PdfArray array = new PdfArray();
            PdfDictionary dic = new PdfDictionary();
            if ((colorType & 2) == 0) {
                if (gamma == 1f)
                    return PdfName.DEVICEGRAY;
                array.add(PdfName.CALGRAY);
                dic.put(PdfName.GAMMA, new PdfNumber(gamma));
                dic.put(PdfName.WHITEPOINT, new PdfLiteral("[1 1 1]"));
                array.add(dic);
            }
            else {
                PdfObject wp = new PdfLiteral("[1 1 1]");
                array.add(PdfName.CALRGB);
                if (gamma != 1f) {
                    PdfArray gm = new PdfArray();
                    PdfNumber n = new PdfNumber(gamma);
                    gm.add(n);
                    gm.add(n);
                    gm.add(n);
                    dic.put(PdfName.GAMMA, gm);
                }
                if (hasCHRM) {
                    float z = yW*((xG-xB)*yR-(xR-xB)*yG+(xR-xG)*yB);
                    float YA = yR*((xG-xB)*yW-(xW-xB)*yG+(xW-xG)*yB)/z;
                    float XA = YA*xR/yR;
                    float ZA = YA*((1-xR)/yR-1);
                    float YB = -yG*((xR-xB)*yW-(xW-xB)*yR+(xW-xR)*yB)/z;
                    float XB = YB*xG/yG;
                    float ZB = YB*((1-xG)/yG-1);
                    float YC = yB*((xR-xG)*yW-(xW-xG)*yW+(xW-xR)*yG)/z;
                    float XC = YC*xB/yB;
                    float ZC = YC*((1-xB)/yB-1);
                    float XW = XA+XB+XC;
                    float YW = 1;//YA+YB+YC;
                    float ZW = ZA+ZB+ZC;
                    PdfArray wpa = new PdfArray();
                    wpa.add(new PdfNumber(XW));
                    wpa.add(new PdfNumber(YW));
                    wpa.add(new PdfNumber(ZW));
                    wp = wpa;
                    PdfArray matrix = new PdfArray();
                    matrix.add(new PdfNumber(XA));
                    matrix.add(new PdfNumber(YA));
                    matrix.add(new PdfNumber(ZA));
                    matrix.add(new PdfNumber(XB));
                    matrix.add(new PdfNumber(YB));
                    matrix.add(new PdfNumber(ZB));
                    matrix.add(new PdfNumber(XC));
                    matrix.add(new PdfNumber(YC));
                    matrix.add(new PdfNumber(ZC));
                    dic.put(PdfName.MATRIX, matrix);
                }
                dic.put(PdfName.WHITEPOINT, wp);
                array.add(dic);
            }
            return array;
        }
    }
View Full Code Here

                    img = Image.getInstance(width, height, components, bpc, image);
            }
            else {
                img = new ImgRaw(width, height, components, bpc, idat.toByteArray());
                img.setDeflated(true);
                PdfDictionary decodeparms = new PdfDictionary();
                decodeparms.put(PdfName.BITSPERCOMPONENT, new PdfNumber(bitDepth));
                decodeparms.put(PdfName.PREDICTOR, new PdfNumber(15));
                decodeparms.put(PdfName.COLUMNS, new PdfNumber(width));
                decodeparms.put(PdfName.COLORS, new PdfNumber((colorType == 3 || (colorType & 2) == 0) ? 1 : 3));
                additional.put(PdfName.DECODEPARMS, decodeparms);
            }
            if (additional.get(PdfName.COLORSPACE) == null)
                additional.put(PdfName.COLORSPACE, getColorspace());
            if (intent != null)
View Full Code Here

     * @param ref the reference to the image dictionary
     * @throws BadElementException on error
     * @return the image
     */   
    public static Image getInstance(PRIndirectReference ref) throws BadElementException {
        PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref);
        int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue();
        int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue();
        Image imask = null;
        PdfObject obj = dic.get(PdfName.SMASK);
        if (obj != null && obj.isIndirect()) {
            imask = getInstance((PRIndirectReference)obj);
        }
        else {
            obj = dic.get(PdfName.MASK);
            if (obj != null && obj.isIndirect()) {
                PdfObject obj2 = PdfReader.getPdfObjectRelease(obj);
                if (obj2 instanceof PdfDictionary)
                    imask = getInstance((PRIndirectReference)obj);
            }
View Full Code Here

     * A content operator implementation (gs).
     */
    private static class ProcessGraphicsStateResource implements ContentOperator{
        public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
            PdfName dictionaryName = (PdfName)operands.get(0);
            PdfDictionary extGState = processor.resources.getAsDict(PdfName.EXTGSTATE);
            if (extGState == null)
                throw new IllegalArgumentException("Resources do not contain ExtGState entry. Unable to process operator " + operator);
            PdfDictionary gsDic = extGState.getAsDict(dictionaryName);
            if (gsDic == null)
                throw new IllegalArgumentException(dictionaryName + " is an unknown graphics state dictionary");
           
            // at this point, all we care about is the FONT entry in the GS dictionary
            PdfArray fontParameter = gsDic.getAsArray(PdfName.FONT);
            if (fontParameter != null){
                CMapAwareDocumentFont font = new CMapAwareDocumentFont((PRIndirectReference)fontParameter.getPdfObject(0));
                float size = fontParameter.getAsNumber(1).floatValue();
               
                processor.gs().font = font;
View Full Code Here

                maxPageNum = maxPage;
           
            for (int pageNum = 1; pageNum <= maxPageNum; pageNum++){
                System.out.println("==============Page " + pageNum + "====================");
                System.out.println("- - - - - Dictionary - - - - - -");
                PdfDictionary pageDictionary = reader.getPageN(pageNum);
                System.out.println(getDictionaryDetail(pageDictionary));
                System.out.println("- - - - - Content Stream - - - - - -");
                RandomAccessFileOrArray f = reader.getSafeFile();
               
                byte[] contentBytes = reader.getPageContent(pageNum, f);
View Full Code Here

    private static class SetTextFont implements ContentOperator{
        public void invoke(PdfContentStreamProcessor processor, PdfLiteral operator, ArrayList operands) {
            PdfName fontResourceName = (PdfName)operands.get(0);
            float size = ((PdfNumber)operands.get(1)).floatValue();
           
            PdfDictionary fontsDictionary = processor.resources.getAsDict(PdfName.FONT);
            CMapAwareDocumentFont font = new CMapAwareDocumentFont((PRIndirectReference)fontsDictionary.get(fontResourceName));
           
            processor.gs().font = font;
            processor.gs().fontSize = size;
           
        }
View Full Code Here

        PageRotation[] rotations = inputCommand.getRotations();
        if (rotations != null && rotations.length > 0) {
            if (rotations.length > 1) {
                for (int i = 0; i < rotations.length; i++) {
                    if (pdfNumberOfPages >= rotations[i].getPageNumber() && rotations[i].getPageNumber() > 0) {
                        PdfDictionary dictionary = rotationReader.getPageN(rotations[i].getPageNumber());
                        int rotation = (rotations[i].getDegrees() + rotationReader.getPageRotation(rotations[i]
                                .getPageNumber())) % 360;
                        dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
                    } else {
                        LOG.warn("Rotation for page " + rotations[i].getPageNumber() + " ignored.");
                    }
                }
            } else {
                // rotate all
                if (rotations[0].getType() == PageRotation.ALL_PAGES) {
                    int pageRotation = rotations[0].getDegrees();
                    for (int i = 1; i <= pdfNumberOfPages; i++) {
                        PdfDictionary dictionary = rotationReader.getPageN(i);
                        int rotation = (pageRotation + rotationReader.getPageRotation(i)) % 360;
                        dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
                    }
                } else if (rotations[0].getType() == PageRotation.SINGLE_PAGE) {
                    // single page rotation
                    if (pdfNumberOfPages >= rotations[0].getPageNumber() && rotations[0].getPageNumber() > 0) {
                        PdfDictionary dictionary = rotationReader.getPageN(rotations[0].getPageNumber());
                        int rotation = (rotations[0].getDegrees() + rotationReader.getPageRotation(rotations[0]
                                .getPageNumber())) % 360;
                        dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
                    } else {
                        LOG.warn("Rotation for page " + rotations[0].getPageNumber() + " ignored.");
                    }
                } else if (rotations[0].getType() == PageRotation.ODD_PAGES) {
                    // odd pages rotation
                    int pageRotation = rotations[0].getDegrees();
                    for (int i = 1; i <= pdfNumberOfPages; i = i + 2) {
                        PdfDictionary dictionary = rotationReader.getPageN(i);
                        int rotation = (pageRotation + rotationReader.getPageRotation(i)) % 360;
                        dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
                    }
                } else if (rotations[0].getType() == PageRotation.EVEN_PAGES) {
                    // even pages rotation
                    int pageRotation = rotations[0].getDegrees();
                    for (int i = 2; i <= pdfNumberOfPages; i = i + 2) {
                        PdfDictionary dictionary = rotationReader.getPageN(i);
                        int rotation = (pageRotation + rotationReader.getPageRotation(i)) % 360;
                        dictionary.put(PdfName.ROTATE, new PdfNumber(rotation));
                    }
                } else {
                    LOG.warn("Unable to find the rotation type. " + rotations[0]);
                }
            }
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfDictionary

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.