function kalins_pdf_page_shortcode_replace($str, $page)
{
    //replace all passed in shortcodes
    $SCList = array("[ID]", "[post_title]", "[post_name]", "[guid]", "[comment_count]");
    //[post_date], "[post_date_gmt]", "[post_modified]", [post_modified_gmt]
    $l = count($SCList);
    for ($i = 0; $i < $l; $i++) {
        //loop through all page shortcodes (the ones that only work for before/after page/post and refer directly to a page/post attribute)
        $scName = substr($SCList[$i], 1, count($SCList[$i]) - 2);
        $str = str_replace($SCList[$i], $page->{$scName}, $str);
    }
    $str = str_replace("[post_permalink]", get_permalink($page->ID), $str);
    $postCallback = new KalinsPDF_callback();
    if (preg_match('#\\[ *post_excerpt *(length=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', $str)) {
        if ($page->post_excerpt == "") {
            //if there's no excerpt applied to the post, extract one
            $postCallback->pageContent = strip_tags($page->post_content);
            $str = preg_replace_callback('#\\[ *post_excerpt *(length=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postExcerptCallback'), $str);
        } else {
            //if there is a post excerpt just use it and don't generate our own
            $str = preg_replace('#\\[ *post_excerpt *(length=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', $page->post_excerpt, $str);
        }
    }
    $postCallback->curDate = $page->post_date;
    //change the curDate param and run the regex replace for each type of date/time shortcode
    $str = preg_replace_callback('#\\[ *post_date *(format=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postDateCallback'), $str);
    $postCallback->curDate = $page->post_date_gmt;
    $str = preg_replace_callback('#\\[ *post_date_gmt *(format=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postDateCallback'), $str);
    $postCallback->curDate = $page->post_modified;
    $str = preg_replace_callback('#\\[ *post_modified *(format=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postDateCallback'), $str);
    $postCallback->curDate = $page->post_modified_gmt;
    $str = preg_replace_callback('#\\[ *post_modified_gmt *(format=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postDateCallback'), $str);
    $postCallback->page = $page;
    $str = preg_replace_callback('#\\[ *post_author *(type=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postAuthorCallback'), $str);
    $str = preg_replace_callback('#\\[ *post_meta *(name=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postMetaCallback'), $str);
    $str = preg_replace_callback('#\\[ *post_categories *(delimeter=[\'|\\"]([^\'\\"]*)[\'|\\"])? *(links=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postCategoriesCallback'), $str);
    $str = preg_replace_callback('#\\[ *post_tags *(delimeter=[\'|\\"]([^\'\\"]*)[\'|\\"])? *(links=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postTagsCallback'), $str);
    $str = preg_replace_callback('#\\[ *post_comments *(before=[\'|\\"]([^\'\\"]*)[\'|\\"])? *(after=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'commentCallback'), $str);
    $str = preg_replace_callback('#\\[ *post_parent *(link=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postParentCallback'), $str);
    $str = preg_replace_callback('#\\[ *post_thumb *(size=[\'|\\"]([^\'\\"]*)[\'|\\"])? *(extract=[\'|\\"]([^\'\\"]*)[\'|\\"])? *\\]#', array(&$postCallback, 'postThumbCallback'), $str);
    $str = kalins_pdf_global_shortcode_replace($str);
    //then parse the global shortcodes
    return $str;
}
        $objTcpdf->writeHTML($strHtml, true, 0, true, 0);
        //$proBar->increase();
    }
} catch (Exception $e) {
    $outputVar->status = "problem creating pages and posts. Perhaps there's a problem with one of the pages you've selected or with the before or after HTML.";
    die(json_encode($outputVar));
}
try {
    if ($finalPage != "") {
        $objTcpdf->AddPage();
        //create final page in pdf
        $objTcpdf->SetFont(PDF_FONT_NAME_MAIN, '', $fontSize);
        if ($isSingle) {
            $finalPage = kalins_pdf_page_shortcode_replace($finalPage, $result[0]);
        } else {
            $finalPage = kalins_pdf_global_shortcode_replace($finalPage);
        }
        $strHtml = wpautop($finalPage, true);
        $totalHTML = $totalHTML . $strHtml;
        $totalTXT = $totalTXT . $finalPage;
        $objTcpdf->writeHTML($strHtml, true, 0, true, 0);
    }
} catch (Exception $e) {
    $outputVar->status = "problem creating final page.";
    die(json_encode($outputVar));
}
try {
    if ($includeTOC) {
        // add a new page for TOC
        $objTcpdf->addTOCPage();
        // write the TOC title