1

我正在使用手机存储中的 Google 云打印打印 Pdf。我想通过替换它来使用 pdf URL。如何使用网址?例如:我想将 /print/test.pdf" 替换为 "www.example.com/print/test.pdf"

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/print/test.pdf");
       Intent printIntent = new Intent(MainActivity.this,PrintDialogActivity.class);
       printIntent.setDataAndType(Uri.fromFile(file),"application/pdf");
       printIntent.putExtra("title", "Android print demo");
         startActivity(printIntent);
4

1 回答 1

0

下载http://central.maven.org/maven2/commons-io/commons-io/2.4/commons-io-2.4.jar并将其粘贴到 Android Studio 中的 libs 文件夹中。打开你的 Gradle 文件并在依赖项中添加这个“ compile files('libs/commons-io-1.3.2.jar')

                URL url = null;
                try {
                    url = new URL("http://www.cbu.edu.zm/downloads/pdf-sample.pdf");
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                String tDir = System.getProperty("java.io.tmpdir");
                String path = tDir + "tmp" + ".pdf";
                File file = new File(path); file.deleteOnExit();

                try {
                    FileUtils.copyURLToFile(url, file);
                } catch (IOException e) {
                    e.printStackTrace();
                }

                Intent printIntent = new Intent(MainActivity.this,
                        PrintDialogActivity.class);
                printIntent.setDataAndType(Uri.fromFile(file),
                        "application/pdf");
                printIntent.putExtra("title", "Android print demo");
                startActivity(printIntent);
于 2016-02-10T12:32:24.360 回答