将位图添加到pdf?

时间:2018-01-09 14:48:43

标签: android pdf bitmap pdfviewer

我如何将位图添加到pdfview,当触摸它时,位图可以变换和移动。我使用来自joan zapata https://github.com/JoanZapata/android-pdfview的pdfviewer。有办法解决它。还是有其他的书籍给我。这是我的活动。我尝试在pdfview中添加ontouchlistener,但在pdfview中缩放和扫描不起作用。

package com.example.irfan.signatureapp;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import com.joanzapata.pdfview.PDFView;
import com.joanzapata.pdfview.listener.OnDrawListener;
import com.joanzapata.pdfview.model.PagePart;
import java.io.File;

public class PdfEditorActivity extends AppCompatActivity{

String pdfname;
Bitmap signatureBitmap;
PDFView pdfView;
OnDrawListener drawListener;
Canvas gCanvas;
PagePart pagePart;

private long then;
private int longClickDuration = 2000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pdf_editor);

    pdfView = (PDFView) findViewById(R.id.pdfView);

    Intent intent = getIntent();
    pdfname = intent.getStringExtra("filename");

}

@Override
protected void onResume() {
    super.onResume();
    loadPdfFile(pdfname);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.pdf_editor_menu,menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    if(item.getItemId()==R.id.menu_add_signature){
        drawSignature();
    }
    return true;
}

void loadPdfFile(String path){
    File file = new File(path);
    pdfView.fromFile(file)
            .defaultPage(0)
            .load();

}

void drawSignature(){
    final String signaturePath = Environment.getExternalStorageDirectory().toString() + "/saved_signature/mysignature.png";
    signatureBitmap = BitmapFactory.decodeFile(signaturePath);
}
}

1 个答案:

答案 0 :(得分:0)

你能用Itext吗?我过去曾经用过它。我不知道它是否能达到你想要的效果,但这是一个想法。您仍然使用该方法使用PDF查看器 http://www.concretepage.com/itext/add-image-in-pdf-using-itext-in-java