WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Print image (6 posts)

  1. krnauta
    Member
    Posted 2 years ago #

    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???

  2. gavintfn
    Member
    Posted 2 years ago #

    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...

  3. krnauta
    Member
    Posted 2 years ago #

    Thks, but doesn't work...

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

  4. gavintfn
    Member
    Posted 2 years ago #

    link your page pls..

  5. krnauta
    Member
    Posted 2 years ago #

    Sorry the web is in locahost

    The html code:

    <script language="javascript">
    function imprimer(){
    
    fenetre=window.open("http://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

  6. krnauta
    Member
    Posted 2 years ago #

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

    Source:

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

    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
    	<script type="text/javascript">
    	// <!--
    	/*
    	 * See: http://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>';
    
      ?>

Topic Closed

This topic has been closed to new replies.

About this Topic