When pdf.js loads the pdf file for the first time, the pdf file cannot be found, and the pdf file will not appear until it is refreshed.

after the foreground clicks the file name, the background converts the doc file into a pdf file through openoffice, and then stores it in the server tomcat". After pdf.js loads the transformed pdf file in tomcat in the server for the first time, it will show that the pdf file does not exist, and the pdf file can be displayed successfully after the second refresh. How to make a preview of the pdf file appear the first time it is loaded.

<iframe id="product-doc" style="display: none;" src=""></iframe>
function fileView(fileId) {
    $.ajax({
        url: MMBS_IP + "/resources/rest/climate/alarm/showDocOnlineView",
        data: {
            fileId: fileId
        },
        type: "get",
        async: true,
        beforeSend: ajaxLoading,
        success: function(data) {
            console.log(data);
            var name = data.name.split(".",1)
            if(data.type == "img"){
                var strHtml = "";
                var imgUrl = MMBS_IP + "/resources/rest/getImageStream?imgPath=" + data.name;
                var downLoadPath = """+ data.name +"""
                strHtml += "<button id="img-download" onclick="imgDownload(";
                strHtml += downLoadPath
                strHtml += ")"></button>"
                strHtml += "<img id="product-img" style="width: 100%;height: 100%;" src=""+ imgUrl +""/>";
                var imgName = data.name.split("/")
                $("-sharpproduct-win-img").show();
                $("-sharpproduct-win-img").html(strHtml);
                $("-sharpproduct-win-img").window({
                    title: imgName[imgName.length-1].split(".",1),
                    width: 1400,
                    height: 800
                });
            }else {
                var path = MMBS_IP + "/resource/generic/web/viewer.html?file=" + data.name
                console.log(path);
                $("-sharpproduct-doc").attr("src", path);
                $("-sharpproduct-doc").show();
                $("-sharpproduct-doc").window({
                    title: name,
                    width: 1400,
                    height: 800
                });
            }
        },
        error: function(xhr, textStatus) {
            $.messager.alert("", "!", "info");
        },
        complete: ajaxLoadEnd
    });
};
@RequestMapping(value = "showDocOnlineView", method = RequestMethod.GET)
    public @ResponseBody Map<String, Object> showDocOnlineView(HttpServletRequest request, HttpServletResponse response) 
    {
        Map<String,Object> file = FileMgrService.findFileById(Integer.parseInt(request.getParameter("fileId")));
        Map<String, Object> resultMap = new HashMap<String, Object>();
        String path = request.getServletContext().getRealPath("/resource/generic/web/" + file.get("display_name").toString() +".pdf");
        String name = "";
        if (file.get("file_type").toString().equals("img")) {
            name = file.get("file_path").toString();
        }else {
            try {
                name = file.get("display_name").toString() +".pdf";
                File inputFile = new File(file.get("file_path").toString());  
                File outputFile = new File(path);  
                DOC2PDFUtil dp = new DOC2PDFUtil(inputFile,outputFile);
                dp.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        resultMap.put("type", (file.get("file_type")));
        resultMap.put("name", name);
        return resultMap;
    }

screenshot of failed loading for the first time

iframe



Mar.20,2021

is your conversion from word to pdf real-time?
if so, why not consider early conversion, because the conversion process takes time, and it may not be as good as the conversion on the first request.


first of all, when you load for the first time, click the console to "Network" to see what errors are reported when you request the pdf file.


have you solved the problem? I have also encountered it in the past two days, and I have been unable to find the reason

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e45d0f-443a4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e45d0f-443a4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?