Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6749715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:43:24+00:00 2026-05-26T12:43:24+00:00

i was wondering if this setup would work. i have to crank out a

  • 0

i was wondering if this setup would work. i have to crank out a batch of PDF from a bunch of variables i’m pushing into the $_SESSION via a form (duh…). the idea is to pass the template file to the dompdf engine and have the template populate from the $_SESSION then out to PDF. it seems to me that when the $template gets loaded it should do that, yes?

here’s the basic code:

<?php
function renderToPDF($theTemplate = "template.php") // this is just to show the value
{
  require_once("dompdf/dompdf_config.inc.php");

  $content = file_get_contents($theTemplate); 

  if ($content !== false)
  {
    $dompdf = new DOMPDF();
    $dompdf->load_html($content);
    $dompdf->render();
    $dompdf->stream("kapow_ItWorks.pdf");
  }
}
?>

and this is the template.php file (basically… you don’t want all 16 pages…)

<html>
<meta>
<head>
  <link href="thisPage.css" type="text/css" rel="stylesheet">
</head>
  <body>
    <h1><?php echo $_SESSION['someTitle'] ?></h1>
    <h2>wouldn't it be nice, <?php echo $_SESSION['someName'] ?></h2>
  </body>
</html>

so my thinking is that the template.php will pull the variables right out of the $_SESSION array without any intervention, looking like this:

BIG TITLE

wouldn’t it be nice, HandsomeLulu?

i guess the nut of the question is: Do $_SESSION variables get evaluated when PHP files are loaded, but not rendered?

WR!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:43:25+00:00Added an answer on May 26, 2026 at 12:43 pm

    for some reason, the code ON the page that calls the function ALSO gets dumped into the file. this was placed before the header. i understand now why: i wasn’t referencing an external page, i was importing and external page. don’t know why that didn’t click.

    anyway. as soon as i got rid of the page’s extra stuff, it worked just fine. in retrospect, what dompdf needed to state was quite simply that NO HTML of ANY kind (echo, print, &c.) can be on the page that calls the function. at least that what it appears to require at this level of my knowledge.

    for those who, like me, are floundering in a misma of ‘everything but the answer’, here’s the bare bones code that did the job:

    buildPDF.php:

    <?php
    session_start();
    $_SESSION['someTitle'] = "BIG FAT TITLE";
    $_SESSION['someName'] = "HandomeLu";
    
    $theTemplate = 'template.php';
    
    function renderToPDF($templateFile)
    {
      require_once("_dox/dompdf/dompdf_config.inc.php");
      ob_start();
      include $templateFile;
      $contents = ob_get_clean(); 
    
      if ($contents !== false)
      {
        $dompdf = new DOMPDF();
        $dompdf->load_html($contents);
        $dompdf->render();
        $dompdf->stream("kapow_ItWorks.pdf");
     }
    }
    
    renderToPDF($theTemplate);
    ?>
    

    and this is the template.php:

        <!DOCTYPE HTML>
        <html>
        <meta>
        <head>
          <meta charset="utf-8">
          <link href="thisPage.css" type="text/css" rel="stylesheet">
        </head>
        <body>
          <h1><?php echo $_SESSION['someTitle'] ?></h1>
          <p>wouldn't it be nice, <?php echo $_SESSION['someName'] ?></p>
        </body>
       </html>
    

    also note that the external CSS file reads in just fine. so you can still keep the structure and style separate. also, the $_SESSION variables can be set anywhere, obviously, i just set them here to keep testing easy.

    hope this is useful for those getting started with this GREAT class. if you’re looking to get up and running cranking out PDF files, this kicks so much butt, it should have a trigger and a grip on it. 🙂

    thanks to everyone who commented. you got me in the place i needed to be. 🙂

    this site ROCKS.

    WR!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if this is going to work... Say i have a project template
Cascading deletes aren't setup on this particular database. Just wondering if there's a way
I have a setup with 2GB of memory and I would like to map
So I have this kind of setup class Base { public: Base(); virtual void
I have an existing pdf that I am filling out dynamically in java. I
I've been wondering this for a while, and Google hasn't provided me with the
Just wondering is this kind of code recommended to increase performance? void functionCalledLotsofTimes() {
Just wondering about this code below... when I turn off my internet connection and
I been wondering about this for a while. It seems like there are so
I'm wondering if this is a sufficient algorithm for finding the best value with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.