com.lowagie.text.ExceptionConverter Java Examples

The following examples show how to use com.lowagie.text.ExceptionConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BarcodeInter25.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Creates new BarcodeInter25 */
public BarcodeInter25() {
    try {
        x = 0.8f;
        n = 2;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        textAlignment = Element.ALIGN_CENTER;
        generateChecksum = false;
        checksumText = false;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #2
Source File: PdfEncodings.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Loads a CJK cmap to the cache with the option of associating sequences to the newline.
 * 
 * @param name the CJK cmap name
 * @param newline the sequences to be replaced by a newline in the resulting CID. See
 *            <CODE>CRLF_CID_NEWLINE</CODE>
 */
public static void loadCmap(String name, byte newline[][]) {
	try {
		char planes[][] = null;
		synchronized (cmaps) {
			planes = (char[][]) cmaps.get(name);
		}
		if (planes == null) {
			planes = readCmap(name, newline);
			synchronized (cmaps) {
				cmaps.put(name, planes);
			}
		}
	} catch (IOException e) {
		throw new ExceptionConverter(e);
	}
}
 
Example #3
Source File: PdfPKCS7.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the bytes for the PKCS#1 object.
 * @return a byte array
 */
public byte[] getEncodedPKCS1() {
    try {
        if (externalDigest != null)
            digest = externalDigest;
        else
            digest = sig.sign();
        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        
        ASN1OutputStream dout = new ASN1OutputStream(bOut);
        dout.writeObject(new DEROctetString(digest));
        dout.close();
        
        return bOut.toByteArray();
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #4
Source File: PdfDocument.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Opens the document.
 * <P>
 * You have to open the document before you can begin to add content
 * to the body of the document.
 */

public void open() {
    if (!open) {
        super.open();
        writer.open();
        rootOutline = new PdfOutline(writer);
        currentOutline = rootOutline;
    }
    try {
        initPage();
    }
    catch(DocumentException de) {
        throw new ExceptionConverter(de);
    }
}
 
Example #5
Source File: PdfWriter.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Signals that the <CODE>Document</CODE> has been opened and that <CODE>Elements</CODE> can be
 * added.
 * <P>
 * When this method is called, the PDF-document header is written to the outputstream.
 *
 * @see com.lowagie.text.DocWriter#open()
 */
@Override
public void open() {
	super.open();
	try {
		pdf_version.writeHeader(os);
		body = new PdfBody(this);
		if (pdfxConformance.isPdfX32002()) {
			PdfDictionary sec = new PdfDictionary();
			sec.put(PdfName.GAMMA, new PdfArray(new float[] { 2.2f, 2.2f, 2.2f }));
			sec.put(PdfName.MATRIX, new PdfArray(new float[] { 0.4124f, 0.2126f, 0.0193f, 0.3576f, 0.7152f, 0.1192f, 0.1805f, 0.0722f, 0.9505f }));
			sec.put(PdfName.WHITEPOINT, new PdfArray(new float[] { 0.9505f, 1f, 1.089f }));
			PdfArray arr = new PdfArray(PdfName.CALRGB);
			arr.add(sec);
			setDefaultColorspace(PdfName.DEFAULTRGB, addToBody(arr).getIndirectReference());
		}
	} catch (IOException ioe) {
		throw new ExceptionConverter(ioe);
	}
}
 
Example #6
Source File: HtmlWriter.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Signals that an new page has to be started.
 *
 * @return <CODE>true</CODE> if this action succeeded, <CODE>false</CODE> if not.
 */

@Override
public boolean newPage() {
	try {
		writeStart(HtmlTags.DIV);
		write(" ");
		write(HtmlTags.STYLE);
		write("=\"");
		writeCssProperty(Markup.CSS_KEY_PAGE_BREAK_BEFORE, Markup.CSS_VALUE_ALWAYS);
		write("\" /");
		os.write(GT);
	} catch (IOException ioe) {
		throw new ExceptionConverter(ioe);
	}
	return true;
}
 
Example #7
Source File: PdfEncodings.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Converts a <CODE>byte</CODE> array encoded as <CODE>name</CODE>
 * to a CID string. This is needed to reach some CJK characters
 * that don't exist in 16 bit Unicode.</p>
 * The font to use this result must use the encoding "Identity-H"
 * or "Identity-V".</p>
 * See ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/.
 * @param name the CJK encoding name
 * @param start the start offset in the data
 * @param length the number of bytes to convert
 * @param seq the <CODE>byte</CODE> array to be decoded
 * @return the CID string
 */    
public static String convertCmap(String name, byte seq[], int start, int length) {
    try {
        char planes[][] = null;
        synchronized (cmaps) {
            planes = (char[][])cmaps.get(name);
        }
        if (planes == null) {
            planes = readCmap(name, (byte[][])null);
            synchronized (cmaps) {
                cmaps.put(name, planes);
            }
        }
        return decodeSequence(seq, start, length, planes);
    }
    catch (IOException e) {
        throw new ExceptionConverter(e);
    }        
}
 
Example #8
Source File: PRStream.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Sets the data associated with the stream, either compressed or uncompressed. Note that the
 * data will never be compressed if Document.compress is set to false.
 *
 * @param data raw data, decrypted and uncompressed.
 * @param compress true if you want the stream to be compressed.
 * @param compressionLevel a value between -1 and 9 (ignored if compress == false)
 * @since iText 2.1.3
 */
public void setData(byte[] data, boolean compress, int compressionLevel) {
	remove(PdfName.FILTER);
	offset = -1;
	if (Document.compress && compress) {
		try {
			ByteArrayOutputStream stream = new ByteArrayOutputStream();
			Deflater deflater = new Deflater(compressionLevel);
			DeflaterOutputStream zip = new DeflaterOutputStream(stream, deflater);
			zip.write(data);
			zip.close();
			deflater.end();
			bytes = stream.toByteArray();
			this.compressionLevel = compressionLevel;
		} catch (IOException ioe) {
			throw new ExceptionConverter(ioe);
		}
		put(PdfName.FILTER, PdfName.FLATEDECODE);
	} else {
		bytes = data;
	}
	setLength(bytes.length);
}
 
Example #9
Source File: PdfReader.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
public PdfObject getPdfObject(int idx) {
    try {
        lastXrefPartial = -1;
        if (idx < 0 || idx >= xrefObj.size())
            return null;
        PdfObject obj = (PdfObject)xrefObj.get(idx);
        if (!partial || obj != null)
            return obj;
        if (idx * 2 >= xref.length)
            return null;
        obj = readSingleObject(idx);
        lastXrefPartial = -1;
        if (obj != null)
            lastXrefPartial = idx;
        return obj;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #10
Source File: PdfWriter.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Signals that the <CODE>Document</CODE> has been opened and that
 * <CODE>Elements</CODE> can be added.
 * <P>
 * When this method is called, the PDF-document header is
 * written to the outputstream.
 * @see com.lowagie.text.DocWriter#open()
 */
public void open() {
    super.open();
    try {
    	pdf_version.writeHeader(os);
        body = new PdfBody(this);
        if (pdfxConformance.isPdfX32002()) {
            PdfDictionary sec = new PdfDictionary();
            sec.put(PdfName.GAMMA, new PdfArray(new float[]{2.2f,2.2f,2.2f}));
            sec.put(PdfName.MATRIX, new PdfArray(new float[]{0.4124f,0.2126f,0.0193f,0.3576f,0.7152f,0.1192f,0.1805f,0.0722f,0.9505f}));
            sec.put(PdfName.WHITEPOINT, new PdfArray(new float[]{0.9505f,1f,1.089f}));
            PdfArray arr = new PdfArray(PdfName.CALRGB);
            arr.add(sec);
            setDefaultColorspace(PdfName.DEFAULTRGB, addToBody(arr).getIndirectReference());
        }
    }
    catch(IOException ioe) {
        throw new ExceptionConverter(ioe);
    }
}
 
Example #11
Source File: BulkReceivingPdf.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable and set its logo image if 
 * there is a logoImage to be used, creates and sets the nestedHeaderTable and its content.
 * 
 * @param writer    The PdfWriter for this document.
 * @param document  The document.
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 */
public void onOpenDocument(PdfWriter writer, Document document) {
    try {
        
        loadHeaderTable();
        
        // initialization of the template
        tpl = writer.getDirectContent().createTemplate(100, 100);
        
        // initialization of the font
        helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
        
    }catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #12
Source File: PdfWriter.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Writes a <CODE>PdfImage</CODE> to the outputstream.
 *
 * @param pdfImage the image to be added
 * @return a <CODE>PdfIndirectReference</CODE> to the encapsulated image
 * @throws PdfException when a document isn't open yet, or has been closed
 */

PdfIndirectReference add(PdfImage pdfImage, PdfIndirectReference fixedRef) throws PdfException {
	if (!imageDictionary.contains(pdfImage.name())) {
		PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_IMAGE, pdfImage);
		if (fixedRef instanceof PRIndirectReference) {
			PRIndirectReference r2 = (PRIndirectReference) fixedRef;
			fixedRef = new PdfIndirectReference(0, getNewObjectNumber(r2.getReader(), r2.getNumber(), r2.getGeneration()));
		}
		try {
			if (fixedRef == null) {
				fixedRef = addToBody(pdfImage).getIndirectReference();
			} else {
				addToBody(pdfImage, fixedRef);
			}
		} catch (IOException ioe) {
			throw new ExceptionConverter(ioe);
		}
		imageDictionary.put(pdfImage.name(), fixedRef);
		return fixedRef;
	}
	return (PdfIndirectReference) imageDictionary.get(pdfImage.name());
}
 
Example #13
Source File: PdfWriter.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Signals that the <CODE>Document</CODE> has been opened and that
 * <CODE>Elements</CODE> can be added.
 * <P>
 * When this method is called, the PDF-document header is
 * written to the outputstream.
 */

public void open() {
    super.open();
    try {
        os.write(HEADER);
        body = new PdfBody(this);
        if (pdfxConformance == PDFX32002) {
            PdfDictionary sec = new PdfDictionary();
            sec.put(PdfName.GAMMA, new PdfArray(new float[]{2.2f,2.2f,2.2f}));
            sec.put(PdfName.MATRIX, new PdfArray(new float[]{0.4124f,0.2126f,0.0193f,0.3576f,0.7152f,0.1192f,0.1805f,0.0722f,0.9505f}));
            sec.put(PdfName.WHITEPOINT, new PdfArray(new float[]{0.9505f,1f,1.089f}));
            PdfArray arr = new PdfArray(PdfName.CALRGB);
            arr.add(sec);
            setDefaultColorspace(PdfName.DEFAULTRGB, addToBody(arr).getIndirectReference());
        }
    }
    catch(IOException ioe) {
        throw new ExceptionConverter(ioe);
    }
}
 
Example #14
Source File: BarcodeEAN.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Creates new BarcodeEAN */
public BarcodeEAN() {
    try {
        x = 0.8f;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        guardBars = true;
        codeType = EAN13;
        code = "";
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #15
Source File: Barcode39.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/** Creates a new Barcode39.
 */    
public Barcode39() {
    try {
        x = 0.8f;
        n = 2;
        font = BaseFont.createFont("Helvetica", "winansi", false);
        size = 8;
        baseline = size;
        barHeight = size * 3;
        textAlignment = Element.ALIGN_CENTER;
        generateChecksum = false;
        checksumText = false;
        startStopText = true;
        extended = false;
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #16
Source File: FieldPositioningEvents.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter,
 *      com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
@Override
public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) {
	rect.setBottom(rect.getBottom() - 3);
	PdfFormField field = (PdfFormField) genericChunkFields.get(text);
	if (field == null) {
		TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text);
		tf.setFontSize(14);
		try {
			field = tf.getTextField();
		} catch (Exception e) {
			throw new ExceptionConverter(e);
		}
	} else {
		field.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	}
	if (parent == null) {
		writer.addAnnotation(field);
	} else {
		parent.addKid(field);
	}
}
 
Example #17
Source File: EndPageTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter,
 *      com.lowagie.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	try {
		Rectangle page = document.getPageSize();
		PdfPTable head = new PdfPTable(3);
		for (int k = 1; k <= 6; ++k)
			head.addCell("head " + k);
		head.setTotalWidth(page.getWidth() - document.leftMargin()
				- document.rightMargin());
		head.writeSelectedRows(
				0,
				-1,
				document.leftMargin(),
				page.getHeight() - document.topMargin()
						+ head.getTotalHeight(), writer.getDirectContent());
		PdfPTable foot = new PdfPTable(3);
		for (int k = 1; k <= 6; ++k)
			foot.addCell("foot " + k);
		foot.setTotalWidth(page.getWidth() - document.leftMargin()
				- document.rightMargin());
		foot.writeSelectedRows(0, -1, document.leftMargin(),
				document.bottomMargin(), writer.getDirectContent());
	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}
}
 
Example #18
Source File: HtmlWriter.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* Constructs a <CODE>HtmlWriter</CODE>.
*
* @param doc     The <CODE>Document</CODE> that has to be written as HTML
* @param os      The <CODE>OutputStream</CODE> the writer has to write to.
*/
   
   protected HtmlWriter(Document doc, OutputStream os) {
       super(doc, os);
       
       document.addDocListener(this);
       this.pageN = document.getPageNumber();
       try {
           os.write(LT);
           os.write(getISOBytes(HtmlTags.HTML));
           os.write(GT);
           os.write(NEWLINE);
           os.write(TAB);
           os.write(LT);
           os.write(getISOBytes(HtmlTags.HEAD));
           os.write(GT);
       }
       catch(IOException ioe) {
           throw new ExceptionConverter(ioe);
       }
   }
 
Example #19
Source File: PRStream.java    From MesquiteCore with GNU Lesser General Public License v3.0 6 votes vote down vote up
public PRStream(PdfReader reader, byte conts[]) {
    this.reader = reader;
    this.offset = -1;
    if (Document.compress) {
        try {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            DeflaterOutputStream zip = new DeflaterOutputStream(stream);
            zip.write(conts);
            zip.close();
            bytes = stream.toByteArray();
        }
        catch (IOException ioe) {
            throw new ExceptionConverter(ioe);
        }
        put(PdfName.FILTER, PdfName.FLATEDECODE);
    }
    else
        bytes = conts;
    setLength(bytes.length);
}
 
Example #20
Source File: PdfReader.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Reads a <CODE>PdfObject</CODE> resolving an indirect reference if needed.
 *
 * @param obj the <CODE>PdfObject</CODE> to read
 * @return the resolved <CODE>PdfObject</CODE>
 */
public static PdfObject getPdfObject(PdfObject obj) {
	if (obj == null) {
		return null;
	}
	if (!obj.isIndirect()) {
		return obj;
	}
	try {
		PRIndirectReference ref = (PRIndirectReference) obj;
		int idx = ref.getNumber();
		boolean appendable = ref.getReader().appendable;
		obj = ref.getReader().getPdfObject(idx);
		if (obj == null) {
			return null;
		} else {
			if (appendable) {
				switch (obj.type()) {
					case PdfObject.NULL:
						obj = new PdfNull();
						break;
					case PdfObject.BOOLEAN:
						obj = new PdfBoolean(((PdfBoolean) obj).booleanValue());
						break;
					case PdfObject.NAME:
						obj = new PdfName(obj.getBytes());
						break;
				}
				obj.setIndRef(ref);
			}
			return obj;
		}
	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}
}
 
Example #21
Source File: CFFFont.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void emit(byte[] buffer) {
    //System.err.println("range emit offset "+offset+" size="+length);
    try {
        buf.seek(offset);
        for (int i=myOffset; i<myOffset+length; i++)
            buffer[i] = buf.readByte();
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
    //System.err.println("finished range emit");
}
 
Example #22
Source File: PdfEncryption.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
public byte[] encryptByteArray(byte[] b) {
	try {
		ByteArrayOutputStream ba = new ByteArrayOutputStream();
		OutputStreamEncryption os2 = getEncryptionStream(ba);
		os2.write(b);
		os2.finish();
		return ba.toByteArray();
	} catch (IOException ex) {
		throw new ExceptionConverter(ex);
	}
}
 
Example #23
Source File: CFFFont.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
char getCard8() {
    try {
        byte i = buf.readByte();
        return (char)(i & 0xff);
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #24
Source File: TiffImage.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Gets the number of pages the TIFF document has.
 * @param s the file source
 * @return the number of pages
 */    
public static int getNumberOfPages(RandomAccessFileOrArray s) {
    try {
        return TIFFDirectory.getNumDirectories(s);
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #25
Source File: RadioCheckField.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Sets the checked symbol. It can be
 * <CODE>TYPE_CHECK</CODE>,
 * <CODE>TYPE_CIRCLE</CODE>,
 * <CODE>TYPE_CROSS</CODE>,
 * <CODE>TYPE_DIAMOND</CODE>,
 * <CODE>TYPE_SQUARE</CODE> and
 * <CODE>TYPE_STAR</CODE>.
 * @param checkType the checked symbol
 */
public void setCheckType(int checkType) {
    if (checkType < TYPE_CHECK || checkType > TYPE_STAR)
        checkType = TYPE_CIRCLE;
    this.checkType = checkType;
    setText(typeChars[checkType - 1]);
    try {
        setFont(BaseFont.createFont(BaseFont.ZAPFDINGBATS, BaseFont.WINANSI, false));
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example #26
Source File: PdfDocument.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Opens the document.
 * <P>
 * You have to open the document before you can begin to add content to the body of the
 * document.
 */
@Override
public void open() {
	if (!open) {
		super.open();
		writer.open();
		rootOutline = new PdfOutline(writer);
		currentOutline = rootOutline;
	}
	try {
		initPage();
	} catch (DocumentException de) {
		throw new ExceptionConverter(de);
	}
}
 
Example #27
Source File: PdfDocument.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Opens the document.
 * <P>
 * You have to open the document before you can begin to add content
 * to the body of the document.
 */
public void open() {
    if (!open) {
        super.open();
        writer.open();
        rootOutline = new PdfOutline(writer);
        currentOutline = rootOutline;
    }
    try {
        initPage();
    }
    catch(DocumentException de) {
        throw new ExceptionConverter(de);
    }
}
 
Example #28
Source File: PdfEncryption.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
public byte[] decryptByteArray(byte[] b) {
	try {
		ByteArrayOutputStream ba = new ByteArrayOutputStream();
		StandardDecryption dec = getDecryptor();
		byte[] b2 = dec.update(b, 0, b.length);
		if (b2 != null)
			ba.write(b2);
		b2 = dec.finish();
		if (b2 != null)
			ba.write(b2);
		return ba.toByteArray();
	} catch (IOException ex) {
		throw new ExceptionConverter(ex);
	}
}
 
Example #29
Source File: PdfFont.java    From MesquiteCore with GNU Lesser General Public License v3.0 5 votes vote down vote up
static PdfFont getDefaultFont() {
    try {
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
        return new PdfFont(bf, 12);
    }
    catch (Exception ee) {
        throw new ExceptionConverter(ee);
    }
}
 
Example #30
Source File: HtmlParser.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
* Parses a given file.
* @param document the document the parser will write to
* @param file the file with the content
*/
   
   public void go(DocListener document, String file) {
       try {
           parser.parse(file, new SAXmyHtmlHandler(document));
       }
       catch(SAXException se) {
           throw new ExceptionConverter(se);
       }
       catch(IOException ioe) {
           throw new ExceptionConverter(ioe);
       }
   }