【问题标题】:data not exist after saved in pdf format (fpdf)保存为 pdf 格式 (fpdf) 后数据不存在
【发布时间】:2018-01-10 08:04:41
【问题描述】:

我使用 fpdf 在 php(codeigniter) 中创建 pdf 文档。要打印的数据已经出现在谷歌浏览器的pdf预览中。但是当数据已经保存为pdf文档格式时,数据不会出现

this is my code:

public function laporan()
{
    $bulan1 = $this->input->post('bulan1');
    $bulan2 = $this->input->post('bulan2');
    $tanggal = array(
        'tanggal1'=>$bulan1,
        'tanggal2'=>$bulan2
    );

    $query  = "SELECT costumers.nama AS costumer, alats.nama AS alat, DATE(transaksis.tanggal_ambil) AS tanggal_ambil,DATE(transaksis.tanggal_kembali) AS tanggal_kembali FROM costumers,transaksis,alats WHERE costumers.id=transaksis.costumer_id AND transaksis.alat_id=alats.id AND DATE(transaksis.created_at) BETWEEN '$bulan1' AND '$bulan2' ORDER BY transaksis.created_at DESC";
    $data   = $this->UserModel->query_umum($query)->result();
    $header = array(
        array("label"=>"No", "length"=>8, "align"=>"L"),
        array("label"=>"Peminjam", "length"=>50, "align"=>"L"),
        array("label"=>"Nama Alat", "length"=>60, "align"=>"L"),
        array("label"=>"Tanggal Kirim", "length"=>30, "align"=>"L"),
        array("label"=>"Tanggal Pengembalian", "length"=>40, "align"=>"L")
    );

    $this->cetak_laporan($header,$data,$tanggal);
}

public function cetak_laporan($header,$data,$tanggal)
{
    $laporan = new FPDF();
    $laporan->AddPage();
    $laporan->SetFont('Arial','B',12);
    $laporan->Image(base_url('asset/img/logo-dewiratih.png'),5,4,30,10);

    $laporan->SetY(4);
    $laporan->SetX(37);
    $laporan->Cell(100,5, "CV. DEWI RATIH", 0, 1, 'L');
    $laporan->SetFont('Arial','',6);
    $laporan->SetX(37);
    $laporan->Cell(100,2, "CONTRACTOR-SUPLIER-HEAVY EQUIPMENT RENTAL-STONES CRUISER", 0, 1, 'L');
    $laporan->SetX(37);
    $laporan->Cell(100,2, "Jl. Laut Mororejo Kaliwungu Kendal-Jateng 51372", 0, 1, 'L');
    $laporan->SetX(37);
    $laporan->Cell(100,2, "Telp/Fax (024) 8666225, Email : dewiratih_99@yahoo.com", 0, 1, 'L');
    $laporan->SetLineWidth(0.5);
    $laporan->Line(3,16,205,16);

// $pdf->Line(1,3.2,28.5,3.2);
    $laporan->SetLineWidth(0);
    $laporan->SetFont('Arial','B',14);
    $laporan->Cell(0,15, "LAPORAN PEMINJAMAN ALAT", 0, 1, 'C');
    // $pdf->SetFont('Arial','',12);
    // $pdf->Cell(168,5,"Penyewa : ",0,1,'L');
    $laporan->SetFont('Arial','',9);
    // foreach ($tanggal as $tgl) {
        $laporan->Cell(168,5,"Laporan dari tanggal : ".$tanggal['tanggal1']." Sampai ".$tanggal['tanggal2'],0,1,'L');
    // }
    $laporan->SetFont('Arial','B',10);
    foreach ($header as $kolom) {
        $laporan->Cell($kolom['length'], 5, $kolom['label'], 1, '0', $kolom['align'], false);
    }
    $laporan->Ln();
    // $fill=false;
    $laporan->SetFont('Arial','',10);
    $no= 0;
    foreach ($data as $baris) {
        $i = 0;
        $laporan->Cell(8, 5, $no+1, 1, '0', $kolom['align'], false);
        foreach ($baris as $cell) {             
            $laporan->Cell($header[$i+1]['length'], 5, $cell, 1, '0', $kolom['align'], false);
            $i++;
        }
        $no++;
        $laporan->Ln();
    }
    // $pdf->Ln();
    $laporan->Cell(25,5,"Keterangan : ",0,0,'L');
    $laporan->Output("Laporan Peminjaman.pdf","I");
}

