HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: /volume1/web/qrcodesforeveryone/wp-content/plugins/dk-pdf/api.php
<?php
/**
 * DK PDF Public API
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Generate a PDF for a post and save it to a file.
 *
 * Must be called after plugins_loaded (priority 10).
 *
 * Usage:
 *   $path = dkpdf_generate( 42 );
 *   $path = dkpdf_generate( 42, [ 'output_path' => '/path/to/file.pdf' ] );
 *   $path = dkpdf_generate( 42, [ 'title' => 'Custom Title' ] );
 *
 * @param int   $post_id The post ID to generate PDF for.
 * @param array $args    Optional arguments:
 *                       - 'output_path' (string) Full file path for the PDF.
 *                       - 'title' (string) Override PDF document title/filename.
 *                       - 'format' (string) Page size, e.g. 'A4', 'Letter', 'A4-L'.
 * @return string|WP_Error File path on success, WP_Error on failure.
 */
function dkpdf_generate( int $post_id, array $args = [] ) {
	try {
		$container = \Dinamiko\DKPDF\Container::container();
	} catch ( \LogicException $e ) {
		return new WP_Error(
			'plugin_not_initialized',
			__( 'DK PDF plugin is not initialized yet. Make sure to call this function after plugins_loaded.', 'dkpdf' )
		);
	}

	$generator = $container->get( 'pdf.programmatic_generator' );

	return $generator->generate( $post_id, $args );
}