Java 类android.graphics.pdf.PdfRenderer 实例源码

项目:NotifyTools    文件:PdfActivity.java   
private void showPage(int indexx) {

        if (mPdfRenderer.getPageCount() <= indexx) {
            index=mPdfRenderer.getPageCount()-1;
            return;
        }
        // Make sure to close the current page before opening another one.
        if (null != mCurrentPage) {
            mCurrentPage.close();
        }
        // Use `openPage` to open a specific page in PDF.
        mCurrentPage = mPdfRenderer.openPage(index);
        // Important: the destination bitmap must be ARGB (not RGB).
        Bitmap bitmap = Bitmap.createBitmap(mCurrentPage.getWidth(), mCurrentPage.getHeight(),
                Bitmap.Config.ARGB_8888);
        // Here, we render the page onto the Bitmap.
        // To render a portion of the page, use the second and third parameter. Pass nulls to get
        // the default result.
        // Pass either RENDER_MODE_FOR_DISPLAY or RENDER_MODE_FOR_PRINT for the last parameter.
        mCurrentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
        // We are ready to show the Bitmap to user.
        imgPdf.setImageBitmap(bitmap);
        mAttacher.update();
        updateUi();
    }
项目:GitHub    文件:BasePDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    iv.setImageBitmap(bitmap);
    container.addView(v, 0);

    return v;
}
项目:TextReader    文件:BasePDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    iv.setImageBitmap(bitmap);
    container.addView(v, 0);

    return v;
}
项目:BookReader-master    文件:BasePDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    iv.setImageBitmap(bitmap);
    container.addView(v, 0);

    return v;
}
项目:subsampling-pdf-decoder    文件:PDFRegionDecoder.java   
/**
 * Creates a {@link Bitmap} in the correct size and renders the region defined by rect of the
 * {@link PdfRenderer.Page} into it.
 *
 * @param rect the rect of the {@link PdfRenderer.Page} to be rendered to the bitmap
 * @param sampleSize the sample size
 * @return a bitmap containing the rendered rect of the page
 */
@Override public Bitmap decodeRegion(Rect rect, int sampleSize) {

  int bitmapWidth = rect.width() / sampleSize;
  int bitmapHeight = rect.height() / sampleSize;

  Bitmap bitmap = Bitmap.createBitmap(bitmapWidth , bitmapHeight,
      Bitmap.Config.ARGB_8888);

  Matrix matrix = new Matrix();
  matrix.setScale(scale/sampleSize,scale/sampleSize);
  matrix.postTranslate(-rect.left/sampleSize, -rect.top/sampleSize);
  page.render(bitmap, null, matrix, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);

  return bitmap;
}
项目:subsampling-pdf-decoder    文件:PDFDecoder.java   
/**
 * Creates a {@link Bitmap}in the correct size and renders the {@link PdfRenderer.Page} into it.
 *
 * @param context not used
 * @param uri not used
 * @return a bitmap, containing the pdf page
 * @throws Exception, if rendering fails
 */
