<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845151</guid>
        <pubDate>Tue, 02 Mar 2021 04:49:35 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845151</link>
        <description><![CDATA[Vashnaemnik: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=421216&view=findpost&p=3845146'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Gonarh &#064; <time class="tag-quote__quoted-time" datetime="2021-03-01T20:19:56+03:00">01.03.21, 17:19</time></span><div class='quote '>Ещё раз, у тебя фундаментальная ошибка, спрашивать разрешение в момент записи пдф. А если ты решишь делать запись пдф в десяти местах? Всё это говно у тебя будет повторяться 10 раз? Спрашивай один раз, сразу при старте приложения, и запрос на получение прав делай там же в случае отсутствия оных. При записи достаточно обрабатывать исключение в try/catch</div></div><br>
Огромное спасибо за помощь.<br>
А подскажите, сейчас он мне делает пдф файл корявый.<br>
Как мне его перевести в нормальный вид?<br>
Будет ли лучший результат ,если я буду делать скриншот экрана, и уже его сохранять в пдф?<br>
Или есть более лучший способ?]]></description>
        <author>Vashnaemnik</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845146</guid>
        <pubDate>Mon, 01 Mar 2021 17:19:56 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845146</link>
        <description><![CDATA[Gonarh: Ещё раз, у тебя фундаментальная ошибка, спрашивать разрешение в момент записи пдф. А если ты решишь делать запись пдф в десяти местах? Всё это говно у тебя будет повторяться 10 раз? Спрашивай один раз, сразу при старте приложения, и запрос на получение прав делай там же в случае отсутствия оных. При записи достаточно обрабатывать исключение в try/catch]]></description>
        <author>Gonarh</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845135</guid>
        <pubDate>Mon, 01 Mar 2021 14:51:38 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845135</link>
        <description><![CDATA[Vashnaemnik: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=421216&view=findpost&p=3845133'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Gonarh &#064; <time class="tag-quote__quoted-time" datetime="2021-03-01T14:39:59+00:00">01.03.21, 14:39</time></span><div class='quote '></div></div><br>
Спасибо :) другого от вас я и не ждал :)<br>
спасибо за подсказки <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2021-03-01T15:06:12+00:00">01.03.21, 15:06</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=421216&view=findpost&p=3845133'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Gonarh &#064; <time class="tag-quote__quoted-time" datetime="2021-03-01T14:39:59+00:00">01.03.21, 14:39</time></span><div class='quote '></div></div><br>
а подсказку можно?<br>
Если я уберу лишнее, сразу принудительно буду запрашивать разрешения и выполнять действие<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(getApplicationContext(), &quot;Разрешение предоставлено&quot;, Toast.LENGTH_SHORT).show();</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument document = new PdfDocument();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2250, 1400, 1).create();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument.Page page = document.startPage(pageInfo);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;View content = inflater.inflate(R.layout.activity_main, null);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.measure(1400, 2250);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.layout(0,0, 2250, 1400);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.draw(page.getCanvas());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.finishPage(page);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String directory_path = Environment.getExternalStorageDirectory().getPath() + &quot;/Табель/&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(directory_path);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists()) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;file.mkdirs();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String targetPdf = directory_path+&quot;Табель.pdf&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File filePath = new File(targetPdf);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.writeTo(new FileOutputStream(filePath));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(MainActivity.this, &quot;Cохранено&quot;, Toast.LENGTH_LONG).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.e(&quot;main&quot;, &quot;error &quot;+e.toString());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(MainActivity.this, &quot;Ошибка: &quot; + e.toString(), &nbsp;Toast.LENGTH_LONG).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.close();</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
Папка и файл создаются.<br>
Но может есть какие нибудь подводные камни? может ли мне это как то боком выйти?]]></description>
        <author>Vashnaemnik</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845133</guid>
        <pubDate>Mon, 01 Mar 2021 14:39:59 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845133</link>
        <description><![CDATA[Gonarh: То есть ты опять предлагаешь сделать работу за тебя? Один раз я уже так сделал, больше не буду. В чем ошибка, уже рассказал, дальше сам.]]></description>
        <author>Gonarh</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845129</guid>
        <pubDate>Mon, 01 Mar 2021 12:50:34 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845129</link>
        <description><![CDATA[Vashnaemnik: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=421216&view=findpost&p=3845128'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Gonarh &#064; <time class="tag-quote__quoted-time" datetime="2021-03-01T12:48:02+00:00">01.03.21, 12:48</time></span><div class='quote '></div></div><br>
Я вставлял после этого создание папки и файла, но он их не делает.<br>
Помогите подправить код :) если конечно будете согласны.<br>
И смущает, что после условия else мне надо снова повторять код. Но если условие убираю, то ничего не происходит. Не могу понять]]></description>
        <author>Vashnaemnik</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845128</guid>
        <pubDate>Mon, 01 Mar 2021 12:48:02 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845128</link>
        <description><![CDATA[Gonarh: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=421216&view=findpost&p=3845126'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Vashnaemnik &#064; <time class="tag-quote__quoted-time" datetime="2021-03-01T12:40:44+00:00">01.03.21, 12:40</time></span><div class='quote '>Но при разрешении, ничего не происходит.</div></div><br>
И не будет, у тебя так в коде написано.]]></description>
        <author>Gonarh</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845126</guid>
        <pubDate>Mon, 01 Mar 2021 12:40:44 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845126</link>
        <description><![CDATA[Vashnaemnik: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=421216&view=findpost&p=3845105'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Gonarh &#064; <time class="tag-quote__quoted-time" datetime="2021-03-01T05:56:14+00:00">01.03.21, 05:56</time></span><div class='quote '>Это первое что надо сделать, затем ты должен в своем приложении проверить выдано ли фактически данное разрешение твоему приложению, и если нет, то вывести запрос на оный.</div></div><br>
Подскажите. Мозг пипец уже кипит.<br>
Изменил функционал кнопки print.<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">//Проверка версии SDK устройства</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (Build.VERSION.SDK_INT &#62;= 19) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//динамическое получение прав на WRITE_EXTERNAL_STORAGE</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (Build.VERSION.SDK_INT &#62;= Build.VERSION_CODES.M) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;== PackageManager.PERMISSION_GRANTED) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(getApplicationContext(), &quot;Разрешение предоставлено&quot;, Toast.LENGTH_SHORT).show();</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument document = new PdfDocument();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2250, 1400, 1).create();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument.Page page = document.startPage(pageInfo);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;View content = inflater.inflate(R.layout.activity_main, null);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.measure(1400, 2250);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.layout(0,0, 2250, 1400);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.draw(page.getCanvas());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.finishPage(page);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String directory_path = Environment.getExternalStorageDirectory().getPath() + &quot;/Табель/&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(directory_path);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists()) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;file.mkdirs();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String targetPdf = directory_path+&quot;Табель.pdf&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File filePath = new File(targetPdf);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.writeTo(new FileOutputStream(filePath));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(MainActivity.this, &quot;Cохранено&quot;, Toast.LENGTH_LONG).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.e(&quot;main&quot;, &quot;error &quot;+e.toString());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(MainActivity.this, &quot;Ошибка: &quot; + e.toString(), &nbsp;Toast.LENGTH_LONG).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.close();</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(getApplicationContext(), &quot;В доступе отказано&quot;, Toast.LENGTH_SHORT).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//запрашиваем разрешение</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument document = new PdfDocument();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2250, 1400, 1).create();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument.Page page = document.startPage(pageInfo);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;View content = inflater.inflate(R.layout.activity_main, null);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.measure(1400, 2250);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.layout(0,0, 2250, 1400);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.draw(page.getCanvas());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.finishPage(page);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String directory_path = Environment.getExternalStorageDirectory().getPath() + &quot;/Табель/&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(directory_path);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists()) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;file.mkdirs();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String targetPdf = directory_path+&quot;Табель.pdf&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File filePath = new File(targetPdf);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.writeTo(new FileOutputStream(filePath));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(MainActivity.this, &quot;Cохранено&quot;, Toast.LENGTH_LONG).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.e(&quot;main&quot;, &quot;error &quot;+e.toString());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(MainActivity.this, &quot;Ошибка: &quot; + e.toString(), &nbsp;Toast.LENGTH_LONG).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.close();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div></ol></div></div></div></div><br>
Но ни как не могу понять.<br>
При первом нажатии кнопки мне отказано в доступе, и запрашиваем принудительно у пользователя. Но при разрешении, ничего не происходит. И уже после следующего нажатия создается и папка и файл. Правда открывая файл, там такая длиннющая квакозябра :) но это наверное из за русского языка, не могу понять пока как это исправить.<br>
И второе что смущает, что у меня создание папки и файла прописано дважды. Но если убираю условие else, он ничего не делает. Может что то не так делаю?]]></description>
        <author>Vashnaemnik</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845105</guid>
        <pubDate>Mon, 01 Mar 2021 05:56:14 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845105</link>
        <description><![CDATA[Gonarh: Это первое что надо сделать, затем ты должен в своем приложении проверить выдано ли фактически данное разрешение твоему приложению, и если нет, то вывести запрос на оный.]]></description>
        <author>Gonarh</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845104</guid>
        <pubDate>Mon, 01 Mar 2021 04:32:01 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845104</link>
        <description><![CDATA[Vashnaemnik: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=421216&view=findpost&p=3845102'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Gonarh &#064; <time class="tag-quote__quoted-time" datetime="2021-03-01T03:02:56+00:00">01.03.21, 03:02</time></span><div class='quote '></div></div><br>
А разве в манифесте строка:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&#62;</div></ol></div></div></div></div><br>
Это не то? Сколько читал на форумах, везде писали что для получения права на запись на внешнее хранилище отвечает эта строка в манифесте.]]></description>
        <author>Vashnaemnik</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845102</guid>
        <pubDate>Mon, 01 Mar 2021 03:02:56 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845102</link>
        <description><![CDATA[Gonarh: Запроси у системы права на запись на внешнее хранилище.]]></description>
        <author>Gonarh</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845094</guid>
        <pubDate>Sun, 28 Feb 2021 19:12:50 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845094</link>
        <description><![CDATA[Vashnaemnik: Здесь проект целиком.<br>
<a class='tag-url' href='https://yadi.sk/d/l2pXn1JkhVRsSw' target='_blank'>https://yadi.sk/d/l2pXn1JkhVRsSw</a><br>
Выдает мне ошибку, что доступ запрещен.]]></description>
        <author>Vashnaemnik</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845068</guid>
        <pubDate>Sun, 28 Feb 2021 06:00:06 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845068</link>
        <description><![CDATA[Gonarh: Я тебе об этом ответил ещё в теме с бмп.]]></description>
        <author>Gonarh</author>
        <category>Android</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845064</guid>
        <pubDate>Sat, 27 Feb 2021 19:01:00 +0000</pubDate>
        <title>Сохранение в пдф</title>
        <link>https://forum.sources.ru/index.php?showtopic=421216&amp;view=findpost&amp;p=3845064</link>
        <description><![CDATA[Vashnaemnik: Добрый вечер.<br>
Я пытаюсь свое активити сохранить в пдф:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">else if (id == R.id.print) {</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument document = new PdfDocument();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2250, 1400, 1).create();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PdfDocument.Page page = document.startPage(pageInfo);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;View content = inflater.inflate(R.layout.activity_main, null);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.measure(1400, 2250);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.layout(0,0, 2250, 1400);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content.draw(page.getCanvas());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.finishPage(page);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String directory_path = Environment.getExternalStorageDirectory().getPath() + &quot;/mypdf/&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File file = new File(directory_path);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!file.exists()) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;file.mkdirs();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String targetPdf = directory_path+&quot;Табель.pdf&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;File filePath = new File(targetPdf);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.writeTo(new FileOutputStream(filePath));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(MainActivity.this, &quot;Cохранено&quot;, Toast.LENGTH_LONG).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} catch (IOException e) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log.e(&quot;main&quot;, &quot;error &quot;+e.toString());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Toast.makeText(MainActivity.this, &quot;Ошибка: &quot; + e.toString(), &nbsp;Toast.LENGTH_LONG).show();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.close();</div></ol></div></div></div></div><br>
Но он мне выдает ошибку:<br>
Ошибка: java.io.FileNotFoundException:/storage/emulfted/0/mypdf/Табель.pdf (Permission denied)<br>
Подскажите что не так может быть? Почему доступ запрещен?]]></description>
        <author>Vashnaemnik</author>
        <category>Android</category>
      </item>
	
      </channel>
      </rss>
	