Rectangle 27 53

Hi the problem is in FileDownloader class

urlConnection.setRequestMethod("GET");
    urlConnection.setDoOutput(true);

You need to remove the above two lines and everything will work fine. Please mark the question as answered if it is working as expected.

Attaching the working code with screenshots.

package com.example.downloadread;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class FileDownloader {
    private static final int  MEGABYTE = 1024 * 1024;

    public static void downloadFile(String fileUrl, File directory){
        try {

            URL url = new URL(fileUrl);
            HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
            //urlConnection.setRequestMethod("GET");
            //urlConnection.setDoOutput(true);
            urlConnection.connect();

            InputStream inputStream = urlConnection.getInputStream();
            FileOutputStream fileOutputStream = new FileOutputStream(directory);
            int totalSize = urlConnection.getContentLength();

            byte[] buffer = new byte[MEGABYTE];
            int bufferLength = 0;
            while((bufferLength = inputStream.read(buffer))>0 ){
                fileOutputStream.write(buffer, 0, bufferLength);
            }
            fileOutputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.downloadread"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.downloadread.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="15dp"
        android:text="download"
        android:onClick="download" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button1"
        android:layout_marginTop="38dp"
        android:text="view"
        android:onClick="view" />

</RelativeLayout>

HI Zack, by removing those two lines, it works, I can download and read on my mobile device. but somehow, each time i tried to read the DLed pdf on emulator, it crashes, any idea why? i use this adobe reader apk -> appsapk.com/adobe-reader did you read on emulator or your device? thx

and also, i wish to know why by removing those two lines, the app works? what is the story behind the scene? thx

My understanding is when downloading PDF from desktop application you need to specify GET / POST, however in Android decides how to download based on the response code. Hence that line is not required. Also the doOutput is not required as we are streaming and writing to the pdf file. Let me know if you need more details. Thanks for marking it as answered. Have a good day.

@MohammedZackria-Zack Your Example is Good But some Problem When I am Open another Pdf Previous File Deleted Automatically . Please Say Me How can I Prevent File Delete Please Help Me

android download pdf from url then open it with a pdf reader - Stack O...

android pdf download httpurlconnection fileinputstream
Rectangle 27 3

Found my own answer and it was so much simpler than where I was looking. My page with the download link is in an iframe. Something in the Android default browser loses your download if it occurs in an iframe. I added target="_blank" to the a tag that initiates the download and everything now works fine.

Here is some sample code to demonstrate the the problem and the fix.

<html>
<head><title>Test page</title></head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<body>
    <a href="http://www.adobe.com/products/eulas/pdfs/Photoshop_On_a_Server_Policy_5-31-2011.pdf">
        Download sample pdf</a><br />
    <iframe src="inner.html" />
</body>
</html>

and inner.html:

<html>
<head><title>test iframe</title></head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<body>
    <p>This does NOT work on Android default browser.
    <a href="http://www.adobe.com/products/eulas/pdfs/Photoshop_On_a_Server_Policy_5-31-2011.pdf">
    Download sample pdf within iframe</a></p>

    <p><a href="http://www.adobe.com/products/eulas/pdfs/Photoshop_On_a_Server_Policy_5-31-2011.pdf"
    target="_blank">Download sample pdf within iframe with target</a>.</p>
</body>
</html>

asp.net mvc - Android browser won't download pdf file - Stack Overflow

android asp.net-mvc pdf download
Rectangle 27 3

Found my own answer and it was so much simpler than where I was looking. My page with the download link is in an iframe. Something in the Android default browser loses your download if it occurs in an iframe. I added target="_blank" to the a tag that initiates the download and everything now works fine.

Here is some sample code to demonstrate the the problem and the fix.

<html>
<head><title>Test page</title></head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<body>
    <a href="http://www.adobe.com/products/eulas/pdfs/Photoshop_On_a_Server_Policy_5-31-2011.pdf">
        Download sample pdf</a><br />
    <iframe src="inner.html" />
</body>
</html>

and inner.html:

<html>
<head><title>test iframe</title></head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<body>
    <p>This does NOT work on Android default browser.
    <a href="http://www.adobe.com/products/eulas/pdfs/Photoshop_On_a_Server_Policy_5-31-2011.pdf">
    Download sample pdf within iframe</a></p>

    <p><a href="http://www.adobe.com/products/eulas/pdfs/Photoshop_On_a_Server_Policy_5-31-2011.pdf"
    target="_blank">Download sample pdf within iframe with target</a>.</p>
</body>
</html>

asp.net mvc - Android browser won't download pdf file - Stack Overflow

android asp.net-mvc pdf download
Rectangle 27 2

The android browser does not have a default built in PDF support so this cannot be easily done with that.

1) Download and install adobe reader from the play store and then try the following code

First you create a file on the device memory and then you read the pdf data into it. "theurl" is the url of where the pdf is located

InputStream in = null;
File dst = new File(Environment.getExternalStorageDirectory()+"/myPDF.pdf");
    try {
        in = theurl.openStream();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }               
    OutputStream out = null;
try {
    out = new FileOutputStream(dst);
} catch (FileNotFoundException e) {

    // TODO Auto-generated catch block
}
     // Transfer bytes from in to out
     try {
        byte[] buf = new byte[100000];
        int len;
    while ((len = in.read(buf)) > 0) {
      out.write(buf, 0, len);
     }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
     try {
    in.close();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
     try {
    out.close();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
    Intent intent = new Intent();
    Uri path = Uri.fromFile(dst);
    intent.setDataAndType(path, "application/pdf");
    startActivity(intent);

This will download the pdf, create it in your device memory and then the intent will open it on through your application using adove reader on your device.

I just can't modify the library that does it to me... But I'm not working on this project anymore

I voted this answer down, because it doesn't solve the problem with file downloading. The solution is needed for the server, not the client mobile device. Even if the browser cannot view a file of some unknown format, at least it should allow to save it, and this is where the problem is. It makes no sense to recommend installing something on the mobile device, because the server is most probably a public service, used by any customers, and you won't make them installing anything in order to be able to use your site.

Download a PDF file in via Web Browser, in Android ICS - Stack Overflo...

android pdf browser
Rectangle 27 7

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("*url for your pdf*"));
startActivity(browserIntent);

This will cause the pdf to be downloaded in the notification bar, as if you had initiated the download through the browser.

Looks good, downloads the file but can I have an option to open once downloaded? Otherwise people will have to exit my app to open the file in the downloads folder.

PS: ok, they can get at em through the notification bar like you imoplied. Hey, its my first app and first android, am I expected to know what I'm doing? ;) Thanks

android - how to: download and open a pdf file programmatically via ht...

android pdf file-io download
Rectangle 27 68

Example 2 on w3schools shows what you are trying to achieve.

<?php
header("Content-type:application/pdf");

// It will be called downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");

// The PDF source is in original.pdf
readfile("original.pdf");
?>

<html>
<body>

...
...

It is important to notice that header() must be called before any actual output is sent (In PHP 4 and later, you can use output buffering to solve this problem)

Haha true. I mentioned it only because it had the same example.

Remember to remove the single quotes around the file name. If you use filename='downloaded.pdf', some browsers will try to save the file with the quotes in the filename. I recently experienced this on OSX.

readfile()

correct PHP headers for pdf file download - Stack Overflow

php pdf header
Rectangle 27 101

Instead of linking to the .PDF file, instead do something like

<a href="pdf_server.php?file=pdffilename">Download my eBook</a>

which outputs a custom header, opens the PDF (binary safe) and prints the data to the user's browser, then they can choose to save the PDF despite their browser settings. The pdf_server.php should look like this:

header("Content-Type: application/octet-stream");

$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));   
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");            
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
    echo fread($fp, 65536);
    flush(); // this is essential for large downloads
} 
fclose($fp);

PS: and obviously run some sanity checks on the "file" variable to prevent people from stealing your files such as don't accept file extensions, deny slashes, add .pdf to the value

I am facing another problem with this, that my file is located at /products/brochure/myfile.pdf I am giving $file variable as $file_path = $_SERVER['DOCUMENT_ROOT'].'/products/brochure/' . $file; but its downloading the file as "%2Fvar%2Fwww%2Fweb15%2Fweb%2Fproducts%2Fbrochure%2myfile.pdf"

@TravisO "Content-type: application/force-download" isn't listed anywhere here: iana.org/assignments/media-types/application It's a completely bogus header. Please don't make up headers and send them. Could you update your answer. Thanks.

Be careful when using this code verbatim, though. This introduces a serious LFI vulnerability, as you're passing GET-variables directly into fopen.

This code is likely dangerous in another way. If you pass HTTP links to fopen, I think it'll go retrieve the file from another server. Could be used by an attacker to attempt to scan your internal network for exposed PDF files.

Not to mention how easy it would be to bypass any "sanity checks" you think you'll be doing to the "file" parameter. Path injection / directory traversal attacks are extremely likely.

php - How to make PDF file downloadable in HTML link? - Stack Overflow

php pdf xhtml download markup
Rectangle 27 101

Instead of linking to the .PDF file, instead do something like

<a href="pdf_server.php?file=pdffilename">Download my eBook</a>

which outputs a custom header, opens the PDF (binary safe) and prints the data to the user's browser, then they can choose to save the PDF despite their browser settings. The pdf_server.php should look like this:

header("Content-Type: application/octet-stream");

$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));   
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");            
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
    echo fread($fp, 65536);
    flush(); // this is essential for large downloads
} 
fclose($fp);

