Android-Code to Implement PDF Viewer












2















Here i need to use Pdf-Viewer in my app.i took many API as a reference but still stucking up in viewing Pdf files from SDCARD. here my code



`First.java



public class First extends ListActivity {
String pdflist;
File imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}}


Second.java



public class Second extends PdfViewerActivity {

@Override
public int getPreviousPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.left_arrow;
}

@Override
public int getNextPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.right_arrow;
}

@Override
public int getZoomInImageResource() {
// TODO Auto-generated method stub
return R.drawable.zoom_in;
}

@Override
public int getZoomOutImageResource() {
// TODO Auto-generated method stub
return R.drawable.zoom_out;
}

@Override
public int getPdfPasswordLayoutResource() {
// TODO Auto-generated method stub
return R.layout.pdf_file_password;
}

@Override
public int getPdfPageNumberResource() {
// TODO Auto-generated method stub
return R.layout.dialog_pagenumber;
}

@Override
public int getPdfPasswordEditField() {
// TODO Auto-generated method stub
return R.id.etPassword;
}

@Override
public int getPdfPasswordOkButton() {
// TODO Auto-generated method stub
return R.id.btOK;
}

@Override
public int getPdfPasswordExitButton() {
// TODO Auto-generated method stub
return R.id.btExit;
}

@Override
public int getPdfPageNumberEditField() {
// TODO Auto-generated method stub
return R.id.pagenum_edit;
}}


And i used Android-Pdf-Reader-Library project.in my emulator Dialogue as"Loading pdf file" is appearing after clicking on Pdf files. And Can you anyone tell me how to Change the Pdf pages by swiping with finger??










share|improve this question

























  • Please see my answer.

    – Dipak Keshariya
    Jul 16 '12 at 8:50











  • Did you find any solution for curl/flip pages with using this library?!

    – Dr.jacky
    Jun 13 '15 at 7:13
















2















Here i need to use Pdf-Viewer in my app.i took many API as a reference but still stucking up in viewing Pdf files from SDCARD. here my code



`First.java



public class First extends ListActivity {
String pdflist;
File imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}}


Second.java



public class Second extends PdfViewerActivity {

@Override
public int getPreviousPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.left_arrow;
}

@Override
public int getNextPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.right_arrow;
}

@Override
public int getZoomInImageResource() {
// TODO Auto-generated method stub
return R.drawable.zoom_in;
}

@Override
public int getZoomOutImageResource() {
// TODO Auto-generated method stub
return R.drawable.zoom_out;
}

@Override
public int getPdfPasswordLayoutResource() {
// TODO Auto-generated method stub
return R.layout.pdf_file_password;
}

@Override
public int getPdfPageNumberResource() {
// TODO Auto-generated method stub
return R.layout.dialog_pagenumber;
}

@Override
public int getPdfPasswordEditField() {
// TODO Auto-generated method stub
return R.id.etPassword;
}

@Override
public int getPdfPasswordOkButton() {
// TODO Auto-generated method stub
return R.id.btOK;
}

@Override
public int getPdfPasswordExitButton() {
// TODO Auto-generated method stub
return R.id.btExit;
}

@Override
public int getPdfPageNumberEditField() {
// TODO Auto-generated method stub
return R.id.pagenum_edit;
}}


And i used Android-Pdf-Reader-Library project.in my emulator Dialogue as"Loading pdf file" is appearing after clicking on Pdf files. And Can you anyone tell me how to Change the Pdf pages by swiping with finger??










share|improve this question

























  • Please see my answer.

    – Dipak Keshariya
    Jul 16 '12 at 8:50











  • Did you find any solution for curl/flip pages with using this library?!

    – Dr.jacky
    Jun 13 '15 at 7:13














2












2








2


5






Here i need to use Pdf-Viewer in my app.i took many API as a reference but still stucking up in viewing Pdf files from SDCARD. here my code



