Example usage for com.lowagie.text.pdf PdfName S

List of usage examples for com.lowagie.text.pdf PdfName S

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfName S.

Prototype

PdfName S

To view the source code for com.lowagie.text.pdf PdfName S.

Click Source Link

Document

A name

Usage

From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFManager.java

License:Apache License

/**
 * Creates the pdf writer./*w ww. ja v a  2 s .  c  om*/
 * 
 * @param out the out
 * @param writer the writer
 * @param pdfdoc the pdfdoc
 * 
 * @return the pdf writer
 * 
 * @throws PDFManagerException the PDF manager exception
 */
private PdfWriter createPDFWriter(OutputStream out, Document pdfdoc) throws PDFManagerException {
    PdfWriter writer = null;
    try {
        // open the pdfwriter using the outstream
        writer = PdfWriter.getInstance(pdfdoc, out);
        LOGGER.debug("PDFWriter intstantiated");

        // register Fonts
        int numoffonts = FontFactory.registerDirectories();

        LOGGER.debug(numoffonts + " fonts found and registered!");

        if ((pdfa) && (iccprofile != null)) {
            // we want to write PDFA, we have to set the PDFX conformance
            // before we open the writer
            writer.setPDFXConformance(PdfWriter.PDFA1B);
        }

        // open the pdf document to add pages and other content
        try {
            pdfdoc.open();
            LOGGER.debug("PDFDocument opened");
        } catch (Exception e) {
            throw new PDFManagerException("PdfWriter was opened, but the pdf document couldn't be opened", e);
        }

        if ((pdfa) && (iccprofile != null)) {

            // set the required PDFDictionary which
            // contains the appropriate ICC profile
            PdfDictionary pdfdict_out = new PdfDictionary(PdfName.OUTPUTINTENT);

            // set identifier for ICC profile
            pdfdict_out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGBIEC61966-2.1"));
            pdfdict_out.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
            pdfdict_out.put(PdfName.S, PdfName.GTS_PDFA1);

            // PdfICCBased ib = new PdfICCBased(iccprofile);
            // writer.setOutputIntents("Custom", "PDF/A sRGB", null, "PDF/A
            // sRGB ICC Profile, sRGB_IEC61966-2-1_withBPC.icc",
            // colorProfileData);

            // read icc profile
            // ICC_Profile icc = ICC_Profile.getInstance(new
            // FileInputStream("c:\\srgb.profile"));
            PdfICCBased ib = new PdfICCBased(iccprofile);
            ib.remove(PdfName.ALTERNATE);

            PdfIndirectObject pio = writer.addToBody(ib);
            pdfdict_out.put(PdfName.DESTOUTPUTPROFILE, pio.getIndirectReference());
            writer.getExtraCatalog().put(PdfName.OUTPUTINTENTS, new PdfArray(pdfdict_out));

            // create MarkInfo elements
            // not sure this is necessary; maybe just needed for tagged PDFs
            // (PDF/A 1a)
            PdfDictionary markInfo = new PdfDictionary(PdfName.MARKINFO);
            markInfo.put(PdfName.MARKED, new PdfBoolean("false"));
            writer.getExtraCatalog().put(PdfName.MARKINFO, markInfo);

            // write XMP
            this.writeXMPMetadata(writer);
        }
    } catch (Exception e) {
        LOGGER.error("Can't open the PdfWriter object\n" + e.toString() + "\n" + e.getMessage());
        throw new PDFManagerException("Can't open the PdfWriter object", e);
    }
    return writer;
}

From source file:it.flavianopetrocchi.jpdfbookmarks.itextbookmarksconverter.iTextBookmarksConverter.java

License:Open Source License

private void setActionInBookmark(Bookmark bookmark, PdfDictionary action) {
    PdfObject dest;//from www  . j  a  v  a 2s  . com
    if (PdfName.GOTO.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        dest = PdfReader.getPdfObjectRelease(action.get(PdfName.D));
        if (dest != null) {
            mapGotoBookmark(bookmark, dest);
        }
    } else if (PdfName.URI.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        bookmark.setType(BookmarkType.Uri);
        bookmark.setUri(((PdfString) PdfReader.getPdfObjectRelease(action.get(PdfName.URI))).toUnicodeString());
    } else if (PdfName.GOTOR.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        bookmark.setRemoteDestination(true);
        PdfObject file = PdfReader.getPdfObjectRelease(action.get(PdfName.F));
        if (file != null) {
            if (file.isString()) {
                String path = Ut.onWindowsReplaceBackslashWithSlash(((PdfString) file).toUnicodeString());
                bookmark.setRemoteFilePath(path);
            } else if (file.isDictionary()) {
                file = PdfReader.getPdfObject(((PdfDictionary) file).get(PdfName.F));
                if (file.isString()) {
                    bookmark.setRemoteFilePath(((PdfString) file).toUnicodeString());
                }
            }
        }
        dest = PdfReader.getPdfObjectRelease(action.get(PdfName.D));
        if (dest != null) {
            if (dest.isString()) {
                bookmark.setNamedDestination(dest.toString());
            } else if (dest.isName()) {
                bookmark.setNamedDestination(PdfName.decodeName(dest.toString()));
                bookmark.setNamedAsName(true);
            } else if (dest.isArray()) {
                PdfArray arr = (PdfArray) dest;
                PdfReader remoteReader;
                try {
                    //                        File remoteFile = new File(bookmark.getRemoteFilePath());
                    //                        if (!remoteFile.isAbsolute()) {
                    //                            File openedFile = new File(filePath);
                    //                            String containingFolder = openedFile.getParent();
                    //                            String remotePath = containingFolder + File.separator + bookmark.getRemoteFilePath();
                    //                            remoteFile = new File(remotePath);
                    //                        }
                    File remoteFile = Ut.createAbsolutePath(new File(filePath),
                            new File(bookmark.getRemoteFilePath()));
                    remoteReader = new PdfReader(remoteFile.getCanonicalPath());
                    makeBookmarkParam(remoteReader, bookmark, arr, null);
                    remoteReader.close();
                } catch (IOException ex) {
                    //System.out.println(ex.getMessage());
                } finally {
                }
            }
        }
        PdfObject newWindow = PdfReader.getPdfObjectRelease(action.get(PdfName.NEWWINDOW));
        if (newWindow != null) {
            bookmark.setNewWindow(((PdfBoolean) newWindow).booleanValue());
        }
    } else if (PdfName.LAUNCH.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        bookmark.setType(BookmarkType.Launch);
        PdfObject file = PdfReader.getPdfObjectRelease(action.get(PdfName.F));
        if (file == null) {
            file = PdfReader.getPdfObjectRelease(action.get(PdfName.WIN));
        }
        if (file != null) {
            if (file.isString()) {
                bookmark.setFileToLaunch(((PdfString) file).toUnicodeString());
            } else if (file.isDictionary()) {
                file = PdfReader.getPdfObjectRelease(((PdfDictionary) file).get(PdfName.F));
                if (file.isString()) {
                    bookmark.setFileToLaunch(((PdfString) file).toUnicodeString());
                }
            }
        }
    } else if (PdfName.HIDE.equals(PdfReader.getPdfObjectRelease(action.get(PdfName.S)))) {
        bookmark.setType(BookmarkType.Hide);
        PdfObject annotation = PdfReader.getPdfObjectRelease(action.get(PdfName.T));
        if (annotation != null) {
            if (annotation.isDictionary()) {
            } else if (annotation.isArray()) {
            } else if (annotation.isString()) {
                bookmark.setFieldNameToHide(((PdfString) annotation).toUnicodeString());
            }
        }
        PdfBoolean hide = (PdfBoolean) PdfReader.getPdfObjectRelease(action.get(PdfName.H));
        if (hide != null) {
            bookmark.setHide(hide.booleanValue());
        }
    } else {
        bookmark.setType(BookmarkType.Unknown);
    }
}

From source file:net.sf.sze.service.impl.converter.PdfConverterImpl.java

License:GNU General Public License

/**
 * Put PDF-A-Infos to the document.//from w ww  .  j a  v  a2s  .  co  m
 * @param writer the pdf-writer.
 * @throws IOException IOException.
 */
private void addPdfAInfosToDictonary(PdfWriter writer) throws IOException {
    PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
    outi.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
    outi.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
    outi.put(PdfName.S, PdfName.GTS_PDFA1);

    ICC_Profile icc = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
    PdfICCBased ib = new PdfICCBased(icc);
    ib.remove(PdfName.ALTERNATE);
    outi.put(PdfName.DESTOUTPUTPROFILE, writer.addToBody(ib).getIndirectReference());
    writer.getExtraCatalog().put(PdfName.OUTPUTINTENTS, new PdfArray(outi));
}

