Show Mobile Navigation

jueves, 9 de febrero de 2023

Nele - febrero 09, 2023
public void createPdf(View v) { PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage(page); PDFont font = PDType1Font.HELVETICA; PDPageContentStream contentStream; try { // Define a content stream for adding to the PDF contentStream = new PDPageContentStream(document, page); // Write Hello World in blue text contentStream.beginText(); contentStream.setNonStrokingColor(15, 38, 192); contentStream.setFont(font, 12); contentStream.newLineAtOffset(100, 700); contentStream.showText("Hello World"); contentStream.endText(); // Load in the images InputStream in = assetManager.open("falcon.jpg"); InputStream alpha = assetManager.open("trans.png"); // Draw a green rectangle contentStream.addRect(5, 500, 100, 100); contentStream.setNonStrokingColor(0, 255, 125); contentStream.fill(); // Draw the falcon base image PDImageXObject ximage = JPEGFactory.createFromStream(document, in); contentStream.drawImage(ximage, 20, 20); // Draw the red overlay image Bitmap alphaImage = BitmapFactory.decodeStream(alpha); PDImageXObject alphaXimage = LosslessFactory.createFromImage(document, alphaImage); contentStream.drawImage(alphaXimage, 20, 20 ); // Make sure that the content stream is closed: contentStream.close(); // Save the final pdf document to a file String path = root.getAbsolutePath() + "/Created.pdf"; document.save(path); document.close(); tv.setText("Successfully wrote PDF to " + path); } catch (IOException e) { Log.e("PdfBox-Android-Sample", "Exception thrown while creating PDF", e); } }
Next Previous
Editor's Choice