Почему JS print не работает для изображений в Chrome - PullRequest
0 голосов
/ 11 февраля 2019

В моем проекте мне нужно сгенерировать html (некоторые таблицы, метки и т. Д.) С помощью qr-кода и распечатать его.Все работает нормально, кроме печати qr-кода в Chrome.Chrome не печатает qr-код, вот страница.Что я делаю не так?

<h:form id="printForm" prependId="false">
     ...
    <div style="background-color: #f8f8f8;">
        <button onclick="myFunction()" style="float: right;" class="btn btn-primary no-print">Печать</button>
        <div >
        <h:outputText id="print" value="#{formPrintController.content}" escape="false" style="line-height: 1"/>
        </div>
    </div>
    ...

</h:form>

JS-код

<script type="text/javascript">
     function myFunction() {
         var divToPrint=document.getElementById("print");
         newWin= window.open("");
         console.log(divToPrint.outerHTML);
         newWin.document.write(divToPrint.outerHTML);
         newWin.print();
         newWin.close();
     }
</script>

Контроллер

@Controller
@SpringViewScoped
public class FormPrintController{

    private String content;

    @PostConstruct
    public void init() throws IOException, DocumentException {
        ...

        HttpServletRequest request = (HttpServletRequest) 
        FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String url = request.getRequestURL().toString();
        String qr ="https://api.qrserver.com/v1/create-qr-code/?data="+url+"&size=50x50";
        content = "<img style=\"width:50px;height:50px\" src=\"" + qr+"\"/>";

        System.out.println(content);
        ...
    }
}

System.out.println (контент) результат:

<img style="width:50px;height:50px" src="https://api.qrserver.com/v1/create-qr-code/?data=http://localhost:8080/view/constructor-form/form-print.xhtml&size=50x50"/>

Я пытался напечатать его в Mozilla FireFox, все работает отлично.В чем проблема?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...