Example usage for com.lowagie.text DocumentException DocumentException

List of usage examples for com.lowagie.text DocumentException DocumentException

Introduction

In this page you can find the example usage for com.lowagie.text DocumentException DocumentException.

Prototype

public DocumentException(String message) 

Source Link

Document

Constructs a DocumentException with a message.

Usage

From source file:it.pdfsam.console.tools.pdf.writers.PdfCopyFieldsConcatenator.java

License:Open Source License

public void addDocument(PdfReader reader, String ranges) throws Exception {
    if (reader != null) {
        reader.selectPages(ranges);//  w  w  w  . java2  s.  co  m
        writer.addDocument(reader);
    } else {
        throw new DocumentException("Reader is null");
    }
}

From source file:it.pdfsam.console.tools.pdf.writers.PdfCopyFieldsConcatenator.java

License:Open Source License

public void addDocument(PdfReader reader) throws Exception {
    if (reader != null) {
        writer.addDocument(reader);//from  w  ww.  j a va2s. co  m
    } else {
        throw new DocumentException("Reader is null");
    }
}

From source file:it.pdfsam.console.tools.pdf.writers.PdfSimpleConcatenator.java

License:Open Source License

public void addDocument(PdfReader reader, String ranges) throws Exception {
    if (reader != null) {
        reader.selectPages(ranges);//w  w w.  jav a2  s.  co m
        addDocument(reader);
    } else {
        throw new DocumentException("Reader is null");
    }
}

From source file:it.pdfsam.console.tools.pdf.writers.PdfSimpleConcatenator.java

License:Open Source License

