Example usage for com.itextpdf.text.pdf PdfObject type

List of usage examples for com.itextpdf.text.pdf PdfObject type

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfObject type.

Prototype

int type

To view the source code for com.itextpdf.text.pdf PdfObject type.

Click Source Link

Document

The type of this PdfObject

Usage

From source file:mkl.testarea.itext5.pdfcleanup.PdfCleanUpContentOperator.java

License:Open Source License

/**
 * Overriding standard PdfObject.toPdf because we need sorted PdfDictionaries.
 *//*  ww  w .j  a  va2s.  c o  m*/
private static void toPdf(PdfObject object, PdfWriter writer, OutputStream os) throws IOException {
    if (object instanceof PdfDictionary) {
        os.write('<');
        os.write('<');

        List<PdfName> keys = new ArrayList<PdfName>(((PdfDictionary) object).getKeys());
        Collections.sort(keys);

        for (PdfName key : keys) {
            toPdf(key, writer, os);
            PdfObject value = ((PdfDictionary) object).get(key);
            int type = value.type();

            if (type != PdfObject.ARRAY && type != PdfObject.DICTIONARY && type != PdfObject.NAME
                    && type != PdfObject.STRING) {
                os.write(' ');
            }

            toPdf(value, writer, os);
        }

        os.write('>');
        os.write('>');
    } else {
        object.toPdf(writer, os);
    }
}