【问题讨论】:

    标签: php codeigniter pdf fpdf


    【解决方案1】:

    如果您想先显示文档,然后用户可以选择下载它,那么您应该考虑使用GET 作为查询字符串,而不是$bulan1$bulan2POST 方法。

    当您从上一页预览 pdf 文档时,它实际上发送了您的 POST 变量($bulan1$bulan2),但是当您保存它时,浏览器只是在没有 POST 数据的情况下发出请求在它上面,可以在您保存的文档上看到它错过了$bulan1$bulan2 值。

    【讨论】:

      【解决方案2】:

      我检查了你的,一切都很好:)(谷歌浏览器,adobbe 阅读器,福昕阅读器)。

      检查我的代码:

      public function laporan()
          {
              $bulan1  = $this->input->post('bulan1');
              $bulan2  = $this->input->post('bulan2');
              $tanggal = array(
                  'tanggal1' => '1111',
                  'tanggal2' => '2222',
              );
      
              $data = [];
              for ($i = 0; $i <= 3; $i++) {
                  for ($i2 = 0; $i2 <= 3; $i2++) {
                      $data[$i][$i2] = random_string('alnum', 5);
                  }
              }
      
              $header = array(
                  array("label" => "No", "length" => 8, "align" => "L"),
                  array("label" => "Peminjam", "length" => 50, "align" => "L"),
                  array("label" => "Nama Alat", "length" => 60, "align" => "L"),
                  array("label" => "Tanggal Kirim", "length" => 30, "align" => "L"),
                  array("label" => "Tanggal Pengembalian", "length" => 40, "align" => "L"),
              );
      
              $this->cetak_laporan($header, $data, $tanggal);
          }
      
          public function cetak_laporan($header, $data, $tanggal)
          {
              $laporan = new FPDF();
              $laporan->AddPage();
              $laporan->SetFont('Arial', 'B', 12);
              $laporan->Image('https://wiki.maemo.org/images/thumb/d/de/Maemo.org_logo_contest_sample1_bundyo.png/300px-Maemo.org_logo_contest_sample1_bundyo.png', 5, 4, 30, 10);
      
              $laporan->SetY(4);
              $laporan->SetX(37);
              $laporan->Cell(100, 5, "CV. DEWI RATIH", 0, 1, 'L');
              $laporan->SetFont('Arial', '', 6);
              $laporan->SetX(37);
              $laporan->Cell(100, 2, "CONTRACTOR-SUPLIER-HEAVY EQUIPMENT RENTAL-STONES CRUISER", 0, 1, 'L');
              $laporan->SetX(37);
              $laporan->Cell(100, 2, "Jl. Laut Mororejo Kaliwungu Kendal-Jateng 51372", 0, 1, 'L');
              $laporan->SetX(37);
              $laporan->Cell(100, 2, "Telp/Fax (024) 8666225, Email : dewiratih_99@yahoo.com", 0, 1, 'L');
              $laporan->SetLineWidth(0.5);
              $laporan->Line(3, 16, 205, 16);
      
      // $pdf->Line(1,3.2,28.5,3.2);
              $laporan->SetLineWidth(0);
              $laporan->SetFont('Arial', 'B', 14);
              $laporan->Cell(0, 15, "LAPORAN PEMINJAMAN ALAT", 0, 1, 'C');
              // $pdf->SetFont('Arial','',12);
              // $pdf->Cell(168,5,"Penyewa : ",0,1,'L');
              $laporan->SetFont('Arial', '', 9);
              // foreach ($tanggal as $tgl) {
              $laporan->Cell(168, 5, "Laporan dari tanggal : " . $tanggal['tanggal1'] . " Sampai " . $tanggal['tanggal2'], 0, 1, 'L');
              // }
              $laporan->SetFont('Arial', 'B', 10);
              foreach ($header as $kolom) {
                  $laporan->Cell($kolom['length'], 5, $kolom['label'], 1, '0', $kolom['align'], false);
              }
              $laporan->Ln();
              // $fill=false;
              $laporan->SetFont('Arial', '', 10);
              $no = 0;
      
              foreach ($data as $baris) {
                  $i = 0;
                  $laporan->Cell(8, 5, $no + 1, 1, '0', $kolom['align'], false);
                  foreach ($baris as $cell) {
                      $laporan->Cell($header[$i + 1]['length'], 5, $cell, 1, '0', $kolom['align'], false);
                      $i++;
                  }
                  $no++;
                  $laporan->Ln();
              }
              // $pdf->Ln();
              $laporan->Cell(25, 5, "Keterangan : ", 0, 0, 'L');
              $laporan->Output("Laporan Peminjaman.pdf", "I");
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多