PDF-объект не отображался на экране мобильного веб-сайта в Laravel 7Php

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 PDF-объект не отображался на экране мобильного веб-сайта в Laravel 7

Сообщение Anonymous »

Я знаю, возможно, этот вопрос задавался несколько раз.
Все, что я хочу сделать, это отобразить PDF-объект в веб-браузере на экране мобильного устройства. Я пытался использовать тег embed и тег iframe, но ни один из них не работает должным образом в веб-браузере на мобильном экране. К вашему сведению, теги embed и iframe очень хорошо работают на экране рабочего стола. Это мой контроллер

Код: Выделить всё

public function read_file($id) {
$findId = DB::connection('sqlsrv38')->table('kred_file_regulasi')->find($id);

if (!$findId) {
return response()->json([
'error' => 'File not found',
'data' => null,
], 404);
}

$filePath = $findId->nama_path;

if (!Storage::disk('ftp_edoc')->exists($filePath)) {
return response()->json([
'error' => 'File not found on storage',
'data' => $findId,
], 404);
}

try {
$fileContent = Storage::disk('ftp_edoc')->get($filePath);

return response($fileContent)
->header('Content-Type', 'application/pdf')
->header('Content-Disposition', 'inline; filename="' . $findId->nama_file . '"');
} catch (\Exception $e) {
return response()->json([
'error' => 'Error reading file: ' .  $e->getMessage(),
'data' => $findId,
], 500);
}
}
А это мой клинок

Код: Выделить всё

    @extends('layouts.media2');

@section('judule')
[*] Daftar File Regulasi Keperawatan
@endsection

@section('isine')




[h4]Jenis Regulasi[/h4]

@foreach ($jenis_regulasi as $item)

{{ $item->jenis_reg }}

@endforeach




[h4]Nama Regulasi[/h4]

Pilih Jenis Regulasi




@endsection

@section('modal')









×









@endsection

@push('js-script')

// Toast library
function infoToast(posisine,icone,infone) {
const Toast = Swal.mixin({
toast: true,
position: posisine,
showConfirmButton: false,
timer: 3000
});

Toast.fire({
icon: icone,
title: infone
});
}

function getFiles(dataId) {
$.ajax({
method: "POST",
url: "{{ route('keperawatan_fetch_files') }}",
data: {
_token: '{{ csrf_token() }}',
dataId: dataId,
},
success: function(response) {
var selectFileContainer = $('#nama-file-container');
selectFileContainer.empty();
response.forEach(function(file) {
selectFileContainer.append(
`${file.nama_file}`
);
});
},
error: function(xhr, status, error) {
console.error('AJAX Error:', status, error);
},
});
}

function startRead() {
var getTimeNow = new Date().toISOString();
return getTimeNow;
}

function convertMiliseconds(text) {
const split = text.split(" ");
const value = parseInt(split[0]);
const acuan = split[1];

let miliseconds = 0;
if(acuan.includes('menit')) {
miliseconds = value * 60 * 1000;
} else if (acuan.includes('jam')) {
miliseconds = value * 3600 * 1000;
}
return miliseconds;
}

$(document).ready(function() {
$('body').on('click', '.btn-jenis-reg', function (e) {
e.preventDefault();
var dataId = $(this).data('id');
getFiles(dataId);
});

$('body').on('click', '.btn-show-pdf', function () {
var mulai = startRead();
var fileId = $(this).data('id');
var fileName = $(this).data('name');
var waktuBacaMin = $(this).data('wbm');
var miliseconds = convertMiliseconds(waktuBacaMin);

var isMobile = window.innerWidth   {
$('#btn-baca-spo').removeAttr("disabled");
}, miliseconds);

$('#pdf-frame').attr('src', url);
$('#modal-title').text(fileName);
$('#modal-show-pdf').modal('show');
},
error: function(xhr) {
alert('Error: ' + xhr.status + ' - ' + xhr.statusText);
}
});
});

$('body').on('click', '#btn-baca-spo', function () {
var id_jenis_kegiatan = 4;
var topik = $('#nama_file').val();
var id_peran = 1;
var mulai = $('#mulai').val();
var akhir = new Date().toISOString();
var detail = $('#saran').val();
let nid_karyawan = $('#nid_karyawan').val();
let id_karyawan = $('#id_karyawan').val();
var periode = parseInt(new Date().getFullYear(), 10);
var id_unit_kerja = $('#id_unit_kerja').val();
console.log(typeof akhir, typeof mulai);
$.ajax({
url: `{{ route('keperawatan_add_aktf_kompetensi') }}`,
method: "POST",
data: {
id_jenis_kegiatan: id_jenis_kegiatan,
topik: topik,
id_peran: id_peran,
mulai: mulai,
akhir: akhir,
detail: detail,
nid_karyawan: nid_karyawan,
id_karyawan: id_karyawan,
periode: periode,
id_unit_kerja: id_unit_kerja,
_token: '{{ csrf_token() }}'
},
success: function(response) {
if (response.statuseKd === 200) {
console.log(response);
$('#modal-show-pdf').modal('hide');
infoToast('top', 'success', response.message);
}
},
error: function(xhr) {
if (xhr.status === 422) {
infoToast('toast-top-full-width', 'error', 'Terdapat kesalahan input, pastikan anda belum pernah melakukan setor aktifitas kompetensi ini');
}
}
})
});
});

@endpush
И вот как это отображается на экране мобильного устройства
Изображение

Кстати, я использую Laravel 7 и Bootstrap 4

Подробнее здесь: https://stackoverflow.com/questions/791 ... -laravel-7
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»