v2.5.2
Giriş yap

PHPOffice xlsx to pdf - pdf çevirme işlemi yapamıyorum.

webman
379 defa görüntülendi

Merhabalar..

verileri excell sayfasına yazdırıyorum. Kaydediyorum. ZİP olarak indiriyorum.. Ancak zip olarak indirmek istemiyorum pdf e çevirerek ya indirecem yada gösterecem sayfada.
pdf e bir türlü çeviremiyorum. Ne yapmam lazım ?

<?php

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;


if (empty($_GET['uid']) || !is_numeric($_GET['uid'])) {
  die();
}

$uid = $_GET['uid'];

$model = new Model('users');
$user = $model->where('id', '=', $uid)->first();

$model = new Model('user_tests');
$userTests = $model->join('tests', 'test_id', 'id')->where('user_id', '=', $uid)->get();

if (!empty($userTests)) {
  $inputFileName = 'templates/empty104.xlsx';
  $outputFileName = 'templates/data2.xlsx';
  $graphFileName = 'templates/graph.xlsx';
  $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
  $reader->setIncludeCharts(true);
  $template = $reader->load($inputFileName);

  $template->getSheetByName('user')->setCellValue('A1', $user['name']);
  $template->getSheetByName('user')->setCellValue('A2', $user['email']);
  $template->getSheetByName('user')->setCellValue('A3', $user['mobile']);
  $template->getSheetByName('user')->setCellValue('A4', $user['gender'] == 'Erkek' ? 'Erkek' : 'Kadın');
  $template->getSheetByName('user')->setCellValue('A5', date('d-m-Y', strtotime($user['date_birth'])));

  foreach ($userTests as $test) {
    $testId = $test['id'];
    $testType = $test['type'];
    if ($testType != '****') {
      $answers = getUserAnswers($uid, $testType);
      $answers = array_column($answers, 'answer_code');
      if ($testType == '****') {
        $answers = array_map('mmpiAnswerFix', $answers);
      }
    } else {
      $filename = '*****/'.$user['name'].'-'.$user['id'].'-'.'****'.'.html';
      if (file_exists($filename)) {
        $file = file_get_contents($filename);
      } else {
        file_get_contents('https://************************.php?uid=' . $uid);
        sleep(2);
        if (file_exists($filename)) {
          $file = file_get_contents($filename);
        } else {
          break;
        }
      }
      $dom = new DOMDocument;
      @$dom->loadHTML($file);
      $contents = $dom->getElementsByTagName('app-pct-bar');
      $answers = [];
      foreach ($contents as $content) {
        $score = $content->getAttribute(':score');
        if ($content->getAttribute(':reversed') === 'true') {
          $score = -1 * $score;
        }
        if ($content->getAttribute(':reversed') === 'true') {
          $answers[] = floor(50 + $score / 2);
        } else {
          $answers[] = round(50 + $score / 2);
        }
      }
    }
    $answers = array_chunk($answers, 1);
    $template->getSheetByName($testType)->fromArray($answers, NULL, 'B5');

  }

  $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($template, 'Xlsx');
  $writer->setIncludeCharts(true);
  $writer->save($outputFileName);
  
}

$files = array($outputFileName, $graphFileName);
$zipname = $user['name'] . '.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFromString(basename($file), file_get_contents($file));
}
$zip->close();

header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
unlink($zipname);
unlink($outputFileName);
exit();

?>
Cevap yaz
Cevaplar (0)
Henüz kimse cevap yazmadı. İlk cevap yazan sen ol!