@Override public Bitmap decode(Context context, Uri uri) throws Exception {
  ParcelFileDescriptor descriptor =
      ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);

  PdfRenderer renderer = new PdfRenderer(descriptor);
  final PdfRenderer.Page page = renderer.openPage(position);

  Bitmap bitmap = Bitmap.createBitmap((int) (page.getWidth() * scale + 0.5),
      (int) (page.getHeight() * scale + 0.5f), Bitmap.Config.ARGB_8888);

  page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);

  page.close();
  renderer.close();
  descriptor.close();

  return bitmap;
}
项目:BookReader    文件:BasePDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    iv.setImageBitmap(bitmap);
    container.addView(v, 0);

    return v;
}
项目:PdfViewPager    文件:BasePDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    iv.setImageBitmap(bitmap);
    ((ViewPager) container).addView(v, 0);

    return v;
}
项目:NotifyTools    文件:PdfActivity.java   
private void openRenderer( )  {
    // In this sample, we read a PDF from the assets directory.
    File f = new File(uri.getPath());
    try {
        mFileDescriptor = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
        mPdfRenderer = new PdfRenderer(mFileDescriptor);
        cnt=mPdfRenderer.getPageCount();
    } catch (Exception e) {
        log.e(e);
    }
}
项目:GitHub    文件:PDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    PhotoViewAttacher attacher = new PhotoViewAttacher(iv);
    attacher.setScale(scale.getScale(), scale.getCenterX(), scale.getCenterY(), true);
    attacher.setOnMatrixChangeListener(this);

    attachers.put(position, new WeakReference<PhotoViewAttacher>(attacher));

    iv.setImageBitmap(bitmap);
    attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
        @Override
        public void onPhotoTap(View view, float x, float y) {
            if (pageClickListener != null) {
                pageClickListener.onPageTap(view, x, y);
            }
        }
    });
    attacher.update();
    container.addView(v, 0);

    return v;
}
项目:GitHub    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected void init() {
    try {
        renderer = new PdfRenderer(getSeekableFileDescriptor(pdfPath));
        inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        PdfRendererParams params = extractPdfParamsFromFirstPage(renderer, renderQuality);
        bitmapContainer = new SimpleBitmapPool(params);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:GitHub    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
private PdfRendererParams extractPdfParamsFromFirstPage(PdfRenderer renderer, float renderQuality) {
    PdfRenderer.Page samplePage = getPDFPage(renderer, FIRST_PAGE);
    PdfRendererParams params = new PdfRendererParams();

    params.setRenderQuality(renderQuality);
    params.setOffScreenSize(offScreenSize);
    params.setWidth((int) (samplePage.getWidth() * renderQuality));
    params.setHeight((int) (samplePage.getHeight() * renderQuality));

    samplePage.close();

    return params;
}
项目:TextReader    文件:PDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    PhotoViewAttacher attacher = new PhotoViewAttacher(iv);
    attacher.setScale(scale.getScale(), scale.getCenterX(), scale.getCenterY(), true);
    attacher.setOnMatrixChangeListener(this);

    attachers.put(position, new WeakReference<PhotoViewAttacher>(attacher));

    iv.setImageBitmap(bitmap);
    attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
        @Override
        public void onPhotoTap(View view, float x, float y) {
            if (pageClickListener != null) {
                pageClickListener.onPageTap(view, x, y);
            }
        }
    });
    attacher.update();
    container.addView(v, 0);

    return v;
}
项目:TextReader    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected void init() {
    try {
        renderer = new PdfRenderer(getSeekableFileDescriptor(pdfPath));
        inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        PdfRendererParams params = extractPdfParamsFromFirstPage(renderer, renderQuality);
        bitmapContainer = new SimpleBitmapPool(params);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:TextReader    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
private PdfRendererParams extractPdfParamsFromFirstPage(PdfRenderer renderer, float renderQuality) {
    PdfRenderer.Page samplePage = getPDFPage(renderer, FIRST_PAGE);
    PdfRendererParams params = new PdfRendererParams();

    params.setRenderQuality(renderQuality);
    params.setOffScreenSize(offScreenSize);
    params.setWidth((int) (samplePage.getWidth() * renderQuality));
    params.setHeight((int) (samplePage.getHeight() * renderQuality));

    samplePage.close();

    return params;
}
项目:BookReader-master    文件:PDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    PhotoViewAttacher attacher = new PhotoViewAttacher(iv);
    attacher.setScale(scale.getScale(), scale.getCenterX(), scale.getCenterY(), true);
    attacher.setOnMatrixChangeListener(this);

    attachers.put(position, new WeakReference<PhotoViewAttacher>(attacher));

    iv.setImageBitmap(bitmap);
    attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
        @Override
        public void onPhotoTap(View view, float x, float y) {
            if (pageClickListener != null) {
                pageClickListener.onPageTap(view, x, y);
            }
        }
    });
    attacher.update();
    container.addView(v, 0);

    return v;
}
项目:BookReader-master    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected void init() {
    try {
        renderer = new PdfRenderer(getSeekableFileDescriptor(pdfPath));
        inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        PdfRendererParams params = extractPdfParamsFromFirstPage(renderer, renderQuality);
        bitmapContainer = new SimpleBitmapPool(params);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:BookReader-master    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
private PdfRendererParams extractPdfParamsFromFirstPage(PdfRenderer renderer, float renderQuality) {
    PdfRenderer.Page samplePage = getPDFPage(renderer, FIRST_PAGE);
    PdfRendererParams params = new PdfRendererParams();

    params.setRenderQuality(renderQuality);
    params.setOffScreenSize(offScreenSize);
    params.setWidth((int) (samplePage.getWidth() * renderQuality));
    params.setHeight((int) (samplePage.getHeight() * renderQuality));

    samplePage.close();

    return params;
}
项目:Android_365    文件:PdfRendererBasicFragment.java   
/**
 * Open pdf render
 */
private void openRenderer(Context context) throws IOException {
    // In this sample, we read a PDF from the assets directory.
    mFileDescriptor = context.getAssets().openFd("sample.pdf").getParcelFileDescriptor();
    // This is the PdfRenderer we use to render the PDF.
    if (mFileDescriptor != null) {
        mPdfRenderer = new PdfRenderer(mFileDescriptor);
        System.out.println("successfully open pdf render");
    } else
        System.out.println("cant create pdf file description");
}
项目:Android_365    文件:PdfRendererBasicFragment.java   
/**
 * Show pages by index
 */
private void showPage(int index) {
    if (mPdfRenderer == null || mPdfRenderer.getPageCount() <= index) {
        System.out.println("pdf render is null");
        return;
    }
    // Make sure to close the current page before opening another one.
    if (null != mCurrentPage) {
        mCurrentPage.close();
    }
    // Use `openPage` to open a specific page in PDF.
    mCurrentPage = mPdfRenderer.openPage(index);
    // Important: the destination bitmap must be ARGB (not RGB).
    if (pdfBitmap != null) {
        mImageView.setImageBitmap(null);
        pdfBitmap.recycle();
    }
    pdfBitmap = Bitmap.createBitmap(mCurrentPage.getWidth(), mCurrentPage.getHeight(),
            Bitmap.Config.ARGB_8888);
    // Here, we render the page onto the Bitmap.
    // To render a portion of the page, use the second and third parameter. Pass nulls to get
    // the default result.
    // Pass either RENDER_MODE_FOR_DISPLAY or RENDER_MODE_FOR_PRINT for the last parameter.
    mCurrentPage.render(pdfBitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    // We are ready to show the Bitmap to user.
    mImageView.setImageBitmap(pdfBitmap);
    updateUi();
}
项目:subsampling-pdf-decoder    文件:PDFPagerAdapter.java   
/**
 * @param file the pdf file
 */
public PDFPagerAdapter(Context context, File file) {
  super();
  this.context = context;
  this.file = file;
  this.scale = 8;
  try {
    mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    renderer = new PdfRenderer(mFileDescriptor);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
项目:subsampling-pdf-decoder    文件:PDFRegionDecoder.java   
/**
 * Initializes the region decoder. This method initializes
 * @param context not used here
 * @param uri not used here (file is already loaded)
 * @return the rescaled point
 * @throws Exception
 */
@Override public Point init(Context context, Uri uri) throws Exception {

  this.descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
  this.renderer = new PdfRenderer(descriptor);
  page = renderer.openPage(position);

  return new Point((int) ((page.getWidth() * scale + 0.5f)),
      (int) ((page.getHeight() * scale + 0.5f)));
}
项目:BookReader    文件:PDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    PhotoViewAttacher attacher = new PhotoViewAttacher(iv);
    attacher.setScale(scale.getScale(), scale.getCenterX(), scale.getCenterY(), true);
    attacher.setOnMatrixChangeListener(this);

    attachers.put(position, new WeakReference<PhotoViewAttacher>(attacher));

    iv.setImageBitmap(bitmap);
    attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
        @Override
        public void onPhotoTap(View view, float x, float y) {
            if (pageClickListener != null) {
                pageClickListener.onPageTap(view, x, y);
            }
        }
    });
    attacher.update();
    container.addView(v, 0);

    return v;
}
项目:BookReader    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
private PdfRendererParams extractPdfParamsFromFirstPage(PdfRenderer renderer, float renderQuality) {
    PdfRenderer.Page samplePage = getPDFPage(renderer, FIRST_PAGE);
    PdfRendererParams params = new PdfRendererParams();

    params.setRenderQuality(renderQuality);
    params.setOffScreenSize(offScreenSize);
    params.setWidth((int) (samplePage.getWidth() * renderQuality));
    params.setHeight((int) (samplePage.getHeight() * renderQuality));

    samplePage.close();

    return params;
}
项目:PdfViewPager    文件:PDFPagerAdapter.java   
@Override
@SuppressWarnings("NewApi")
public Object instantiateItem(ViewGroup container, int position) {
    View v = inflater.inflate(R.layout.view_pdf_page, container, false);
    ImageView iv = (ImageView) v.findViewById(R.id.imageView);

    if (renderer == null || getCount() < position) {
        return v;
    }

    PdfRenderer.Page page = getPDFPage(renderer, position);

    Bitmap bitmap = bitmapContainer.get(position);
    page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
    page.close();

    PhotoViewAttacher attacher = new PhotoViewAttacher(iv);
    attacher.setScale(scale.getScale(), scale.getCenterX(), scale.getCenterY(), true);
    attacher.setOnMatrixChangeListener(this);

    attachers.put(position, new WeakReference<PhotoViewAttacher>(attacher));

    iv.setImageBitmap(bitmap);
    attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
        @Override
        public void onPhotoTap(View view, float x, float y) {
            pageClickListener.onClick(view);
        }
    });
    attacher.update();
    ((ViewPager) container).addView(v, 0);

    return v;
}
项目:PdfViewPager    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected void init() {
    try {
        renderer = new PdfRenderer(getSeekableFileDescriptor(pdfPath));
        inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        PdfRendererParams params = extractPdfParamsFromFirstPage(renderer, renderQuality);
        bitmapContainer = new SimpleBitmapPool(params);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:PdfViewPager    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
private PdfRendererParams extractPdfParamsFromFirstPage(PdfRenderer renderer, float renderQuality) {
    PdfRenderer.Page samplePage = getPDFPage(renderer, FIRST_PAGE);
    PdfRendererParams params = new PdfRendererParams();

    params.setRenderQuality(renderQuality);
    params.setOffScreenSize(offScreenSize);
    params.setWidth((int) (samplePage.getWidth() * renderQuality));
    params.setHeight((int) (samplePage.getHeight() * renderQuality));

    samplePage.close();

    return params;
}
项目:reader    文件:PdfViewWrapper.java   
/**
 * Loads the PDF file at the given path into the pdf.js component within WebView.
 */
public void loadPdfFile(final String fileId, final int initialPage) throws IOException {
    File pdfFile = new File(getContext().getCacheDir(), fileId);

    try (InputStream in = DB.Singleton.get(getContext()).getInputStreamForFile(fileId);
         FileOutputStream out = new FileOutputStream(pdfFile)) {
        ByteStreams.copy(in, out);
    }

    mRenderer = new PdfRenderer(
            ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_ONLY));

    setPage(initialPage);
}
项目:GitHub    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected PdfRenderer.Page getPDFPage(PdfRenderer renderer, int position) {
    return renderer.openPage(position);
}
项目:TextReader    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected PdfRenderer.Page getPDFPage(PdfRenderer renderer, int position) {
    return renderer.openPage(position);
}
项目:BookReader-master    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected PdfRenderer.Page getPDFPage(PdfRenderer renderer, int position) {
    return renderer.openPage(position);
}
项目:BookReader    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected void init() {
    try {
        renderer = new PdfRenderer(getSeekableFileDescriptor(pdfPath));
        inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        PdfRendererParams params = extractPdfParamsFromFirstPage(renderer, renderQuality);
        bitmapContainer = new SimpleBitmapPool(params);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:BookReader    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected PdfRenderer.Page getPDFPage(PdfRenderer renderer, int position) {
    return renderer.openPage(position);
}
项目:PdfViewPager    文件:BasePDFPagerAdapter.java   
@SuppressWarnings("NewApi")
protected PdfRenderer.Page getPDFPage(PdfRenderer renderer, int position) {
    return renderer.openPage(position);
}