From source file:org.areasy.common.doclet.document.tags.TagA.java

License:Open Source License

public Element toElement(String text) {
    String addr = getAttribute("href");

    if (addr == null || !DefaultConfiguration.isLinksCreationActive())
        addr = "";
    if (!isPre())
        text = DocletUtility.stripLineFeeds(text);

    Element aChunk;/*from ww w .j  a v  a2s. co m*/
    if (addr.startsWith("locallink")) {
        boolean plainText = addr.startsWith("locallinkplain");
        String dest = addr.substring(addr.indexOf(':') + 1).trim();

        setCode(!plainText);

        return new LinkPhrase(dest, text, Math.max(9, (int) getFont().size()), plainText);
    } else if (addr.equalsIgnoreCase("newpage"))
        return super.toElement(text);
    else if (addr.startsWith("http://") || addr.startsWith("https://")) {
        try {
            URL url = new URL(addr);
            return new Chunk(text, getFont()).setAnchor(url);
        } catch (MalformedURLException e) {
            log.error("Malformed URL: " + addr);
        }
    } else {
        String fileName = addr.trim();
        String anchorName = "";

        int hashIndex = addr.indexOf('#');

        if (hashIndex >= 0) {
            fileName = addr.substring(0, hashIndex).trim();
            anchorName = addr.substring(hashIndex + 1).trim();
        }

        boolean isLocalAnchor = (fileName.length() == 0 && anchorName.length() > 0);
        File file = null;

        try {
            if (fileName.length() > 0)
                file = new File(DocletUtility.getFilePath(fileName));
            else
                file = State.getCurrentFile();
        } catch (FileNotFoundException e) {
            log.debug("Could not find linked file " + fileName);
        }

        if (isLocalAnchor || Destinations.isValidDestinationFile(file)) {
            String fullAnchor = Destinations.createAnchorDestination(file, anchorName);

            PdfAction action = new PdfAction("", "");
            action.remove(PdfName.F);
            action.put(PdfName.S, PdfName.GOTO);
            action.put(PdfName.D, new PdfString(fullAnchor));

            aChunk = new Phrase();

            Chunk chunk = createChunk(text);
            ((Phrase) aChunk).add(chunk.setAction(action));

            return aChunk;
        }
    }

    if (getAttribute("name") != null)
        setLink(false); // no underline for anchors

    Font font = getFont();
    font.setColor(0, 0, 0);

    aChunk = new Chunk(text, font);

    setLink(false);

    return aChunk;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java

License:Open Source License

private PdfAction createActionForLink(final String target) {
    if (StringUtils.isEmpty(target)) {
        return null;
    }/* w w w  .  ja  va 2s.c  o m*/
    final PdfAction action = new PdfAction();
    if (target.startsWith("#")) {
        // its a local link ..
        action.put(PdfName.S, PdfName.GOTO);
        action.put(PdfName.D, new PdfString(target.substring(1)));
    } else {
        action.put(PdfName.S, PdfName.URI);
        action.put(PdfName.URI, new PdfString(target));
    }
    return action;
}

From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java

License:Open Source License

private void processLink(RenderingContext c, Box box) {
    Element elem = box.getElement();
    if (elem != null) {
        NamespaceHandler handler = _sharedContext.getNamespaceHandler();
        String uri = handler.getLinkUri(elem);
        if (uri != null) {
            if (uri.length() > 1 && uri.charAt(0) == '#') {
                String anchor = uri.substring(1);
                Box target = _sharedContext.getBoxById(anchor);
                if (target != null) {
                    PdfDestination dest = createDestination(c, target);

                    if (dest != null) {
                        PdfAction action = new PdfAction();
                        if (!"".equals(handler.getAttributeValue(elem, "onclick"))) {
                            action = PdfAction.javaScript(handler.getAttributeValue(elem, "onclick"), _writer);
                        } else {
                            action.put(PdfName.S, PdfName.GOTO);
                            action.put(PdfName.D, dest);
                        }/*from   ww w .  j  a  v  a  2s . co  m*/

                        com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
                        if (targetArea == null) {
                            return;
                        }

                        targetArea.setBorder(0);
                        targetArea.setBorderWidth(0);

                        PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(),
                                targetArea.getBottom(), targetArea.getRight(), targetArea.getTop(), action);
                        annot.put(PdfName.SUBTYPE, PdfName.LINK);
                        annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0));
                        annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0));
                        _writer.addAnnotation(annot);
                    }
                }
            } else if (uri.indexOf("://") != -1) {
                PdfAction action = new PdfAction(uri);

                com.lowagie.text.Rectangle targetArea = checkLinkArea(c, box);
                if (targetArea == null) {
                    return;
                }
                PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(),
                        targetArea.getRight(), targetArea.getTop(), action);
                annot.put(PdfName.SUBTYPE, PdfName.LINK);

                annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0));
                annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0));
                _writer.addAnnotation(annot);
            }
        }
    }
}

From source file:questions.images.TransparentEllipse2.java

public static void main(String[] args) {

    Document document = new Document(PageSize.POSTCARD);
    try {//from  w w  w . ja  v a 2 s. c  om
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        // clipped image
        cb.ellipse(1, 1, PageSize.POSTCARD.getWidth() - 2, PageSize.POSTCARD.getHeight() - 2);
        cb.clip();
        cb.newPath();
        Image img = Image.getInstance(RESOURCE);
        img.scaleToFit(PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());
        cb.addImage(img, PageSize.POSTCARD.getWidth(), 0, 0, PageSize.POSTCARD.getHeight(), 0, 0);

        //Prepare gradation list
        int gradationStep = 40;
        float[] gradationRatioList = new float[gradationStep];
        for (int i = 0; i < gradationStep; i++) {
            gradationRatioList[i] = 1 - (float) Math.sin(Math.toRadians(90.0f / gradationStep * (i + 1)));
        }

        //Create template
        PdfTemplate template = cb.createTemplate(PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());

        //Prepare transparent group
        PdfTransparencyGroup transGroup = new PdfTransparencyGroup();
        transGroup.put(PdfName.CS, PdfName.DEVICEGRAY);
        transGroup.setIsolated(true);
        transGroup.setKnockout(false);
        template.setGroup(transGroup);

        //Prepare graphic state
        PdfGState gState = new PdfGState();
        PdfDictionary maskDict = new PdfDictionary();
        maskDict.put(PdfName.TYPE, PdfName.MASK);
        maskDict.put(PdfName.S, new PdfName("Luminosity"));
        maskDict.put(new PdfName("G"), template.getIndirectReference());
        gState.put(PdfName.SMASK, maskDict);
        cb.setGState(gState);

        //Create gradation for mask
        for (int i = 1; i < gradationStep + 1; i++) {
            template.setLineWidth(gradationStep + 1 - i);
            template.setGrayStroke(gradationRatioList[gradationStep - i]);
            template.ellipse(0, 0, PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());
            template.stroke();
        }

        //Place template
        cb.addTemplate(template, 0, 0);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    document.close();
}

From source file:questions.markedcontent.ObjectData.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A5.rotate());
    try {//ww w . jav  a 2s  .  c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setTagged();

        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfStructureTreeRoot tree = writer.getStructureTreeRoot();
        PdfStructureElement se = new PdfStructureElement(tree, new PdfName("Figure"));
        PdfStructureElement element = new PdfStructureElement(se, new PdfName("Element"));
        PdfDictionary userproperties = new PdfDictionary();
        userproperties.put(PdfName.O, PdfName.USERPROPERTIES);
        userproperties.put(PdfName.S, new PdfName("Figure"));
        PdfArray properties = new PdfArray();
        PdfDictionary property1 = new PdfDictionary();
        property1.put(PdfName.N, new PdfString("Name1"));
        property1.put(PdfName.V, new PdfString("Value1"));
        properties.add(property1);
        PdfDictionary property2 = new PdfDictionary();
        property2.put(PdfName.N, new PdfString("Name2"));
        property2.put(PdfName.V, new PdfString("Value2"));
        properties.add(property2);
        PdfDictionary property3 = new PdfDictionary();
        property3.put(PdfName.N, new PdfString("Name3"));
        property3.put(PdfName.V, new PdfString("Value3"));
        properties.add(property3);
        userproperties.put(PdfName.P, properties);
        element.put(PdfName.A, userproperties);

        PdfLayer lay1 = new PdfLayer("My object", writer);

        cb.beginMarkedContentSequence(element);
        cb.beginLayer(lay1);
        cb.setColorFill(Color.BLUE);
        cb.rectangle(50, 50, 200, 200);
        cb.fill();
        cb.endLayer();
        cb.endMarkedContentSequence();

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    document.close();

}