public void addDocument(PdfReader reader) throws Exception {
    if (reader != null) {
        int numPages = reader.getNumberOfPages();
        for (int count = 1; count <= numPages; count++) {
            writer.addPage(writer.getImportedPage(reader, count));
        }/* w w  w.j a v a 2  s  .  co  m*/
    } else {
        throw new DocumentException("Reader is null");
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.NameRequest.java

License:Open Source License

public ActionForward resolve(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        final HttpServletResponse httpServletResponse) throws Exception {

    String digest = Hashing.sha1().hashString(storedPassword, Charsets.UTF_8).toString();
    String providedUsername = request.getParameter("username");
    String providedDigest = request.getParameter("password");

    if (storedUsername.equals(providedUsername) && digest.equals(providedDigest)) {
        String id = request.getParameter("id");
        User user = User.findByUsername(id);

        String name = user.getPerson().getName();
        String nickName = user.getPerson().getNickname();
        httpServletResponse.setHeader("Content-Type", "application/json; charset=" + CharEncoding.UTF_8);
        String message = "{\n" + "\"name\" : \"" + name + "\",\n" + "\"nickName\" : \"" + nickName + "\"\n"
                + "}";
        httpServletResponse.getOutputStream().write(message.getBytes(CharEncoding.UTF_8));
        httpServletResponse.getOutputStream().close();
        return null;

    } else {/*www. ja v  a  2 s .co  m*/
        throw new DocumentException("invalid.authentication");
    }

}

From source file:org.eclipse.birt.report.engine.emitter.postscript.truetypefont.TrueTypeFont.java

License:Open Source License

/**
 * Creates a new TrueType font.// w  ww  . j  ava 2s.co m
 * 
 * @param ttFile
 *            the location of the font on file. The file must end in '.ttf'
 *            or '.ttc' but can have modifiers after the name
 * @param enc
 *            the encoding to be applied to this font
 * @param emb
 *            true if the font is to be embedded in the PDF
 * @param ttfAfm
 *            the font as a <CODE>byte</CODE> array
 * @throws DocumentException
 *             the font is invalid
 * @throws IOException
 *             the font file could not be read
 */
TrueTypeFont(String ttFile, boolean justNames) throws DocumentException, IOException {
    this.justNames = justNames;
    String nameBase = getBaseName(ttFile);
    String ttcName = getTTCName(nameBase);
    if (nameBase.length() < ttFile.length()) {
        style = ttFile.substring(nameBase.length());
    }
    embedded = false;
    fileName = ttcName;
    ttcIndex = "";
    if (ttcName.length() < nameBase.length())
        ttcIndex = nameBase.substring(ttcName.length() + 1);
    if (fileName.toLowerCase().endsWith(".ttf") || fileName.toLowerCase().endsWith(".otf")
            || fileName.toLowerCase().endsWith(".ttc")) {
        process();
    } else
        throw new DocumentException(fileName + style + " is not a TTF, OTF or TTC font file.");
}

From source file:org.eclipse.birt.report.engine.emitter.postscript.truetypefont.TrueTypeFont.java

License:Open Source License

private int[] getTableLocation(String name) throws DocumentException {
    int[] table_location;
    table_location = (int[]) positionTables.get(name);
    if (table_location == null)
        throw new DocumentException("Table 'head' does not exist in " + fileName + style);
    return table_location;
}

From source file:org.eclipse.birt.report.engine.emitter.postscript.truetypefont.TrueTypeFont.java

License:Open Source License

/**
 * Gets the Postscript font name.//from ww  w .  j  a v a  2 s  . c  om
 * 
 * @throws DocumentException
 *             the font is invalid
 * @throws IOException
 *             the font file could not be read
 * @return the Postscript font name
 */
String getBaseFont() throws DocumentException, IOException {
    int table_location[];
    table_location = (int[]) positionTables.get("name");
    if (table_location == null)
        throw new DocumentException("Table 'name' does not exist in " + fileName + style);
    rf.seek(table_location[0] + 2);
    int numRecords = rf.readUnsignedShort();
    int startOfStorage = rf.readUnsignedShort();
    for (int k = 0; k < numRecords; ++k) {
        int platformID = rf.readUnsignedShort();
        int nameID = rf.readUnsignedShort();
        int length = rf.readUnsignedShort();
        int offset = rf.readUnsignedShort();
        if (nameID == 6) {
            rf.seek(table_location[0] + startOfStorage + offset);
            if (platformID != 0 && platformID != 3) {
                String name = readStandardString(length);
                name = name.replace(' ', '_');
                return name.replace((char) 0, '_');
            }
        }
    }
    File file = new File(fileName);
    return file.getName().replace(' ', '_');
}

From source file:org.eclipse.birt.report.engine.emitter.postscript.truetypefont.TrueTypeFont.java

License:Open Source License

/**
 * Extracts the names of the font in all the languages available.
 * /*from   ww w .  j  a v a 2s. c o m*/
 * @param id
 *            the name id to retrieve
 * @throws DocumentException
 *             on error
 * @throws IOException
 *             on error
 */
String[][] getNames(int id) throws DocumentException, IOException {
    int table_location[];
    table_location = (int[]) positionTables.get("name");
    if (table_location == null)
        throw new DocumentException("Table 'name' does not exist in " + fileName + style);
    rf.seek(table_location[0] + 2);
    int numRecords = rf.readUnsignedShort();
    int startOfStorage = rf.readUnsignedShort();
    ArrayList<String[]> names = new ArrayList<String[]>();
    for (int k = 0; k < numRecords; ++k) {
        int platformID = rf.readUnsignedShort();
        int platformEncodingID = rf.readUnsignedShort();
        int languageID = rf.readUnsignedShort();
        int nameID = rf.readUnsignedShort();
        int length = rf.readUnsignedShort();
        int offset = rf.readUnsignedShort();
        if (nameID == id) {
            int pos = rf.getFilePointer();
            rf.seek(table_location[0] + startOfStorage + offset);
            String name;
            if (platformID == 0 || platformID == 3 || (platformID == 2 && platformEncodingID == 1)) {
                name = readUnicodeString(length);
            } else {
                name = readStandardString(length);
            }
            names.add(new String[] { String.valueOf(platformID), String.valueOf(platformEncodingID),
                    String.valueOf(languageID), name });
            rf.seek(pos);
        }
    }
    String thisName[][] = new String[names.size()][];
    for (int k = 0; k < names.size(); ++k)
        thisName[k] = (String[]) names.get(k);
    return thisName;
}

From source file:org.eclipse.birt.report.engine.emitter.postscript.truetypefont.TrueTypeFont.java

License:Open Source License

/**
 * Reads the font data.//  w ww . j  a v  a2s.  c  o m
 * 
 * @param ttfAfm
 *            the font as a <CODE>byte</CODE> array, possibly <CODE>null</CODE>
 * @throws DocumentException
 *             the font is invalid
 * @throws IOException
 *             the font file could not be read
 */
void process() throws DocumentException, IOException {
    positionTables = new HashMap<String, int[]>();
    metadataTables = new HashMap<String, byte[]>();

    try {
        rf = new RandomAccessFileOrArray(fileName);
        if (ttcIndex.length() > 0) {
            int dirIdx = Integer.parseInt(ttcIndex);
            if (dirIdx < 0)
                throw new DocumentException("The font index for " + fileName + " must be positive.");
            String mainTag = readStandardString(4);
            if (!mainTag.equals("ttcf"))
                throw new DocumentException(fileName + " is not a valid TTC file.");
            rf.skipBytes(4);
            int dirCount = rf.readInt();
            if (dirIdx >= dirCount)
                throw new DocumentException("The font index for " + fileName + " must be between 0 and "
                        + (dirCount - 1) + ". It was " + dirIdx + ".");
            rf.skipBytes(dirIdx * 4);
            directoryOffset = rf.readInt();
        }
        rf.seek(directoryOffset);
        rf.readFully(directoryRawData);
        int ttId = Util.getInt(directoryRawData, 0);
        if (ttId != 0x00010000 && ttId != 0x4F54544F)
            throw new DocumentException(fileName + " is not a valid TTF or OTF file.");
        int num_tables = Util.getUnsignedShort(directoryRawData, 4);
        for (int k = 0; k < num_tables; ++k) {
            byte[] rawData = new byte[16];
            rf.readFully(rawData);
            String tag = getStandardString(rawData, 0, 4);
            int table_location[] = new int[2];
            table_location[0] = Util.getInt(rawData, 8);
            table_location[1] = Util.getInt(rawData, 12);
            positionTables.put(tag, table_location);
            metadataTables.put(tag, rawData);
        }
        fontName = getBaseFont();
        fullName = getNames(4); // full name
        familyName = getNames(1); // family name
        notice = getNames(0);
        version = getNames(5);

        if (!justNames) {
            fillTables();
            readGlyphWidths();
            readCMaps();
            readKerning();
            readBbox();
            GlyphWidths = null;
        }
    } finally {
        if (rf != null) {
            rf.close();
            if (!embedded)
                rf = null;
        }
    }
}