`First.java



public class First extends ListActivity {
String pdflist;
File imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}}


Second.java



public class Second extends PdfViewerActivity {

@Override
public int getPreviousPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.left_arrow;
}

@Override
public int getNextPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.right_arrow;
}

@Override
public int getZoomInImageResource() {
// TODO Auto-generated method stub
return R.drawable.zoom_in;
}

@Override
public int getZoomOutImageResource() {
// TODO Auto-generated method stub
return R.drawable.zoom_out;
}

@Override
public int getPdfPasswordLayoutResource() {
// TODO Auto-generated method stub
return R.layout.pdf_file_password;
}

@Override
public int getPdfPageNumberResource() {
// TODO Auto-generated method stub
return R.layout.dialog_pagenumber;
}

@Override
public int getPdfPasswordEditField() {
// TODO Auto-generated method stub
return R.id.etPassword;
}

@Override
public int getPdfPasswordOkButton() {
// TODO Auto-generated method stub
return R.id.btOK;
}

@Override
public int getPdfPasswordExitButton() {
// TODO Auto-generated method stub
return R.id.btExit;
}

@Override
public int getPdfPageNumberEditField() {
// TODO Auto-generated method stub
return R.id.pagenum_edit;
}}


And i used Android-Pdf-Reader-Library project.in my emulator Dialogue as"Loading pdf file" is appearing after clicking on Pdf files. And Can you anyone tell me how to Change the Pdf pages by swiping with finger??










share|improve this question
















Here i need to use Pdf-Viewer in my app.i took many API as a reference but still stucking up in viewing Pdf files from SDCARD. here my code



`First.java



public class First extends ListActivity {
String pdflist;
File imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);

File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}}


Second.java



public class Second extends PdfViewerActivity {

@Override
public int getPreviousPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.left_arrow;
}

@Override
public int getNextPageImageResource() {
// TODO Auto-generated method stub
return R.drawable.right_arrow;
}

@Override
public int getZoomInImageResource() {
// TODO Auto-generated method stub
return R.drawable.zoom_in;
}

@Override
public int getZoomOutImageResource() {
// TODO Auto-generated method stub
return R.drawable.zoom_out;
}

@Override
public int getPdfPasswordLayoutResource() {
// TODO Auto-generated method stub
return R.layout.pdf_file_password;
}

@Override
public int getPdfPageNumberResource() {
// TODO Auto-generated method stub
return R.layout.dialog_pagenumber;
}

@Override
public int getPdfPasswordEditField() {
// TODO Auto-generated method stub
return R.id.etPassword;
}

@Override
public int getPdfPasswordOkButton() {
// TODO Auto-generated method stub
return R.id.btOK;
}

@Override
public int getPdfPasswordExitButton() {
// TODO Auto-generated method stub
return R.id.btExit;
}

@Override
public int getPdfPageNumberEditField() {
// TODO Auto-generated method stub
return R.id.pagenum_edit;
}}


And i used Android-Pdf-Reader-Library project.in my emulator Dialogue as"Loading pdf file" is appearing after clicking on Pdf files. And Can you anyone tell me how to Change the Pdf pages by swiping with finger??







android pdf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 17 '12 at 13:03







Michael-aes

















asked Jul 16 '12 at 7:37









Michael-aesMichael-aes

481311




481311













  • Please see my answer.

    – Dipak Keshariya
    Jul 16 '12 at 8:50











  • Did you find any solution for curl/flip pages with using this library?!

    – Dr.jacky
    Jun 13 '15 at 7:13



















  • Please see my answer.

    – Dipak Keshariya
    Jul 16 '12 at 8:50











  • Did you find any solution for curl/flip pages with using this library?!

    – Dr.jacky
    Jun 13 '15 at 7:13

















Please see my answer.

– Dipak Keshariya
Jul 16 '12 at 8:50





Please see my answer.

– Dipak Keshariya
Jul 16 '12 at 8:50













Did you find any solution for curl/flip pages with using this library?!

– Dr.jacky
Jun 13 '15 at 7:13





Did you find any solution for curl/flip pages with using this library?!

– Dr.jacky
Jun 13 '15 at 7:13












1 Answer
1






active

oldest

votes


















1














