Как динамически загрузить изображение в printview с помощью функции document.write

Следующее прост и работает для меня:

 bool hasMyColumn = (reader.GetSchemaTable().Select("ColumnName = 'MyColumnName'").Count() == 1);
0
задан ScrapCode 18 January 2019 в 05:25
поделиться

2 ответа

Нашли решение из здесь :

Кажется, мне нужно использовать setTimeout

setTimeout(function() {
newWindow.print();
newWindow.close();
}, 250);
0
ответ дан Rakesh Sadhula 18 January 2019 в 05:25
поделиться

Речь идет об ожидании загрузки контента

<script>
var printContent = '<h1>Hello World</h1>';
var mywindow = window.open('about:blank', 'PRINT', 'height=400,width=600');

//~ mywindow.onload = function() {
mywindow.document.write('<html><head><title>'+"Contract Approval Form"+'</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<div id="headerLogo"></div>');
mywindow.document.write('<div id="watermarkDiv"></div>');
mywindow.document.write('<div style="margin-top:50px;" id="content">' +printContent+ '</div>');
var img = mywindow.document.createElement('img');
img.setAttribute('src', 'mylogo.png');
img.onload = function() {
    // now you can print, need to wait for image to load - which connotes you need to work out how to wait for all content to load
    mywindow.focus();
    mywindow.print();

}

mywindow.document.getElementById("headerLogo").appendChild(img);
mywindow.document.write('</body></html>');

</script>
0
ответ дан David Bray 18 January 2019 в 05:25
поделиться
Другие вопросы по тегам:

Похожие вопросы: