1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 Copyright 2014 The Android Open Source Project 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16--> 17 18 19 20<sample> 21 <name>PdfRendererBasic</name> 22 <group>UI</group> 23 <package>com.example.android.pdfrendererbasic</package> 24 25 <!-- change minSdk if needed--> 26 <minSdk>21</minSdk> 27 28 <strings> 29 <intro> 30 <![CDATA[ 31 This sample demonstrates how to use PdfRenderer to display PDF documents on the screen. 32 ]]> 33 </intro> 34 </strings> 35 36 <template src="base-build"/> 37 <androidX>true</androidX> 38 39 <metadata> 40 <status>PUBLISHED</status> 41 <categories>UI, Graphics</categories> 42 <technologies>Android</technologies> 43 <languages>Java</languages> 44 <solutions>Mobile</solutions> 45 <level>BEGINNER</level> 46 <icon>screenshots/icon-web.png</icon> 47 <screenshots> 48 <img>screenshots/main.png</img> 49 </screenshots> 50 <api_refs> 51 <android>android.graphics.pdf.PdfRenderer</android> 52 </api_refs> 53 54 <description> 55<![CDATA[ 56This sample demonstrates how to display PDF document on screen using 57the PdfRenderer introduced in Android 5.0 Lollipop. 58]]> 59 </description> 60 61 <intro> 62<![CDATA[ 63You can now render PDF document pages into bitmap images for printing by using 64the new [PdfRenderer][1] class. You must specify a [ParcelFileDescriptor][2] 65that is seekable (that is, the content can be randomly accessed) on which the 66system writes the the printable content. Your app can obtain a page for 67rendering with [openPage()][3], then call [render()][4] to turn the opened 68[PdfRenderer.Page][5] into a bitmap. 69 70This sample loads the PDF from assets. Contents of assets are compressed by 71default, and the PdfRenderer class cannot open it. In this sample, we work 72around this by copying the file into the cache directory. 73 74[1]: https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html 75[2]: https://developer.android.com/reference/android/os/ParcelFileDescriptor.html 76[3]: https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html#openPage(int) 77[4]: https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.Page.html#render(android.graphics.Bitmap,%20android.graphics.Rect,%20android.graphics.Matrix,%20int) 78[5]: https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.Page.html 79 80]]> 81 </intro> 82 </metadata> 83 84</sample> 85