you can open pdf on google doc



    WebView webviewer = new WebView(this);
webviewer.getSettings().setJavaScriptEnabled(true);
webviewer.getSettings().setPluginsEnabled(true);
setContentView(webviewer);

webviewer.loadUrl("http://docs.google.com/gview?embedded=true&url=PDF_url/fileName.pdf");
setContentView(webviewer);


To open the PDF in application like quick pdf or adobe pdf reader:



    Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);





share|improve this answer
























  • thanks for immediate reply.In my app i don't need to open PDF in WebView bro. Help me to open PDF in above Code.

    – Michael-aes
    Jul 16 '12 at 8:23











  • if you dont want to open on webview simply open on readers using 2nd code which i gave u.

    – Furqi
    Jul 16 '12 at 9:30











  • I have tried that too.what shuld i want to give as a parameter(file) in Uri path?

    – Michael-aes
    Jul 16 '12 at 10:34











  • You have to give path where your pdf file saved in your sd card. final File file = new File( Environment.getExternalStorageDirectory() +"mypdf.pdf");

    – Furqi
    Jul 16 '12 at 10:39











  • @furqi...Thnks its working perfectly..is it will open the Hyperlink in the PDF pages??

    – Michael-aes
    Jul 17 '12 at 6:11











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11499942%2fandroid-code-to-implement-pdf-viewer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














you can open pdf on google doc



    WebView webviewer = new WebView(this);
webviewer.getSettings().setJavaScriptEnabled(true);
webviewer.getSettings().setPluginsEnabled(true);
setContentView(webviewer);

webviewer.loadUrl("http://docs.google.com/gview?embedded=true&url=PDF_url/fileName.pdf");
setContentView(webviewer);


To open the PDF in application like quick pdf or adobe pdf reader:



    Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);





share|improve this answer
























  • thanks for immediate reply.In my app i don't need to open PDF in WebView bro. Help me to open PDF in above Code.

    – Michael-aes
    Jul 16 '12 at 8:23











  • if you dont want to open on webview simply open on readers using 2nd code which i gave u.

    – Furqi
    Jul 16 '12 at 9:30











  • I have tried that too.what shuld i want to give as a parameter(file) in Uri path?

    – Michael-aes
    Jul 16 '12 at 10:34











  • You have to give path where your pdf file saved in your sd card. final File file = new File( Environment.getExternalStorageDirectory() +"mypdf.pdf");

    – Furqi
    Jul 16 '12 at 10:39











  • @furqi...Thnks its working perfectly..is it will open the Hyperlink in the PDF pages??

    – Michael-aes
    Jul 17 '12 at 6:11
















1














you can open pdf on google doc



    WebView webviewer = new WebView(this);
webviewer.getSettings().setJavaScriptEnabled(true);
webviewer.getSettings().setPluginsEnabled(true);
setContentView(webviewer);

webviewer.loadUrl("http://docs.google.com/gview?embedded=true&url=PDF_url/fileName.pdf");
setContentView(webviewer);


To open the PDF in application like quick pdf or adobe pdf reader:



    Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);





share|improve this answer
























  • thanks for immediate reply.In my app i don't need to open PDF in WebView bro. Help me to open PDF in above Code.

    – Michael-aes
    Jul 16 '12 at 8:23











  • if you dont want to open on webview simply open on readers using 2nd code which i gave u.

    – Furqi
    Jul 16 '12 at 9:30











  • I have tried that too.what shuld i want to give as a parameter(file) in Uri path?

    – Michael-aes
    Jul 16 '12 at 10:34











  • You have to give path where your pdf file saved in your sd card. final File file = new File( Environment.getExternalStorageDirectory() +"mypdf.pdf");

    – Furqi
    Jul 16 '12 at 10:39











  • @furqi...Thnks its working perfectly..is it will open the Hyperlink in the PDF pages??

    – Michael-aes
    Jul 17 '12 at 6:11














1












1








1







you can open pdf on google doc



    WebView webviewer = new WebView(this);
webviewer.getSettings().setJavaScriptEnabled(true);
webviewer.getSettings().setPluginsEnabled(true);
setContentView(webviewer);

