Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2017 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/f494002daf7cce58372a9afd040185cb to your computer and use it in GitHub Desktop.
Save anonymous/f494002daf7cce58372a9afd040185cb to your computer and use it in GitHub Desktop.
<?php
/**
* Creates the PDF
*/
function dkpdfg_output_pdf() {
// include mPDF library from DK PDF
include( ABSPATH . '/wp-content/plugins/dk-pdf/includes/mpdf60/mpdf.php' );
// page orientation
$dkpdf_page_orientation = get_option( 'dkpdf_page_orientation', '' );
if ( $dkpdf_page_orientation == 'horizontal') {
$format = 'A4-L';
} else {
$format = 'A4';
}
// font size
$dkpdf_font_size = get_option( 'dkpdf_font_size', '12' );
$dkpdf_font_family = '';
// margins
$dkpdf_margin_left = get_option( 'dkpdf_margin_left', '15' );
$dkpdf_margin_right = get_option( 'dkpdf_margin_right', '15' );
$dkpdf_margin_top = get_option( 'dkpdf_margin_top', '50' );
$dkpdf_margin_bottom = get_option( 'dkpdf_margin_bottom', '30' );
$dkpdf_margin_header = get_option( 'dkpdf_margin_header', '15' );
// creating and setting the pdf
$mpdf = new mPDF('utf-8', $format, $dkpdf_font_size, $dkpdf_font_family,
$dkpdf_margin_left, $dkpdf_margin_right, $dkpdf_margin_top, $dkpdf_margin_bottom, $dkpdf_margin_header
);
// write cover
$dkpdf_show_cover = get_option( 'dkpdfg_show_cover', 'on' );
if( $dkpdf_show_cover == 'on' ) {
$pdf_cover = dkpdfg_get_template( 'dkpdfg-cover' );
$mpdf->WriteHTML( $pdf_cover );
}
// write TOC
$dkpdf_show_toc = get_option( 'dkpdfg_show_toc', 'on' );
if( $dkpdf_show_toc == 'on' ) {
$toc_title = get_option( 'dkpdfg_toc_title', 'Table of contents' );
$mpdf->WriteHTML('<tocpagebreak toc-preHTML="&lt;h2&gt;'. $toc_title .'&lt;/h2&gt;" paging="on" links="on" resetpagenum="1" toc-odd-footer-value="-1" toc-odd-header-value="-1" />');
$mpdf->h2toc = array( 'H1'=>0 );
$mpdf->h2bookmarks = array( 'H1'=>0 );
}
// header
$pdf_header_html = dkpdf_get_template( 'dkpdf-header' );
$mpdf->SetHTMLHeader( $pdf_header_html, 'O', TRUE );
// footer
$pdf_footer_html = dkpdf_get_template( 'dkpdf-footer' );
$mpdf->SetHTMLFooter( $pdf_footer_html );
// write content
$mpdf->WriteHTML( dkpdfg_get_template( 'dkpdfg-index' ) );
// output PDF
$mpdf->Output();
//$mpdf->Output( 'dk-pdf-generator.pdf', 'D' );
/*
$cover_title = get_option( 'dkpdfg_cover_title', '' );
if( $cover_title != '' ) {
$mpdf->Output( $cover_title . '.pdf', 'D' );
} else {
$mpdf->Output( 'dk-pdf-generator.pdf', 'D' );
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment