本文整理汇总了Java中android.graphics.pdf.PdfRenderer类的典型用法代码示例。如果您正苦于以下问题:Java PdfRenderer类的具体用法?Java PdfRenderer怎么用?Java PdfRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfRenderer类属于android.graphics.pdf包,在下文中一共展示了PdfRenderer类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: showPage
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
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();
}
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:26,代码来源:PdfActivity.java
示例2: instantiateItem
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
@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;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:BasePDFPagerAdapter.java
示例3: init
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
@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();
}
}
开发者ID:ynztlxdeai,项目名称:TextReader,代码行数:12,代码来源:BasePDFPagerAdapter.java
示例4: decodeRegion
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
/**
* 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;
}
开发者ID:num42,项目名称:subsampling-pdf-decoder,代码行数:24,代码来源:PDFRegionDecoder.java
示例5: decode
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
/**
* 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;
}
开发者ID:num42,项目名称:subsampling-pdf-decoder,代码行数:27,代码来源:PDFDecoder.java
示例6: instantiateItem
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
@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;
}
开发者ID:voghDev,项目名称:PdfViewPager,代码行数:22,代码来源:BasePDFPagerAdapter.java
示例7: openRenderer
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
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);
}
}
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:12,代码来源:PdfActivity.java
示例8: instantiateItem
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
@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;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:PDFPagerAdapter.java
示例9: extractPdfParamsFromFirstPage
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
@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;
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:BasePDFPagerAdapter.java
示例10: openRenderer
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
/**
* 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");
}
开发者ID:wangchauyan,项目名称:Android_365,代码行数:14,代码来源:PdfRendererBasicFragment.java
示例11: showPage
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
/**
* 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();
}
开发者ID:wangchauyan,项目名称:Android_365,代码行数:31,代码来源:PdfRendererBasicFragment.java
示例12: PDFPagerAdapter
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
/**
* @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);
}
}
开发者ID:num42,项目名称:subsampling-pdf-decoder,代码行数:16,代码来源:PDFPagerAdapter.java
示例13: init
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
/**
* 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)));
}
开发者ID:num42,项目名称:subsampling-pdf-decoder,代码行数:17,代码来源:PDFRegionDecoder.java
示例14: instantiateItem
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
@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;
}
开发者ID:voghDev,项目名称:PdfViewPager,代码行数:35,代码来源:PDFPagerAdapter.java
示例15: loadPdfFile
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
/**
* 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);
}
开发者ID:vanadium-archive,项目名称:reader,代码行数:17,代码来源:PdfViewWrapper.java
示例16: getPDFPage
import android.graphics.pdf.PdfRenderer; //导入依赖的package包/类
@SuppressWarnings("NewApi")
protected PdfRenderer.Page getPDFPage(PdfRenderer renderer, int position) {
return renderer.openPage(position);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:BasePDFPagerAdapter.java
注:本文中的android.graphics.pdf.PdfRenderer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论