Un trucco e' quello di usare ImageMagick per convertire il pdf in png forzando una risoluzione di 300 dpi (anche se non e' nativa)
convert -density 300 ArchieGeneAmmonsC.pdf -quality 90 ArchieGeneAmmonsC300.png
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:design:26.+' //dipendenza PDF compile 'com.itextpdf:itextg:5.5.9' testCompile 'junit:junit:4.12'}
package com.example.lucainnocenti.photonotation; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Environment; import android.os.StrictMode; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Date; public class ReportActivity extends AppCompatActivity { private Button pulsante; private FileOutputStream output; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_report); pulsante = (Button) findViewById(R.id.buttonpdf); pulsante.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { try { crea_pdf(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } catch (DocumentException e) { e.printStackTrace(); } } }); } private void crea_pdf() throws IOException, DocumentException { File pdfFolder = new File(Environment.getExternalStorageDirectory().getPath(), "Photonotation"); if (!pdfFolder.exists()) { pdfFolder.mkdir(); Log.i("Photonotation", "Pdf Directory created"); } //Create time stamp Date date = new Date() ; String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(date); String percorso = pdfFolder.getAbsolutePath() + "/" + timeStamp +".pdf"; Log.i("Photonotation", percorso); File myFile = new File(percorso); output = new FileOutputStream(percorso); Document document = new Document(PageSize.A4); PdfWriter.getInstance(document, output); document.open(); document.add(new Paragraph("Luca")); String path = "/storage/emulated/0/Photonotation/20171031_140238.jpg"; Image image = Image.getInstance(path); document.add(image); document.close(); // visualizza il pdf prodotto
// le prime righe servono ad evitare android.os.FileUriExposedException
if(Build.VERSION.SDK_INT>=24){ try{ Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure"); m.invoke(null); }catch(Exception e){ e.printStackTrace(); } } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(myFile), "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent); } }
Immagine di fondo |
QrCode |
Il risultato finale |
Aggiornamento In realta' il Jtag USB funziona anche sui moduli cinesi Il problema risiede nell'ID USB della porta Jtag. Nel modulo...