• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PdfDocument类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.graphics.pdf.PdfDocument的典型用法代码示例。如果您正苦于以下问题:Java PdfDocument类的具体用法?Java PdfDocument怎么用?Java PdfDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PdfDocument类属于android.graphics.pdf包,在下文中一共展示了PdfDocument类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: drawPage

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
private void drawPage(PdfDocument.Page page, int pageNumber){
	Canvas canvas = page.getCanvas();
	
	ImageManager manager=new ImageManager(context);
	
	Bitmap image;
	if (pageNumber%2==0)
		image=manager.decodeBitmapFromFile(manager.createFileNameFromUrl(frontImageName));
	else 
		image=manager.decodeBitmapFromFile(manager.createFileNameFromUrl(backImageName));
	
	Matrix matrix=new Matrix();
	matrix.setScale(500, 500);
	
    canvas.drawBitmap(image,0,0,new Paint());
}
 
开发者ID:Defuera,项目名称:cards-app,代码行数:17,代码来源:PrintAdapter.java


示例2: initNewPdfPage

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
private PdfDocument.Page initNewPdfPage() {
    PdfDocument.PageInfo pageInfo;

    if (orientation.equals(IOHelper.Orientation.HORIZONTAL)) {
        pageInfo = new PdfDocument.PageInfo.Builder(PDF_HEIGHT, PDF_WIDTH, ++pageNum).create();
    }
    else {
        pageInfo = new PdfDocument.PageInfo.Builder(PDF_WIDTH, PDF_HEIGHT, ++pageNum).create();
    }

    return document.startPage(pageInfo);
}
 
开发者ID:IziOzi,项目名称:IziOzi,代码行数:14,代码来源:PdfCreatorTask.java


示例3: doInBackground

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
@Override
protected Boolean doInBackground(Void... params) {
    PdfDocument document = new PdfDocument();
    ParcelFileDescriptor pfd = null;
    try {
        PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(640, 640 * 9 / 16, 1).create();

        for (Slide slide : store.getState().slides()) {
            PdfDocument.Page page = document.startPage(pageInfo);
            page.getCanvas().drawColor(Style.COLOR_SCHEMES[store.getState().colorScheme()][1]);
            slide.render(mContext,
                    page.getCanvas(),
                    page.getCanvas().getWidth(), page.getCanvas().getHeight(),
                    Style.SLIDE_FONT,
                    Style.COLOR_SCHEMES[App.getState().colorScheme()][0],
                    Style.COLOR_SCHEMES[App.getState().colorScheme()][1],
                    true);
            document.finishPage(page);
        }

        pfd = mContext.getContentResolver().openFileDescriptor(uri, "w");
        if (pfd != null) {
            FileOutputStream fos = new FileOutputStream(pfd.getFileDescriptor());
            document.writeTo(fos);
            return true;
        } else {
            return false;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } finally {
        document.close();
        if (pfd != null) {
            try { pfd.close(); } catch (IOException ignored) {}
        }
    }
}
 
开发者ID:trikita,项目名称:slide,代码行数:39,代码来源:StorageController.java


示例4: PdfCreatorTask

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
public PdfCreatorTask(Context context, IOHelper.Orientation orientation) {
    this.context = context;
    pageNum = 0;
    this.orientation = orientation;
    document = new PdfDocument();
}
 
开发者ID:IziOzi,项目名称:IziOzi,代码行数:8,代码来源:PdfCreatorTask.java


示例5: dfs

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
private void dfs(IOBoard board) {
    // first check if they are all empty pictograms on a board and short circuit
    boolean foundImg = false;
    for (int i = 0; i < board.getRows(); i++) {
        if (foundImg) break;

        for (int j = 0; j < board.getCols(); j++) {
            int index = i * board.getCols() + j;

            IOSpeakableImageButton img = board.getButtons().get(index);
            if (!img.getmImageFile().equals("")) {
                foundImg = true;
                break;
            }
        }
    }

    if (foundImg) {
        PdfDocument.Page page = initNewPdfPage();
        createPdfPage(board, page);
    }

    // now dfs for every child tree board
    for (int i=0; i < board.getButtons().size(); i++) {
        IOSpeakableImageButton btn = board.getButtons().get(i);
        if (btn.getIsMatrioska() && btn.getLevel() != null) {
            // it's a nested board
            IOLevel level = btn.getLevel();

            for (int j = 0; j < level.getInnerBoards().size(); j++) {
                IOBoard innerBoard = level.getBoardAtIndex(j);
                dfs(innerBoard);
            }
        }
    }
}
 
开发者ID:IziOzi,项目名称:IziOzi,代码行数:37,代码来源:PdfCreatorTask.java


示例6: onWrite

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, final WriteResultCallback callback) {

    // Register a cancellation listener
    cancellationSignal.setOnCancelListener(new CancellationSignal.OnCancelListener() {
        @Override
        public void onCancel() {
            // If cancelled then ensure that the PDF doc gets thrown away
            pdfDocument.close();
            pdfDocument = null;
            // And callback
            callback.onWriteCancelled();
        }
    });

    // Iterate through the pages
    for (int currentPageNumber = 0; currentPageNumber < pageCount; currentPageNumber++) {
        // Has this page been requested?
        if(!pageRangesContainPage(currentPageNumber, pages)) {
            // Skip this page
            continue;
        }

        // Start the current page
        PdfDocument.Page page = pdfDocument.startPage(currentPageNumber);

        // Get the canvas for this page
        Canvas canvas = page.getCanvas();

        // Draw on the page
        drawPage(currentPageNumber, canvas);

        // Finish the page
        pdfDocument.finishPage(page);
    }

    // Attempt to send the completed doc out
    try {
        pdfDocument.writeTo(new FileOutputStream(destination.getFileDescriptor()));
    } catch (IOException e) {
        callback.onWriteFailed(e.toString());
        return;
    } finally {
        pdfDocument.close();
        pdfDocument = null;
    }

    // The print is complete
    callback.onWriteFinished(pages);
}
 