webviewer.loadUrl("http://docs.google.com/gview?embedded=true&url=PDF_url/fileName.pdf");
setContentView(webviewer);


To open the PDF in application like quick pdf or adobe pdf reader:



    Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);





share|improve this answer













you can open pdf on google doc



    WebView webviewer = new WebView(this);
webviewer.getSettings().setJavaScriptEnabled(true);
webviewer.getSettings().setPluginsEnabled(true);
setContentView(webviewer);

webviewer.loadUrl("http://docs.google.com/gview?embedded=true&url=PDF_url/fileName.pdf");
setContentView(webviewer);


To open the PDF in application like quick pdf or adobe pdf reader:



    Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);






share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 16 '12 at 8:06









FurqiFurqi

2,25712131




2,25712131













  • thanks for immediate reply.In my app i don't need to open PDF in WebView bro. Help me to open PDF in above Code.

    – Michael-aes
    Jul 16 '12 at 8:23











  • if you dont want to open on webview simply open on readers using 2nd code which i gave u.

    – Furqi
    Jul 16 '12 at 9:30











  • I have tried that too.what shuld i want to give as a parameter(file) in Uri path?

    – Michael-aes
    Jul 16 '12 at 10:34











  • You have to give path where your pdf file saved in your sd card. final File file = new File( Environment.getExternalStorageDirectory() +"mypdf.pdf");

    – Furqi
    Jul 16 '12 at 10:39











  • @furqi...Thnks its working perfectly..is it will open the Hyperlink in the PDF pages??

    – Michael-aes
    Jul 17 '12 at 6:11



















  • thanks for immediate reply.In my app i don't need to open PDF in WebView bro. Help me to open PDF in above Code.

    – Michael-aes
    Jul 16 '12 at 8:23











  • if you dont want to open on webview simply open on readers using 2nd code which i gave u.

    – Furqi
    Jul 16 '12 at 9:30











  • I have tried that too.what shuld i want to give as a parameter(file) in Uri path?

    – Michael-aes
    Jul 16 '12 at 10:34











  • You have to give path where your pdf file saved in your sd card. final File file = new File( Environment.getExternalStorageDirectory() +"mypdf.pdf");

    – Furqi
    Jul 16 '12 at 10:39











  • @furqi...Thnks its working perfectly..is it will open the Hyperlink in the PDF pages??

    – Michael-aes
    Jul 17 '12 at 6:11

















thanks for immediate reply.In my app i don't need to open PDF in WebView bro. Help me to open PDF in above Code.

– Michael-aes
Jul 16 '12 at 8:23





thanks for immediate reply.In my app i don't need to open PDF in WebView bro. Help me to open PDF in above Code.

– Michael-aes
Jul 16 '12 at 8:23













if you dont want to open on webview simply open on readers using 2nd code which i gave u.

– Furqi
Jul 16 '12 at 9:30





if you dont want to open on webview simply open on readers using 2nd code which i gave u.

– Furqi
Jul 16 '12 at 9:30













I have tried that too.what shuld i want to give as a parameter(file) in Uri path?

– Michael-aes
Jul 16 '12 at 10:34





I have tried that too.what shuld i want to give as a parameter(file) in Uri path?

– Michael-aes
Jul 16 '12 at 10:34













You have to give path where your pdf file saved in your sd card. final File file = new File( Environment.getExternalStorageDirectory() +"mypdf.pdf");

– Furqi
Jul 16 '12 at 10:39





You have to give path where your pdf file saved in your sd card. final File file = new File( Environment.getExternalStorageDirectory() +"mypdf.pdf");

– Furqi
Jul 16 '12 at 10:39













@furqi...Thnks its working perfectly..is it will open the Hyperlink in the PDF pages??

– Michael-aes
Jul 17 '12 at 6:11





@furqi...Thnks its working perfectly..is it will open the Hyperlink in the PDF pages??

– Michael-aes
Jul 17 '12 at 6:11


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11499942%2fandroid-code-to-implement-pdf-viewer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks