Search in sources :

Example 1 with PDViewportDictionary

use of com.tom_roush.pdfbox.pdmodel.interactive.measurement.PDViewportDictionary in project PdfBox-Android by TomRoush.

the class PDPage method getViewports.

/**
 * Get the viewports.
 *
 * @return a list of viewports or null if there is no /VP entry.
 */
public List<PDViewportDictionary> getViewports() {
    COSBase base = page.getDictionaryObject(COSName.VP);
    if (!(base instanceof COSArray)) {
        return null;
    }
    COSArray array = (COSArray) base;
    List<PDViewportDictionary> viewports = new ArrayList<PDViewportDictionary>();
    for (int i = 0; i < array.size(); ++i) {
        COSBase base2 = array.getObject(i);
        if (base2 instanceof COSDictionary) {
            viewports.add(new PDViewportDictionary((COSDictionary) base2));
        } else {
            Log.w("PdfBox-Android", "Array element " + base2 + " is skipped, must be a (viewport) dictionary");
        }
    }
    return viewports;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) COSDictionary(com.tom_roush.pdfbox.cos.COSDictionary) ArrayList(java.util.ArrayList) COSArrayList(com.tom_roush.pdfbox.pdmodel.common.COSArrayList) COSBase(com.tom_roush.pdfbox.cos.COSBase) PDViewportDictionary(com.tom_roush.pdfbox.pdmodel.interactive.measurement.PDViewportDictionary)

Example 2 with PDViewportDictionary

use of com.tom_roush.pdfbox.pdmodel.interactive.measurement.PDViewportDictionary in project PdfBox-Android by TomRoush.

the class PDPage method setViewports.

/**
 * Set the viewports.
 *
 * @param viewports A list of viewports, or null if the entry is to be deleted.
 */
public void setViewports(List<PDViewportDictionary> viewports) {
    if (viewports == null) {
        page.removeItem(COSName.VP);
        return;
    }
    COSArray array = new COSArray();
    for (PDViewportDictionary viewport : viewports) {
        array.add(viewport);
    }
    page.setItem(COSName.VP, array);
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDViewportDictionary(com.tom_roush.pdfbox.pdmodel.interactive.measurement.PDViewportDictionary)

Aggregations

COSArray (com.tom_roush.pdfbox.cos.COSArray)2 PDViewportDictionary (com.tom_roush.pdfbox.pdmodel.interactive.measurement.PDViewportDictionary)2 COSBase (com.tom_roush.pdfbox.cos.COSBase)1 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)1 COSArrayList (com.tom_roush.pdfbox.pdmodel.common.COSArrayList)1 ArrayList (java.util.ArrayList)1