Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Viljami Kuosmanen

    (@zuige)

    Can you try cloning this branch from github and see if the issue still persists?

    https://github.com/anttiviljami/wp-pdf-templates/tree/bugfix-localhost

    The current stable version doesn’t work on hosts, where localhost doesn’t point to the wordpress server. I have no idea why on some servers that’s not the case but it seems like there are some hosts that misconfigure theirs servers like that.

    If enough people say the bugfix works fine, i’ll just push a new version upstream.

    Cheers!

    Thread Starter Jamil Ahmed

    (@jimi007)

    I have just fixed that by changing line # 211 in wp-pdf-templates.php to this

    $link = $url['scheme'] .'://'. $_SERVER['SERVER_NAME'] . $url['path'];

    Now that issue is solved but now new error is still showing in debugging

    Unable to stream pdf: headers already sent

    If I disable debugging then a blank PDF is generated.

    Thread Starter Jamil Ahmed

    (@jimi007)

    After replacing with new branch from Github the issue is same..

    Debug output

    Notice: Use of undefined constant DOMPDF_DEFAULT_PAPER_SIZE - assumed 'DOMPDF_DEFAULT_PAPER_SIZE' in xxxxxxx/dev/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php on line 350
    Unable to stream pdf: headers already sent

    I have fixed DOMPDF_DEFAULT_PAPER_SIZE by setting it to ‘letter’ but now last issue still persist that is
    Unable to stream pdf: headers already sent

    I have searched about this and its seems its due to some space in file.. Any idea ?

    Plugin Author Viljami Kuosmanen

    (@zuige)

    $link = $url['scheme'] .'://'. $_SERVER['SERVER_NAME'] . $url['path'];

    This is not a very good fix. We can’t assume that the current wordpress installation is in the same domain. Did you try the branch i sent you? It automatically detects if https://localhost doesn’t work and falls back to what’s essentially your solution.

    Notice: Use of undefined constant DOMPDF_DEFAULT_PAPER_SIZE - assumed 'DOMPDF_DEFAULT_PAPER_SIZE' in xxxxxxx/dev/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php on line 350
    Unable to stream pdf: headers already sent

    This is because your site has started output before the template_redirect action. Maybe a rogue ?> somewhere in your code.

    Thread Starter Jamil Ahmed

    (@jimi007)

    Thank you for correction.

    I have revered all code as per new branch and using default theme with no other plugin. Still error below shown.

    Notice: Use of undefined constant DOMPDF_DEFAULT_PAPER_SIZE - assumed 'DOMPDF_DEFAULT_PAPER_SIZE' in xxxxxxx/dev/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php on line 350
    Unable to stream pdf: headers already sent

    If I replace DOMPDF_DEFAULT_PAPER_SIZE with ‘letter’ then blank PDF is displaying with hard refresh CTRL+SHIFT+R

    I have also defined below line
    define("DOMPDF_UNICODE_ENABLED", true);

    Plugin Author Viljami Kuosmanen

    (@zuige)

    Have you got wp cli enabled?

    Do you get any whitespace when running wp-cli eval exit ?

    Thread Starter Jamil Ahmed

    (@jimi007)

    Nope. sorry I do not have WP CLI.. but if you guide I will install

    Plugin Author Viljami Kuosmanen

    (@zuige)

    It just occured to me that you may have display_errors turned on, which might cause output to start prematurely due to warnings.

    Can you add these lines to your wp-config.php and see if it makes any difference?

    define('WP_DEBUG', false);
    define('WP_DEBUG_DISPLAY', false);
    define('SCRIPT_DEBUG', false);
    
    ini_set('display_errors', 0);
    ini_set('log_errors', 'On');

    I’ve also just pushed version 1.4.2, which contains the fix for the localhost issue. You should upgrade asap.

    Thread Starter Jamil Ahmed

    (@jimi007)

    Thanks for the update. Well errors are gone if I disable all debug as you suggested above. But PDF is still blank.

    Thread Starter Jamil Ahmed

    (@jimi007)

    After a lot of struggling and debugging I get the issue is with file_get_contents…. don’t know what is the perfect solution but I tried these

    when I var_dump $html it has false value and no content. After that I have changed

    $html = file_get_contents( $link, false, $context );
    with
    $html = wp_remote_fopen( $link );

    and pdf-preview and pdf both works and showing the post content… Images and fonts are not working now.

    Do you have any idea ?

    Thread Starter Jamil Ahmed

    (@jimi007)

    Do we need VPS for file_get_contents functionwork properly or this can work on any shared hosting.

    PHP Version 5.4.45
    allow_url_fopen On On

    I have tested at another host and latest version is working there
    PHP Version 5.5.33

    After changing PHP version to 5.5 v 1.4.2 is working fine…. Thank you for your all time on this matter.

    Plugin Author Viljami Kuosmanen

    (@zuige)

    Marking topic as resolved.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Warning: file_get_contents’ is closed to new replies.