PS: and obviously run some sanity checks on the "file" variable to prevent people from stealing your files such as don't accept file extensions, deny slashes, add .pdf to the value

I am facing another problem with this, that my file is located at /products/brochure/myfile.pdf I am giving $file variable as $file_path = $_SERVER['DOCUMENT_ROOT'].'/products/brochure/' . $file; but its downloading the file as "%2Fvar%2Fwww%2Fweb15%2Fweb%2Fproducts%2Fbrochure%2myfile.pdf"

@TravisO "Content-type: application/force-download" isn't listed anywhere here: iana.org/assignments/media-types/application It's a completely bogus header. Please don't make up headers and send them. Could you update your answer. Thanks.

Be careful when using this code verbatim, though. This introduces a serious LFI vulnerability, as you're passing GET-variables directly into fopen.

This code is likely dangerous in another way. If you pass HTTP links to fopen, I think it'll go retrieve the file from another server. Could be used by an attacker to attempt to scan your internal network for exposed PDF files.

Not to mention how easy it would be to bypass any "sanity checks" you think you'll be doing to the "file" parameter. Path injection / directory traversal attacks are extremely likely.

php - How to make PDF file downloadable in HTML link? - Stack Overflow

php pdf xhtml download markup
Rectangle 27 57

To force the download of a PDF file, instead of being handled by the browser's PDF plugin:

If you want to let the browser handle by its default behavior (plugin or download), just send two parameters.

public ActionResult DownloadPDF()
{
    return File("~/Content/MyFile.pdf", "application/pdf");
}

You'll need to use the third parameter to specify a name for the file on the browser dialog.

UPDATE: Charlino is right, when passing the third parameter (download filename) Content-Disposition: attachment; gets added to the Http Response Header. My solution was to send application\force-download as the mime-type, but this generates a problem with the filename of the download so the third parameter is required to send a good filename, therefore eliminating the need to force a download.

Technically that's not what is happening. Technically when you add the third parameter, the MVC framework adds the header content-disposition: attachment; filename=MyRenamedFile.pdf - this is what forces the download. I would suggest you put the MIME type back to application/pdf.

Thank you Charlino, I didn't realized the third parameter was doing that, I thought it was just to change the filename.

Content-Disposition: attachment;

asp.net mvc - How can I present a file for download from an MVC contro...

asp.net-mvc download
Rectangle 27 10

This tells me that the BrowserActivity can handle the PDF, even on the Android 1.5 Emulator. However, after that emulator downloads the file, the download list shows "Cannot download. The content is not supported on the phone." How can I determine whether I'll get this message?

How do I determine if Android can handle PDF - Stack Overflow

android pdf
Rectangle 27 10

This tells me that the BrowserActivity can handle the PDF, even on the Android 1.5 Emulator. However, after that emulator downloads the file, the download list shows "Cannot download. The content is not supported on the phone." How can I determine whether I'll get this message?

How do I determine if Android can handle PDF - Stack Overflow

android pdf
Rectangle 27 36

Here is an example of sending back a pdf.

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Content-Transfer-Encoding: binary');
readfile($filename);

@Swish I didn't find application/force-download content type to do anything different (tested in IE and Firefox). Is there a reason for not sending back the actual MIME type?

Also in the PHP manual Hayley Watson posted:

If you wish to force a file to be downloaded and saved, instead of being rendered, remember that there is no such MIME type as "application/force-download". The correct type to use in this situation is "application/octet-stream", and using anything else is merely relying on the fact that clients are supposed to ignore unrecognised MIME types and use "application/octet-stream" instead (reference: Sections 4.1.4 and 4.5.1 of RFC 2046).

Also according IANA there is no registered application/force-download type.

It works on PC but... "Unable to download. Content not supported" when I visit the download page on Android device. Why?

@Emerald214 No PDF Reader. Or no association for the PDF content type

Especially if the targeted filetype is a .zip and all you're doing on the page is kicking off a file-download through PHP, you may want to add ob_clean(); and ob_flush(); before the code provided in the above answer; when trying to open a .zip natively in Windows, I had an issue wherein the OS reported .zip-archives acquired in this way were invalid, even though 7zip and other dedicated compressed-archive-format-handling tools could cope with them just fine.

automation - How to Automatically Start a Download in PHP? - Stack Ove...

php automation download
Rectangle 27 8

I found a workaround to view my PDF on my Android application (but does not allow me to download it after show on the application). If I open my PDF using Google Docs I can open it with my Intent.

https://docs.google.com/gview?embedded=true&url=https://myUrl.pdf

Here is the whole code I am using right now:

String url= "https://docs.google.com/gview?embedded=true&url=https://url.pdf";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);

But it is still not enough, because I would like to open it without need of using a third party application. Also, opening PDF with Google Docs is slow and I have to wait too much until the PDF is finally opened.

If anyone knows how to open it with native Android please let me know.

What happens if I do not open it with Google Docs?

With the same code, but just using my url, instead the added Google Docs url, Android let me choose between two applications: Adobe Acrobat Reader and Google Chrome.

If I open it with Google Chrome it download the PDF but it is not opened automatically.

If I open it with Adobe Acrobat Reader, it gives to me the following error:

Is it that you want to view the pdf page by page, or possibly extract data from it?

@TonyKutzler I would like to view the whole PDF. It would be great if the user can also download it, but after view the PDF on the screen.

Limitations on opening pdf file in Android - Stack Overflow

android pdf
Rectangle 27 14

$name = 'file.pdf';
//file_get_contents is standard function
$content = file_get_contents($name);
header('Content-Type: application/pdf');
header('Content-Length: '.strlen( $content ));
header('Content-disposition: inline; filename="' . $name . '"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
echo $content;

correct PHP headers for pdf file download - Stack Overflow

php pdf header
Rectangle 27 13

You should create WebViewClient and set it to your webview. Every time you click a link WebViewClient's shouldOverrideUrlLoading method will be called. Check that url points to pdf file and do what you want. For example, you can view pdf.

webView.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading (WebView view, String url) {
        if (url.endsWith(".pdf")) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            // if want to download pdf manually create AsyncTask here
            // and download file
            return true;
        }
        return false;
    }
});

can you help me i had open many html5 pages in webview in between one page downlod pdf file. i had used this code for it but it will not download pdf file

android - Downloading pdf through web browser and webview - Stack Over...

android pdf android-webview
Rectangle 27 1

Since you said the PDF is generated by a form, I'm assuming that's in response to a POST. I'm having the same problem, and found this comment on a similar S/O question:

issue is due to a bug in the Android browser and Dolphin, which causes downloads to fail on POST actions. I changed my actions to GET as a workaround.

asp.net - PDF download fails in Android Browser - Stack Overflow

android asp.net pdf mobile browser
Rectangle 27 1

I've had the same problem. I'm generating a PDF with Apache FOP and writing it to the response in Spring manner with the same headers you have and ResponseEntity. I solved the problem by choosing HttpStatus.OK instead of HttpStatus.CREATED in the ResponseEntity constructor.

Obviously IE8 doesn't understand a 201 (CREATED) as response code.

Spring Controller for PDF download, location.href,jQuery Modal and and...

jquery spring internet-explorer pdf download
Rectangle 27 52

I have been testing this and found that the following works. First you download the file independently and store it on the device and then you go do this:

File file = new File("/sdcard/download/somepdf.pdf");

 PackageManager packageManager = getPackageManager();
 Intent testIntent = new Intent(Intent.ACTION_VIEW);
 testIntent.setType("application/pdf");
 List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
 if (list.size() > 0 && file.isFile()) {
     Intent intent = new Intent();
     intent.setAction(Intent.ACTION_VIEW);
     Uri uri = Uri.fromFile(file);
     intent.setDataAndType(uri, "application/pdf");

     startActivity(intent);

I have tested this on various emulator and a rooted cyanogen phone as well as a HTC Magic. If no pdf renderer is available the list will return zero and nothing will happen.

If you e.g. install droidreader it will react to the intent and display the pdf.

Of course you could do the check before you download the pdf as well depending on your use case or do things like popping up alerts or redirecting do other intents for download or whatever.

public static final String MIME_TYPE_PDF = "application/pdf";

/**
 * Check if the supplied context can render PDF files via some installed application that reacts to a intent
 * with the pdf mime type and viewing action.
 *
 * @param context
 * @return
 */
public static boolean canDisplayPdf(Context context) {
    PackageManager packageManager = context.getPackageManager();
    Intent testIntent = new Intent(Intent.ACTION_VIEW);
    testIntent.setType(MIME_TYPE_PDF);
    if (packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
        return true;
    } else {
        return false;
    }
}

So, you need to download the PDF first, then try to display it? Will this work with PDFs hosted remotely?

No.. you have to download it from what I found. Passing a url in the intent does not work with lots of PDF readers..

thanks for creating the method it helped a lot.

You should use setDataAndType in your canDisplayPdf method - the outcome differs from 'setType'.

That method did not exist back then...

How do I determine if Android can handle PDF - Stack Overflow

android pdf
Rectangle 27 52

I have been testing this and found that the following works. First you download the file independently and store it on the device and then you go do this:

File file = new File("/sdcard/download/somepdf.pdf");

 PackageManager packageManager = getPackageManager();
 Intent testIntent = new Intent(Intent.ACTION_VIEW);
 testIntent.setType("application/pdf");
 List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
 if (list.size() > 0 && file.isFile()) {
     Intent intent = new Intent();
     intent.setAction(Intent.ACTION_VIEW);
     Uri uri = Uri.fromFile(file);
     intent.setDataAndType(uri, "application/pdf");

     startActivity(intent);

I have tested this on various emulator and a rooted cyanogen phone as well as a HTC Magic. If no pdf renderer is available the list will return zero and nothing will happen.

If you e.g. install droidreader it will react to the intent and display the pdf.

Of course you could do the check before you download the pdf as well depending on your use case or do things like popping up alerts or redirecting do other intents for download or whatever.

public static final String MIME_TYPE_PDF = "application/pdf";

/**
 * Check if the supplied context can render PDF files via some installed application that reacts to a intent
 * with the pdf mime type and viewing action.
 *
 * @param context
 * @return
 */
public static boolean canDisplayPdf(Context context) {
    PackageManager packageManager = context.getPackageManager();
    Intent testIntent = new Intent(Intent.ACTION_VIEW);
    testIntent.setType(MIME_TYPE_PDF);
    if (packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
        return true;
    } else {
        return false;
    }
}

So, you need to download the PDF first, then try to display it? Will this work with PDFs hosted remotely?

No.. you have to download it from what I found. Passing a url in the intent does not work with lots of PDF readers..

thanks for creating the method it helped a lot.

How do I determine if Android can handle PDF - Stack Overflow

android pdf
Rectangle 27 5

Well, the following is based on popular examples available on the web. What this does is "read" the pdf file and output it as a text in the rich text box control in the form. The PDFBox for .NET library can be downloaded from sourceforge.

You need to add reference to IKVM.GNU.Classpath & PDFBox-0.7.3. And also, FontBox-0.1.0-dev.dll and PDFBox-0.7.3.dll need to be added on the bin folder of your application. For some reason I can't recall (maybe it's from one of the tutorials), I also added to the bin IKVM.GNU.Classpath.dll.

On the side note, just got my copy of "Head First C#" (on Keith's suggestion) from Amazon. The book is cool! It is really written for beginners. This edition covers VS2008 and the framework 3.5.

/* Marlon Ribunal
 * Convert PDF To Text
 * *******************/

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.IO;
using System.Text;
using System.ComponentModel.Design;
using System.ComponentModel;
using org.pdfbox.pdmodel;
using org.pdfbox.util;

namespace MarlonRibunal.iPdfToText
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent(); 
        }

        void Button1Click(object sender, EventArgs e)    
        {    
            PDDocument doc = PDDocument.load("C:\\pdftoText\\myPdfTest.pdf");
            PDFTextStripper stripper = new PDFTextStripper();
            richTextBox1.Text=(stripper.getText(doc));
        }

     }
}

thanks! Saved me a headache!

The link above no longer works - get a "Unable to open connection to data provider" error message

ocr - Programmatically recognize text from scans in a PDF File - Stack...

pdf ocr