how can i combine multiple pdf to convert single pdf in android? -
I have several PDF files in the SD card, now I have to add those single page PDF files to a program in a PDF document. I have used the Android PDF Writer Library to create those single PDF files. How can I do this? I tried some code and questions but I could not find a good answer. Can somebody help me out?
I do not know how this is APW (Android PDF Writer), but you have the latest PDF files on Android Can combine with the latest. (Not yet the last ... RC3 ...)
Just add your build.gradle this dependency:
compile 'org.apache.pdfbox : Pdfbox: 2.0.0-RC3 ' And do this in an async function:
Private file download ANDCombinePDFs (string urlToPdf1, string urlToPdf2, string UrlToPdf3) throws IOException {PDFMergerUtility ut = new PDFMergerUtility (); Ut.addSource (NetworkUtils.downloadFile (urlToPdf1, 20)); Ut.addSource (NetworkUtils.downloadFile (urlToPdf2, 20)); Ut.addSource (NetworkUtils.downloadFile (urlToPdf3, 20)); Last file file = new file (getContext (). GetExternalCacheDir (), System.currentTimeMillis () + ".pdf"); Final file optupStream fileoptputstream = new fileoptputstream (file); Try {Ut.setDestinationStream (fileOutputStream); Ut.mergeDocuments (MemoryUsageSetting.setupTempFileOnly ()); } Finally {fileOutputStream.close (); } Return file; } Here NetworkUtils.downloadFile () should return an InputStream if you have it on your SDCD, then you can open a file inputstream.
I download PDFs from the Internet like this:
Public static inputstream downloading filetracking (string URL, int timeout intake) throws IOException {OkHttpClient client = new oak HTTP client (); Client.setConnectTimeout (Timeout Inseconds, Time Unit. SECONDS); Client.setReadTimeout (Timeout Inseconds, Time Unit. SECONDS); Request request = new request. Builder () Url (url) .build (); Feedback response = client.newCall (request). Execute (); If (! Response.Full ()) throw new IOException ("do not succeed. Download feedback:" + response); Give second feedback. (). ByteStream (); } To use OkHttpClient, add it to your build.gradle:
compile 'com.squareup.okhttp: okhttp: 2.7.2'