• Resolved krnauta

    (@krnauta)


    Hi all,

    I need to print only the image.

    My code is:

    <?php 
    
    $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
    $url = $thumb['0'];
    
    echo '<script language="javascript">
    function imprimer(){
    
    fenetre=window.open("'.$url.'" );
    fenetre.print();
    fenetre.top.close();
    }
    </script>';
    echo '<a href="javascript:imprimer()">Imprimer</a>';
    
      ?>

    It’s not working ??

    Any idea???

Viewing 5 replies - 1 through 5 (of 5 total)
  • i think (maybe) your variable is not passing to java…
    try:

    ‘echo ‘<script language=”javascript”>
    function imprimer(){

    fenetre=window.open(“‘;
    echo $url;
    echo ‘” );
    fenetre.print();
    fenetre.top.close();
    }
    </script>’;

    also, (maybe)if there is more than one url in array $thumb[0] you should use a foreach statement…

    Thread Starter krnauta

    (@krnauta)

    Thks, but doesn’t work…

    Maybe the best idea it’s make a print.css

    link your page pls..

    Thread Starter krnauta

    (@krnauta)

    Sorry the web is in locahost

    The html code:

    <script language="javascript">
    function imprimer(){
    
    fenetre=window.open("https://localhost:8888/cocina/wp-content/uploads/2012/07/leon.jpg" );
    fenetre.print();
    fenetre.top.close();
    }
    </script><a href="javascript:imprimer()">Imprimer</a>

    The print windows its opening Ok, but not image

    Thread Starter krnauta

    (@krnauta)

    Hi,
    I found the solutions. Maybe is useful for somebody

    Source:

    https://dynom.nl/jquery/print_popup.html

    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
    	<script type="text/javascript">
    	// <!--
    	/*
    	 * See: https://blog.dynom.nl/archives/Javascript-printing-a-popup-window_20091029_52.html
    	 */
    
    	/**
    	 * To put it in jQuery terms:
    	 */
    	Popup = {
    
    		init : function () {
    			$('a.action_print').bind('click', Popup.printIt);
    		},
    
    		printIt : function () {
    			var win = window.open('', 'Image', 'resizable=yes,...');
    			if (win.document) {
    				win.document.writeln('<img src="'+ $(this).attr('href') +'" alt="image" />');
    				win.document.close();
    				win.focus();
    				win.print();
    			}
    
    			return false;
    		}
    	}
    
    	$(document).ready(function () {
    		Popup.init();
    	});
    
    	// -->
    	</script>

    And put this in your theme:

    <?php 
    
    $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
    $urls = $thumb['0'];
    echo '<a class="action_print" href="'.$urls.'">Print image</a>';
    
      ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Print image’ is closed to new replies.