Insert download link in view file Codeignitor 3 and dompdf











up vote
0
down vote

favorite












I installed codeigniter 3 and dompdf. I followed a tutorial what is working perfect. At the moment every time i load the view for example localhost/codeigniter/welcome , the PDF is loaded directly and offered to download.
Instead i would rater like to include a clickable link the view page where the user can view the page and can decide if he want to download the page as pdf. i cant work out how to create the link. What i would need to change in my controller so the customer can view before download the page as pdf and how create the link.



Any help would be appericated



controller Welcome.php



<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

public function index()
{
$this->load->view('welcome_message');

// Get output html
$html = $this->output->get_output();

// Load pdf library
$this->load->library('pdf');

// Load HTML content
$this->dompdf->loadHtml($html);

// (Optional) Setup the paper size and orientation
$this->dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$this->dompdf->render();

// Output the generated PDF (1 = download and 0 = preview)
$this->dompdf->stream("welcome.pdf", array("Attachment"=>0));
}
}


libraries PHP



 <?php defined('BASEPATH') OR exit('No direct script access allowed');

// reference the Dompdf namespace
use DompdfDompdf;

class Pdf
{
public function __construct(){

// include autoloader
require_once dirname(__FILE__).'/dompdf/autoload.inc.php';

// instantiate and use the dompdf class
$pdf = new DOMPDF();

$CI =& get_instance();
$CI->dompdf = $pdf;

}
}
?>


View file



<body>

<div id="container">
<a target="_blank" class="pdfLink" href="<?php echo base_url('welcome'); ?>">download pdf</a>

<h1>Welcome to CodeIgniter!</h1>

<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>

<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>

</body>
</html>









share|improve this question






















  • You mean on load its downloading the file right ? And with the link you want to show your created pdf file or just a link to download pdf !
    – M. Alim
    Nov 12 at 6:16

















up vote
0
down vote

favorite












I installed codeigniter 3 and dompdf. I followed a tutorial what is working perfect. At the moment every time i load the view for example localhost/codeigniter/welcome , the PDF is loaded directly and offered to download.
Instead i would rater like to include a clickable link the view page where the user can view the page and can decide if he want to download the page as pdf. i cant work out how to create the link. What i would need to change in my controller so the customer can view before download the page as pdf and how create the link.



Any help would be appericated



controller Welcome.php



<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

public function index()
{
$this->load->view('welcome_message');

// Get output html
$html = $this->output->get_output();

// Load pdf library
$this->load->library('pdf');

// Load HTML content
$this->dompdf->loadHtml($html);

// (Optional) Setup the paper size and orientation
$this->dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$this->dompdf->render();

// Output the generated PDF (1 = download and 0 = preview)
$this->dompdf->stream("welcome.pdf", array("Attachment"=>0));
}
}


libraries PHP



 <?php defined('BASEPATH') OR exit('No direct script access allowed');

// reference the Dompdf namespace
use DompdfDompdf;

class Pdf
{
public function __construct(){

// include autoloader
require_once dirname(__FILE__).'/dompdf/autoload.inc.php';

// instantiate and use the dompdf class
$pdf = new DOMPDF();

$CI =& get_instance();
$CI->dompdf = $pdf;

}
}
?>


View file



<body>

<div id="container">
<a target="_blank" class="pdfLink" href="<?php echo base_url('welcome'); ?>">download pdf</a>

<h1>Welcome to CodeIgniter!</h1>

<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>

<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>

</body>
</html>









share|improve this question






















  • You mean on load its downloading the file right ? And with the link you want to show your created pdf file or just a link to download pdf !
    – M. Alim
    Nov 12 at 6:16















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I installed codeigniter 3 and dompdf. I followed a tutorial what is working perfect. At the moment every time i load the view for example localhost/codeigniter/welcome , the PDF is loaded directly and offered to download.
Instead i would rater like to include a clickable link the view page where the user can view the page and can decide if he want to download the page as pdf. i cant work out how to create the link. What i would need to change in my controller so the customer can view before download the page as pdf and how create the link.



Any help would be appericated



controller Welcome.php



<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

public function index()
{
$this->load->view('welcome_message');

// Get output html
$html = $this->output->get_output();

// Load pdf library
$this->load->library('pdf');

// Load HTML content
$this->dompdf->loadHtml($html);

// (Optional) Setup the paper size and orientation
$this->dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$this->dompdf->render();

// Output the generated PDF (1 = download and 0 = preview)
$this->dompdf->stream("welcome.pdf", array("Attachment"=>0));
}
}


libraries PHP



 <?php defined('BASEPATH') OR exit('No direct script access allowed');

// reference the Dompdf namespace
use DompdfDompdf;

class Pdf
{
public function __construct(){

// include autoloader
require_once dirname(__FILE__).'/dompdf/autoload.inc.php';

// instantiate and use the dompdf class
$pdf = new DOMPDF();

$CI =& get_instance();
$CI->dompdf = $pdf;

}
}
?>


View file



<body>

<div id="container">
<a target="_blank" class="pdfLink" href="<?php echo base_url('welcome'); ?>">download pdf</a>

<h1>Welcome to CodeIgniter!</h1>

<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>

<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>

</body>
</html>









share|improve this question













I installed codeigniter 3 and dompdf. I followed a tutorial what is working perfect. At the moment every time i load the view for example localhost/codeigniter/welcome , the PDF is loaded directly and offered to download.
Instead i would rater like to include a clickable link the view page where the user can view the page and can decide if he want to download the page as pdf. i cant work out how to create the link. What i would need to change in my controller so the customer can view before download the page as pdf and how create the link.



Any help would be appericated



controller Welcome.php



<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

public function index()
{
$this->load->view('welcome_message');

// Get output html
$html = $this->output->get_output();

// Load pdf library
$this->load->library('pdf');

// Load HTML content
$this->dompdf->loadHtml($html);

// (Optional) Setup the paper size and orientation
$this->dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$this->dompdf->render();

// Output the generated PDF (1 = download and 0 = preview)
$this->dompdf->stream("welcome.pdf", array("Attachment"=>0));
}
}


libraries PHP



 <?php defined('BASEPATH') OR exit('No direct script access allowed');

// reference the Dompdf namespace
use DompdfDompdf;

class Pdf
{
public function __construct(){

// include autoloader
require_once dirname(__FILE__).'/dompdf/autoload.inc.php';

// instantiate and use the dompdf class
$pdf = new DOMPDF();

$CI =& get_instance();
$CI->dompdf = $pdf;

}
}
?>


View file



<body>

<div id="container">
<a target="_blank" class="pdfLink" href="<?php echo base_url('welcome'); ?>">download pdf</a>

<h1>Welcome to CodeIgniter!</h1>

<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>

<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
</div>

</body>
</html>






php codeigniter-3 dompdf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 18:12









Pascal Westrich

105




105












  • You mean on load its downloading the file right ? And with the link you want to show your created pdf file or just a link to download pdf !
    – M. Alim
    Nov 12 at 6:16




















  • You mean on load its downloading the file right ? And with the link you want to show your created pdf file or just a link to download pdf !
    – M. Alim
    Nov 12 at 6:16


















You mean on load its downloading the file right ? And with the link you want to show your created pdf file or just a link to download pdf !
– M. Alim
Nov 12 at 6:16






You mean on load its downloading the file right ? And with the link you want to show your created pdf file or just a link to download pdf !
– M. Alim
Nov 12 at 6:16



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251718%2finsert-download-link-in-view-file-codeignitor-3-and-dompdf%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251718%2finsert-download-link-in-view-file-codeignitor-3-and-dompdf%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values