Comments (5)
Hi, the PhotoView library comes from a patch of another user (I've merged them). About the lack of PdfViewer activity i removed it because it needed a lot of refactoring and I was just using the library.
You should be able to get it from the old version and use it.
Feel free to fork the repo and submit a patch!
from android-pdf-viewer-library.
I did it, but i have some errors about the parsing. Problems that with the original library I don't have. Can You post a sample project where u use your library?
from android-pdf-viewer-library.
At the moment im not using it with a pdfviewer but i'm just rendering pages into files (im still checking and trying to fix some functions that do not work properly), if you really want to check that (horrible) code, but i can't help you more than this:
public class LauncherActivity extends Activity {
private static final String TAG = "it.dorigatti.pdf";
private ImageButton refreshButton;
private Button fireCreationButton;
private EditText fireCreationPath;
private TextView logTextView;
private ImageView previewImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
refreshButton = (ImageButton) findViewById(R.id.refreshButton);
fireCreationButton = (Button) findViewById(R.id.fireCreation);
fireCreationButton.setEnabled(false);
fireCreationPath = (EditText) findViewById(R.id.filePathEt);
logTextView = (TextView) findViewById(R.id.logTv);
previewImageView = (ImageView) findViewById(R.id.preview);
final String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath();
final String fileName = externalDir + File.separator + "PDF-render_Test.pdf";
fireCreationPath.setText(fileName);
refreshButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String filePath = fireCreationPath.getText().toString();
File file = new File(filePath);
if (null == file || !file.exists() || !file.canRead()){
fireCreationPath.setError("The specified file does not exists or is not readable!");
fireCreationButton.setEnabled(false);
fireCreationPath.requestFocus();
}else{
fireCreationPath.setError(null);
fireCreationButton.setEnabled(true);
}
}
});
fireCreationButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
logTextView.setText("Firing preview creation process...\n");
String filePath = fireCreationPath.getText().toString();
long startTime = System.currentTimeMillis();
boolean result = processPreview(filePath);
long endTime = System.currentTimeMillis();
long delta = endTime - startTime;
String elapsed = DateUtils.formatElapsedTime(delta/1000);
String resultText ="File '" + filePath + "' had a preview result of " + result;
logAndTrace(resultText);
String finishText ="Finished creation of thumbnails in " + elapsed +" seconds";
logAndTrace(finishText );
}
});
}
private boolean processPreview(String fullFilePath) {
logAndTrace("File is : " + fullFilePath);
int slash = fullFilePath.lastIndexOf(File.separator);
String externalDir = fullFilePath.substring(0,slash);
String pdfFileName = fullFilePath.substring(slash+1);
logAndTrace("External dir is: " + externalDir + ", fileName is: "+pdfFileName);
try {
File f = new File(fullFilePath);
if (!f.exists()){
Log.e(TAG, "File '" + f.getAbsolutePath() + "' not found");
throw new FileNotFoundException("The file does not exists");
}
long len = f.length();
if (len == 0) {
Log.e(TAG, "File '" + f.getAbsolutePath() + "' has no length");
throw new IllegalArgumentException("File has no length");
}
// first open the file for random access
RandomAccessFile raf = new RandomAccessFile(f, "r");
// extract a file channel
FileChannel channel = raf.getChannel();
// now memory-map a byte-buffer
//java.nio.ByteBuffer b1 = new java.nio.channels.FileChannel
ByteBuffer bb = ByteBuffer.NEW(channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()));
// create a PDFFile from the data
PDFFile mPdfFile = new PDFFile(bb);
// draw the first page to an image
PDFPage page = mPdfFile.getPage(1, true);
// get the width and height for the doc at the default zoom
logAndTrace("page");
float width = page.getWidth();//*0.1f;
float height = page.getHeight();//*0.1f;
logAndTrace("pagesize");
RectF clip = null;
Bitmap pageImage = page.getImage((int) (width), (int) (height), clip, true, true);
if(null==pageImage){
logAndTrace("Image is null");
}else{
logAndTrace("Image is not null");
}
previewImageView.setImageBitmap(pageImage);
OutputStream fOut = null;
File file = new File(externalDir, pdfFileName + "_thumb.png");
fOut = new FileOutputStream(file);
logAndTrace("Image will be saved to:" + file.getAbsolutePath());
pageImage.compress(Bitmap.CompressFormat.PNG, 99, fOut);
fOut.flush();
fOut.close();
raf.close();
// Add to mediastore
MediaStore.Images.Media.insertImage(getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());
//MediaStore.Images.Media.insertImage(getContentResolver(), pageImage, pdfFileName + "_thumb.png", pdfFileName + "_thumb.png");
return true;
} catch (IllegalArgumentException e) {
e.printStackTrace();
return false;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e(TAG,"Exception while writing to device! "+e.getMessage());
return false;
} catch (NullPointerException np){
Log.e(TAG, "Null pointer exception writing image!"+ np.getMessage());
return false;
}
}
private void logAndTrace(String message){
if (null != logTextView){
logTextView.append(message+"\n\n");
}
Log.d(TAG,message);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_launcher, menu);
return true;
}
from android-pdf-viewer-library.
I tested it.. the resolution of image is very bad. Is better the original library.. with the graphview i think is better. Thx!
from android-pdf-viewer-library.
@francescogatto can you show the image difference and how/what you do to render the page? I did not see differences in quality (the code has just performance/crashrecovery fixes, it does not deal with quality)..
If possible, also provide the original PDF
from android-pdf-viewer-library.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-pdf-viewer-library.