微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PDFMAKE:在列表视图中单击按钮生成不同的 PDF

如何解决PDFMAKE:在列表视图中单击按钮生成不同的 PDF

我正在使用 CouchCMS 和 pfdmake。

我有一个使用通过 couchcms 生成自定义路由的列表视图。

<cms:pages masterpage="data.PHP" paginate="1" limit="50" orderby='publish_date' custom_field="status_fifty!='No'" show_future_entries='1' >
    <!-- List generation logic here -->
</cms:pages>

此列表视图有一个按钮,用于使用 ajax 生成 pdf。

            $("button#pdf").click(function() {
                $.ajax({
                    type: "GET",url: "<cms:show k_site_link />pdf-generate-ajax.PHP",data: {
                        id: $(this).attr("data-id")
                    },success: function(data){
                        // alert(dd);

                        var blob = new Blob([data]);
                        
                        window.open(URL.createObjectURL(blob));
                        
                    },error: function (XMLHttpRequest,textStatus,errorThrown) 
                    {
                        alert('Error occurred while opening fax template' 
                              + getAjaxErrorString(textStatus,errorThrown));
                    }
                    // success: function(data){
                    //  var blob = new Blob([data]);
                    //  window.open(URL.createObjectURL(blob));
                    // }
                });
            })

ajax 运行成功,但 pdf 为空白。

async function generatePDF() {
            var str = "Calling,Street View.";
            var res = str.toupperCase();
            var imageWidth = 476.224;
            // var imageHeight = 210.4725;
            var imageHeight= 280.63;
            var dd = {
                pageSize: 'A4',pageMargins: [ 40,40,40 ],footer: function(page) { 
                    { 
                        return {
                            columns: [
                                {
                                    text: '* KINDLY NOTE BUILDING NUMBER AND UNIT RANGES CONFIRMED BY ' + res,style: 'footerComment',alignment: 'center'
                                }
                            ]
                        };
                    }
                },content: [
                    {
                        table: {
                            widths: ['*'],body: [
                                                            [
                                    {
                                        style: 'header',text: 'Still Water Apartments2'
                                    }
                                ],[
                                    {
                                        style: 'address',text: '5901 Leopard St; Corpus Christi; TX 78409,210-248-9443',}
                                ],[
                                    ''
                                ],[
                                    {
                                        image: await this.getBase64ImageFromURL(
                                            "http://localhost/CTO/USGeoTagging/couch/uploads/attachments/ab9422df6cb6f0f5d215e89c916d7219.png"
                                        ),width: imageWidth,height: imageHeight,alignment: 'center'
                                    }
                                ],[
                                    {
                                        style: 'mapfrom',text: 'Map From:'
                                    }
                                ],[
                                    {
                                        style: 'mapfromUrl',text: 'https://www.gxcpl.com/asdfasd',link: 'https://www.gxcpl.com/asdfasd'
                                    }
                                ],[
                                    {
                                        table: {
                                            widths: ['45%','55%'],body: [
                                                [
                                                    'APARTMENT DETAILS','BUILDING NUMBER & UNIT RANGES *'
                                                ]
                                            ]
                                        },layout: 'noBorders'
                                    }
                                ],[
                                    {
                                        table: {
                                            widths: ['20%','25%','50%'],body: [
                                                [
                                                    {
                                                        style: 'contentTextBold',text:'DELIVERY PARKING\nLEASING OFFICE\nMAIL ROOM\nDIRECTIONALITY\nNO. OF ENTRANCES\nACCESS TYPE\nGATE\nGATE TYPE\nGATE (L)\n\nLOADING DOCK'
                                                    },{
                                                        style: 'contentTextnormal',text:': Yes,Building wise\n: Yes\n: No\n: 0\n: 1\n: Blank\n: No\n: Blank\n: Locked Gate,used in case of Emergency\n: No'
                                                    },{
                                                        table: {
                                                            body: [
                                                                                                                                                                                                                                                                        [
                                                                    {
                                                                        text: 'Building #',style: 'contentTextBold'
                                                                    },{
                                                                        text: 'Unit #',style: 'contentTextBold'
                                                                    }
                                                                ],[
                                                                    {
                                                                        text: 'BLDG #1',style: 'contentTextnormal'
                                                                    },{
                                                                        text: '1-10',style: 'contentTextnormal'
                                                                    }
                                                                ]
                                                                                                                                                                                                
                                                            ],alignment: 'center'
                                                        },}
                                                ]
                                            ]
                                        },layout: 'noBorders'
                                    }
                                ]
                                                        ]
                        },layout: 'noBorders'
                    }
                ],styles: {
                    header: {
                        fontSize: 16,bold: 'true'
                    },address: {
                        fontSize: 10,mapfrom: {
                        fontSize: 6,mapfromUrl: {
                        fontSize: 6,color: 'blue'
                    },contentTextBold: {
                        fontSize: 9,bold: true
                    },contentTextnormal: {
                        fontSize: 9
                    },footerComment: {
                        fontSize: 5
                    }
                },defaultStyle: {
                    alignment: 'justify'
                }
            }
            pdfMake.createPdf(dd).open();   

        }

如何才能显示 pdf 内容? 该 blob 已生成显示在新选项卡中,但它是空白的。

问候

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。