-

   rss_forum_sources_ru

 - e-mail

 

 -

 LiveInternet.ru:
: 29.07.2007
:
:
: 80

:


, 01 2021 . 15:40 +
Vashnaemnik:
Gonarh @
, , , .

. .
print.
    // SDK
    if (Build.VERSION.SDK_INT >= 19) {
    // WRITE_EXTERNAL_STORAGE
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
    == PackageManager.PERMISSION_GRANTED) {
    Toast.makeText(getApplicationContext(), " ", Toast.LENGTH_SHORT).show();
    PdfDocument document = new PdfDocument();
    PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2250, 1400, 1).create();
    PdfDocument.Page page = document.startPage(pageInfo);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View content = inflater.inflate(R.layout.activity_main, null);
    content.measure(1400, 2250);
    content.layout(0,0, 2250, 1400);
    content.draw(page.getCanvas());
    document.finishPage(page);
    String directory_path = Environment.getExternalStorageDirectory().getPath() + "//";
    File file = new File(directory_path);
    if (!file.exists()) {
    file.mkdirs();
    }
    String targetPdf = directory_path+".pdf";
    File filePath = new File(targetPdf);
    try {
    document.writeTo(new FileOutputStream(filePath));
    Toast.makeText(MainActivity.this, "C", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
    Log.e("main", "error "+e.toString());
    Toast.makeText(MainActivity.this, ": " + e.toString(), Toast.LENGTH_LONG).show();
    }
    document.close();
    } else {
    Toast.makeText(getApplicationContext(), " ", Toast.LENGTH_SHORT).show();
    //
    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
    }
    }
    } else {
    PdfDocument document = new PdfDocument();
    PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2250, 1400, 1).create();
    PdfDocument.Page page = document.startPage(pageInfo);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View content = inflater.inflate(R.layout.activity_main, null);
    content.measure(1400, 2250);
    content.layout(0,0, 2250, 1400);
    content.draw(page.getCanvas());
    document.finishPage(page);
    String directory_path = Environment.getExternalStorageDirectory().getPath() + "//";
    File file = new File(directory_path);
    if (!file.exists()) {
    file.mkdirs();
    }
    String targetPdf = directory_path+".pdf";
    File filePath = new File(targetPdf);
    try {
    document.writeTo(new FileOutputStream(filePath));
    Toast.makeText(MainActivity.this, "C", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
    Log.e("main", "error "+e.toString());
    Toast.makeText(MainActivity.this, ": " + e.toString(), Toast.LENGTH_LONG).show();
    }
    document.close();
    }

.
, . , . . , :) , .
, . else, . ?

https://forum.sources.ru/index.php?showtopic=421216&view=findpost&p=3845126

:  

: [1] []
 

:
: 

: ( )

:

  URL