dataflow1117@gmail.com
FacebookTwitter

en English
af Afrikaanssq Albanianam Amharicar Arabichy Armenianaz Azerbaijanieu Basquebe Belarusianbn Bengalibs Bosnianbg Bulgarianca Catalanceb Cebuanony Chichewazh-CN Chinese (Simplified)zh-TW Chinese (Traditional)co Corsicanhr Croatiancs Czechda Danishnl Dutchen Englisheo Esperantoet Estoniantl Filipinofi Finnishfr Frenchfy Frisiangl Galicianka Georgiande Germanel Greekgu Gujaratiht Haitian Creoleha Hausahaw Hawaiianiw Hebrewhi Hindihmn Hmonghu Hungarianis Icelandicig Igboid Indonesianga Irishit Italianja Japanesejw Javanesekn Kannadakk Kazakhkm Khmerko Koreanku Kurdish (Kurmanji)ky Kyrgyzlo Laola Latinlv Latvianlt Lithuanianlb Luxembourgishmk Macedonianmg Malagasyms Malayml Malayalammt Maltesemi Maorimr Marathimn Mongolianmy Myanmar (Burmese)ne Nepalino Norwegianps Pashtofa Persianpl Polishpt Portuguesepa Punjabiro Romanianru Russiansm Samoangd Scottish Gaelicsr Serbianst Sesothosn Shonasd Sindhisi Sinhalask Slovaksl Slovenianso Somalies Spanishsu Sudanesesw Swahilisv Swedishtg Tajikta Tamilte Teluguth Thaitr Turkishuk Ukrainianur Urduuz Uzbekvi Vietnamesecy Welshxh Xhosayi Yiddishyo Yorubazu Zulu

DataInFlow
DataInFlow
A Market place of programming
  • Home
  • Tutorial
    • HTML Tutorial
    • PHP TUTORIAL
  • Article
    • Technology
    • Entertainment and News
    • Game
    • Recipes
  • Queries
  • Programming
    • HTML
    • CSS
    • jQuery
    • JavaScript
    • WordPress
    • PHP
    • Codeigniter
    • Laravel
    • Ionic
    • Angular JS
    • Node JS
    • Vue JS
    • Android
    • ASP .NET
  • Sports
    • Cricket
    • Football
    • Football Live Score
  • Web Tools
  • Home
  • Tutorial
    • HTML Tutorial
    • PHP TUTORIAL
  • Programming
  • Queries
  • Sports
    • Cricket
    • Football
    • Football Live Score
  • Article
    • Entertainment and News
    • Technology
    • Recipes
    • Game
  • Web Tools
  • About Us
  • Contact

TCPDF ERROR: Unable to create output file in codeigniter

936 viewsJanuary 4, 2019codeigniter
0
Aditya Gupta (anonymous) Posted December 27, 2018

In Codeigniter I have got this error when I am trying to generate a PDF file using TCPDF library. I have followed some example code, which code generate a PDF file, but all time I am got this error:

TCPDF ERROR: Unable to create output file: http://zaamana.net/assets/generate_pdf/1545722877.pdf

How can I do to solve this error?

I am trying this code:

In my controller page I have created this function.

1
2
3
4
5
6
7
8
9
10
11
<?php
public function generatePDFFile() {
$base_url=base_url();
$data = array();
$htmlContent='';
$data['getInfo'] = 'My PDF Data';
$htmlContent = $this->load->view('back/admin/pdf_file', $data, TRUE);
$createPDFFile = time().'.pdf';
return $this->createPDF($base_url.'assets/generate_pdf/'.$createPDFFile, $htmlContent);
}
?>

Then define createPDF function and enter these codes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
public function createPDF($fileName,$html) {
ob_start();
$this->load->library('Pdf');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator('PDF_CREATOR');
$pdf->SetAuthor('TechArise');
$pdf->SetTitle('TechArise');
$pdf->SetSubject('TechArise');
$pdf->SetKeywords('TechArise');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, 0, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// set font
$pdf->SetFont('dejavusans', '', 10);
// add a page
$pdf->AddPage();
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();
ob_end_clean();
//Close and output PDF document
$pdf->Output($fileName, 'F');
}
?>

 

0 Comments

1 Answer

  • Active
  • Voted
  • Newest
  • Oldest
0
Shyam SJ (anonymous) Posted December 27, 2018

You can not use the base_url() when you uploaded any file or generated any file. Here you need to remove base_url() from the file path, or “FCPATH” to replace base_url().

For Example:

1
2
3
4
5
<?php
 
(FCPATH.'assets/generate_pdf/'.$createPDFFile, $htmlContent);
 
?>

Follow this example code:

1
2
3
4
5
6
7
8
9
10
11
<?php
public function generatePDFFile() {
$base_url=base_url();
$data = array();
$htmlContent='';
$data['getInfo'] = 'My PDF Data';
$htmlContent = $this->load->view('back/admin/pdf_file', $data, TRUE);
$createPDFFile = time().'.pdf';
return $this->createPDF(FCPATH.'assets/generate_pdf/'.$createPDFFile, $htmlContent);
}
?>

 

Select 0 Comments
Write your answer.
Register or Login
Question and answer is powered by AnsPress.io
Subscribe to our Newsletter
Search anything
Questions
How to display success message after submit form value in php 2 Answers | 0 Votes
Should The Government Pay For IT Education? 9 Answers | 0 Votes
What are the top 10 question answer website for programming? 9 Answers | 0 Votes
Fatal error: Uncaught Error: Call to undefined function mysql_connect() 2 Answers | 0 Votes
How to set a session variable in laravel 5.2 4 Answers | 0 Votes
Recent Programming Article
  • Menu hide from sidebar in ionic 3
    December 27, 2018
  • Generate bootstrap modal in angular 6
    December 27, 2018
  • Load more results functionality with jQuery , Ajax and PHP
    December 27, 2018
  • Facebook login with JavaScript SDK
    December 27, 2018
  • Facebook login in Codeigniter and MySQL
    December 27, 2018
Hire us

Hi
Do you want to make web application with php and php framework(CI, Laravel)? Want to make android application with hybrid framework ? Then contact with us. We provide support for developing website and web application at very affordable price.
E-Mail us at: dataflow1117@gmail.com

Recent Technlogy News
  • Astrology Software: Perfect Tool for Astrologers to Earn Money Online
    December 27, 2018
  • Actionable Steps to Secure Workplace for Dummies
    December 27, 2018
  • The Best Spy Glasses in 2019 You Can Buy now
    December 27, 2018
© Copyright 2017-2018 DataInFlow

About Us    Privacy policy    Contact us

Login

Lost your password?

Reset Password

Log in