我想在HTML div标签内打印图像。 这是我的代码:
HTML5:
section, genre
JAVASCRIPT:
<span>
<img src="/images/pag.jpg" alt="pagsanghan Logo" style="opacity: .8; height:100px; width:100px;">
</span>
答案 0 :(得分:0)
您需要首先将图像转换为base64
图像。并将该代码添加到img标签的src中。然后打印功能将打印图像
在此link
中将图像转换为base64
window.print();
@media print {
#monthly-report {
background-color: white;
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
}
}
<span id="monthly-report">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxATEhUQEA8RDhAQEg8SFRgVEBARGBYVFhEXGBUSExgYHiggGB0lJxcVIjEhJSkrLi4uFyAzODMsNzQuLisBCgoKDg0OGxAQGy0lICUvLS8tLS8tLS0xLS0tLS8tLy4tNS0tLS0tLS0tLS0tNS4tLS8tLS8tLS0tLS0tLS0tLf/AABEIAMMBAgMBEQACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAABQYBBAcDAv/EAEoQAAIBAQMHBggLBgUFAAAAAAABAgMEBREGEiExQVFxEyJhgZGhBzJCVHKTwdEVIzNSU2KSo7Gy0hQWNHOi8SRDgoPwRGOz4eL/xAAbAQEAAgMBAQAAAAAAAAAAAAAABAUCAwYBB//EADQRAQACAQICBwgBAwUBAAAAAAABAgMEESExBRJBUVJxkRMUImGBobHRMhUzNELB4fDxI//aAAwDAQACEQMRAD8A7iAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPC1WylTWdVqQpLfOcYrvMZtEc5Z0x3vO1YmfJD2nLOwQ/z89/UhOfelh3mqdTjjtTcfReqvypt57Q0KnhCsa1Qry4Qp+2aMJ1eP5pEdCamee0fX/h8x8Ilk+itK/0Uv1nnvlO6Xs9B6jvr6z+m1Ry7sMtc6lP0qU3+XEzjVY5ardD6qOURP1hK2O/bJV0U7RSk3sz0pfZek21y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