2

I'm using php-script to export Joomla article to PDF-file with mPDF.

The script is shortly the following:

define('_JEXEC', 1);    
define('JPATH_BASE', realpath(dirname(__FILE__) . '/..'));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';

require_once JPATH_BASE . '/mPDF/vendor/autoload.php';

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
$session = JFactory::getSession();
$config = JFactory::getConfig();

$url = urldecode("my-article-url");
$html = file_get_contents($url);

$mpdf = new \Mpdf\Mpdf();

$mpdf->setBasePath($url);
$mpdf->WriteHTML($html);

$file_name = 'myfile.pdf';
$mpdf->Output($file_name, 'D');

It works ok, when the article is published, but when I set the access of the article to Registered, the script cannot get the article contents anymore.

How would it be possible to access article content when its access level is not Public?

3
  • As a "Guest" user, you cannot access non-public articles. You would need to write a query to the database to pull the content of the article. – James Shaver Dec 15 '20 at 17:48
  • @user Welcome to JSE. Please take our tour. – mickmackusa Dec 16 '20 at 5:28
  • OK, thanks! Actually I tried to pull the article data with a query, but I have several content plugins in that article like Sourcerer etc and I wasn't able to get the article text as processed by the content plugins :( E.g. with sourcerer I get the pure php-code as part of the article text. – user3112031 Dec 16 '20 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.