template_data = $template_data;
$this->order_data = $order_data;
$this->company_data = $company_data;
}
/**
* Generate complete HTML document
*/
public function generate() {
$html = '';
$html .= '';
$html .= '
';
$html .= '';
$html .= '';
$html .= 'Document PDF';
$html .= $this->generate_styles();
$html .= '';
$html .= '';
$html .= $this->generate_content();
$html .= '';
$html .= '';
return $html;
}
/**
* Generate only content (for preview/modal).
*/
public function generate_content() {
$canvas_width = intval( $this->template_data['canvasWidth'] ?? 794 );
$canvas_height = intval( $this->template_data['canvasHeight'] ?? 1123 );
$html = '';
$elements = $this->template_data['elements'] ?? array();
$html .= ElementGeneratorFactory::generate_multiple( $elements, $this->order_data, $this->company_data );
$html .= '
';
return $html;
}
/**
* Generate CSS styles for the standalone PDF HTML document.
* CSS rules are loaded from plugin/assets/css/pdf-document.css.
*/
private function generate_styles(): string {
$css_file = plugin_dir_path( __FILE__ ) . '../../assets/css/pdf-document.css';
if ( ! is_readable( $css_file ) ) {
return '';
}
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
global $wp_filesystem;
$css = $wp_filesystem->get_contents( $css_file );
return '';
}
}