开发者ID:shinobicontrols,项目名称:bitesize-kitkat,代码行数:51,代码来源:PrintShopPrintDocumentAdapter.java


示例7: onWrite

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
@Override
public void onWrite(final PageRange[] pageRanges,
					final ParcelFileDescriptor destination,
					final CancellationSignal cancellationSignal,
					final WriteResultCallback callback)
{
	if (pageRanges.length == 0 || !(
		pageRanges[0].getStart() <= 0 && pageRanges[0].getEnd() >= 0 ||
		pageRanges[0] == PageRange.ALL_PAGES))
	{
		Log.d(TAG, "Saving PDF failed - no valid page range");
		return;
	}

	if (cancellationSignal.isCanceled())
	{
		callback.onWriteCancelled();
		pdf.close();
		pdf = null;
		return;
	}

	PdfDocument.Page page = pdf.startPage(0);
	drawPage(page);
	pdf.finishPage(page);

	Log.d(TAG, "Saving PDF");
	try
	{
		pdf.writeTo(new FileOutputStream(destination.getFileDescriptor()));
		Log.w(TAG, "Saving PDF succeeded");
	} catch (IOException e) {
		Log.w(TAG, "Saving PDF failed: " + e.toString());
		callback.onWriteFailed(e.toString());
		return;
	} finally {
		pdf.close();
		pdf = null;
	}
	callback.onWriteFinished(new PageRange[]{ new PageRange(0, 0) });
}
 
开发者ID:pelya,项目名称:android-print-plugin-cups,代码行数:42,代码来源:SharePrinterActivity.java


示例8: drawPage

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
private void drawPage(PdfDocument.Page page)
{
	Log.d(TAG, "Drawing PDF page");
	Canvas canvas = page.getCanvas();
	int w = canvas.getWidth();
	int h = canvas.getHeight();
	int x = w / 2;
	int y = 0;
	int size = h / 50;
	Log.d(TAG, "w " + w + " h " + h + " x " + x + " y " + y + " size " + size + " bounds " + canvas.getClipBounds().toString());
	//layout.draw(canvas);
	Paint paint = new Paint();
	paint.setColor(Color.BLACK);
	paint.setTextSize(size * 1.5f);
	paint.setTextAlign(Paint.Align.CENTER);

	y += (paint.descent() - paint.ascent()) * 2.5;
	canvas.drawText(getResources().getString(R.string.add_printer_android, name), x, y, paint);
	paint.setTextSize(size / 1.3f);
	y += (paint.descent() - paint.ascent()) * 1.5;
	canvas.drawText(getResources().getString(R.string.add_printer_android_ver), x, y, paint);
	y += (paint.descent() - paint.ascent()) * 1.2;
	canvas.drawText(getResources().getString(R.string.install_barcode_scanner, name), x, y, paint);
	paint.setTextSize(size);
	y += (paint.descent() - paint.ascent()) * 1.5;
	canvas.drawText(getResources().getString(R.string.install_printer_plugin, getResources().getString(R.string.app_name)), x, y, paint);
	y += (paint.descent() - paint.ascent()) * 0.2;

	int qrSize = size * 13;
	paint.setFilterBitmap(false);
	canvas.drawBitmap(myAppAddr, null, new Rect(x - qrSize / 2, y, x + qrSize / 2, y + qrSize), paint);
	y += qrSize;

	y += (paint.descent() - paint.ascent()) * 0.7;
	canvas.drawText(getResources().getString(R.string.install_printer_plugin_enable, getResources().getString(R.string.app_name)), x, y, paint);
	y += (paint.descent() - paint.ascent()) * 1;
	canvas.drawText(getResources().getString(R.string.scan_qr, name), x, y, paint);
	paint.setTextSize(size / 1.3f);
	y += (paint.descent() - paint.ascent()) * 1;
	canvas.drawText(getResources().getString(R.string.scan_qr_open_browser), x, y, paint);
	paint.setTextSize(size);
	y += (paint.descent() - paint.ascent()) * 0.2;

	qrSize = size * 20;
	canvas.drawBitmap(qr, null, new Rect(x - qrSize / 2, y, x + qrSize / 2, y + qrSize), paint);
	y += qrSize;

	y += (paint.descent() - paint.ascent()) * 0.8;
	for (String line: notes.split("\n"))
	{
		canvas.drawText(line, x, y, paint);
		y += (paint.descent() - paint.ascent()) * 1;
	}
}
 
开发者ID:pelya,项目名称:android-print-plugin-cups,代码行数:55,代码来源:SharePrinterActivity.java


示例9: onWrite

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination,
		CancellationSignal cancellationSignal, WriteResultCallback callback) {
	// TODO Auto-generated method stub
	
	 // Iterate over each page of the document,
    // check if it's in the output range.
    for (int i = 0; i < 2; i++) {
        // Check to see if this page is in the output range.
            // If so, add it to writtenPagesArray. writtenPagesArray.size()
            // is used to compute the next output page index.
            PdfDocument.Page page = document.startPage(i);

            // check for cancellation
            if (cancellationSignal.isCanceled()) {
                callback.onWriteCancelled();
                document.close();
                document = null;
                return;
            }

            // Draw page content for printing
            drawPage(page,i);

            // Rendering is complete, so page can be finalized.
            document.finishPage(page);
    }

    // Write PDF document to file
    try {
    	document.writeTo(new FileOutputStream(
                destination.getFileDescriptor()));
    } catch (IOException e) {
        callback.onWriteFailed(e.toString());
        return;
    } finally {
    	document.close();
    	document = null;
    }
    PageRange[] writtenPages = {PageRange.ALL_PAGES};
    // Signal the print framework the document is complete
    callback.onWriteFinished(writtenPages);
}
 
开发者ID:Defuera,项目名称:cards-app,代码行数:44,代码来源:PrintAdapter.java


示例10: createPdfPage

import android.graphics.pdf.PdfDocument; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
private void createPdfPage(IOBoard board, PdfDocument.Page page) {
    int pageWidth = page.getInfo().getPageWidth();
    int pageHeight = page.getInfo().getPageHeight();

    int sizeWidth = pageWidth / board.getCols();
    int sizeHeight = pageHeight / board.getRows();

    int picSize = sizeWidth < sizeHeight ? sizeWidth : sizeHeight;

    int marginLeft = (pageWidth - (picSize * board.getCols())) / (board.getCols() + 1);
    int marginTop = (pageHeight - (picSize * board.getRows())) / (board.getRows() + 1);

    for (int i = 0; i < board.getRows(); i++) {
        int top = (marginTop * (i+1)) + (picSize * i);

        for (int j=0; j < board.getCols(); j++) {
            int index = i * board.getCols() + j;
            IOSpeakableImageButton btn = board.getButtons().get(index);

            ImageSize size = new ImageSize(picSize, picSize);
            Bitmap b = null;

            if (!btn.getmImageFile().equals("")) {
                DisplayImageOptions imgOpts = new DisplayImageOptions.Builder()
                        .imageScaleType(ImageScaleType.EXACTLY)
                        .build();

                b = imageLoader.loadImageSync("file://" + btn.getmImageFile(), size, imgOpts);
            }

            if (b != null) {
                int left = (marginLeft * (j+1)) + (picSize * j);

                page.getCanvas().drawBitmap(b, left, top, null);
            }
        }
    }

    document.finishPage(page);
}
 
开发者ID:IziOzi,项目名称:IziOzi,代码行数:42,代码来源:PdfCreatorTask.java



注:本文中的android.graphics.pdf.PdfDocument类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RepositoryConfigException类代码示例发布时间:2022-05-22
下一篇:
Java FilterPattern类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap