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

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

Introduction

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

Prototype

PdfName TYPE

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

Click Source Link

Document

A name

Usage

From source file:org.kuali.coeus.propdev.impl.s2s.S2sUserAttachedFormServiceImpl.java

License:Open Source License

/**
 * Unpacks a file attachment.//  w w w .  j  a v  a  2s.  c o  m
 * @param filespec
 *            The dictonary containing the file specifications
 * @throws IOException
 */
private Object[] unpackFile(PdfDictionary filespec) throws IOException {

    if (filespec == null)
        return null;

    PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE));

    if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type))
        return null;

    PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF));
    if (ef == null)
        return null;

    PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F));
    if (fn == null)
        return null;

    File fLast = new File(fn.toUnicodeString());

    PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F));
    if (prs == null)
        return null;

    byte attachmentByte[] = PdfReader.getStreamBytes(prs);
    Object[] fileInfo = new Object[2];
    fileInfo[0] = fLast.getName();
    fileInfo[1] = attachmentByte;
    return fileInfo;
}

From source file:org.kuali.kra.s2s.service.impl.S2SUserAttachedFormServiceImpl.java

License:Educational Community License

/**
 * Unpacks a file attachment.//from   ww  w  . ja  va2 s . c  om
 *
 * @param reader
 *            The object that reads the PDF document
 * @param filespec
 *            The dictonary containing the file specifications
 * @throws IOException
 */
private Object[] unpackFile(PdfReader reader, PdfDictionary filespec) throws IOException {
    S2sUserAttachedFormAtt userAttachedS2SFormAttachmentBean = new S2sUserAttachedFormAtt();

    if (filespec == null)
        return null;

    PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE));

    if (!PdfName.F.equals(type) && !PdfName.FILESPEC.equals(type))
        return null;

    PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF));
    if (ef == null)
        return null;

    PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F));
    if (fn == null)
        return null;

    File fLast = new File(fn.toUnicodeString());

    PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F));
    if (prs == null)
        return null;

    byte attachmentByte[] = PdfReader.getStreamBytes(prs);
    Object[] fileInfo = new Object[2];
    fileInfo[0] = fLast.getName();
    fileInfo[1] = attachmentByte;
    return fileInfo;
}

From source file:org.pdfsam.console.business.pdf.handlers.UnpackCmdExecutor.java

License:Open Source License

/**
 * Unpack/* w  w w.j  a  v a  2s .  c  o m*/
 * @param filespec the dictionary
 * @param outPath output directory
 * @param overwrite if true overwrite if already exists
 * @return number of unpacked files
 * @throws IOException
 */
private int unpackFile(PdfDictionary filespec, File outPath, boolean overwrite) throws IOException {
    int retVal = 0;
    if (filespec != null) {
        PdfName type = (PdfName) PdfReader.getPdfObject(filespec.get(PdfName.TYPE));
        if (PdfName.F.equals(type) || PdfName.FILESPEC.equals(type)) {
            PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(filespec.get(PdfName.EF));
            PdfString fn = (PdfString) PdfReader.getPdfObject(filespec.get(PdfName.F));
            if (fn != null && ef != null) {
                LOG.debug("Unpacking file " + fn + " to " + outPath);
                File fLast = new File(fn.toUnicodeString());
                File fullPath = new File(outPath, fLast.getName());
                if (fullPath.exists()) {
                    //check if overwrite is allowed
                    if (overwrite) {
                        if (!fullPath.delete()) {
                            LOG.warn("Unable to overwrite " + fullPath.getAbsolutePath()
                                    + ", unable to unpack.");
                        }
                    } else {
                        LOG.warn("Cannot overwrite " + fullPath.getAbsolutePath()
                                + " (overwrite is false), unable to unpack.");
                    }
                } else {
                    PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F));
                    if (prs != null) {
                        byte b[] = PdfReader.getStreamBytes(prs);
                        FileOutputStream fout = new FileOutputStream(fullPath);
                        fout.write(b);
                        fout.close();
                        retVal = 1;
                    }
                }
            }
        }
    }
    return retVal;
}

From source file:org.sejda.impl.itext.component.PdfUnpacker.java

License:Apache License

private void unpack(Set<PdfDictionary> dictionaries) throws TaskIOException {
    for (PdfDictionary dictionary : dictionaries) {
        PdfName type = (PdfName) PdfReader.getPdfObject(dictionary.get(PdfName.TYPE));
        if (PdfName.F.equals(type) || PdfName.FILESPEC.equals(type)) {
            PdfDictionary ef = (PdfDictionary) PdfReader.getPdfObject(dictionary.get(PdfName.EF));
            PdfString fn = (PdfString) PdfReader.getPdfObject(dictionary.get(PdfName.F));
            if (fn != null && ef != null) {
                PRStream prs = (PRStream) PdfReader.getPdfObject(ef.get(PdfName.F));
                if (prs != null) {
                    File tmpFile = copyToTemporaryFile(prs);
                    outputWriter.addOutput(file(tmpFile).name(fn.toUnicodeString()));
                }//  w w  w.ja v a 2 s . com
            }
        }
    }
}

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  va  2  s.c  o m*/
        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();
}