Last active
October 11, 2019 08:16
-
-
Save brettwold/e8dc5ff02ecb07aebf4c96e130caf65b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PdfPrintUsage extends Activity { | |
private WebView wv; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main_activity); | |
wv = (WebView) findViewById(R.id.web_view); | |
} | |
private void createWebPrintJob(WebView webView) { | |
String jobName = getString(R.string.app_name) + " Document"; | |
PrintAttributes attributes = new PrintAttributes.Builder() | |
.setMediaSize(PrintAttributes.MediaSize.ISO_A4) | |
.setResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600)) | |
.setMinMargins(PrintAttributes.Margins.NO_MARGINS).build(); | |
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM + "/PDFTest/"); | |
PdfPrint pdfPrint = new PdfPrint(attributes); | |
pdfPrint.print(webView.createPrintDocumentAdapter(jobName), path, "output_" + System.currentTimeMillis() + ".pdf"); | |
} | |
} |
Great guide, nice code snippet.
Would there be a possibility to get the pdf as outputstream instead of as a file on the device storage?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how i call this button click event? That means click on download button then download a pdf .