0

我想创建一个文件PDF,我想从Express EDGE JS.

从节点 ExpressJSserver.js文件我有:

const express = require("express");
const cors = require("cors");
const cookieParser = require('cookie-parser');
const { config, engine } = require('express-edge');
const bodyParser = require('body-parser');

const app = express();

// Automatically sets view engine and adds dot notation to app.render
app.use(engine);
app.set('views', `${__dirname}/views`);

var corsOptions = {
    origin: "http://localhost:3000",
    credentials: true  
};

app.use(cors(corsOptions));

app.use(cookieParser())

app.use(express.static('public'));

// routes of api
app.use(require('./routes/route'))
app.use(errorHandler);

// set port, listen for requests
const PORT = process.env.PORT || 9090;
app.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}.`);
});

例如,我有这个代码来获取渲染并添加到常量或变量:

const creatPdfFromEdgeJSRender = async (request, response) => {

    const { documentTarget, docTargetId } = request.params;

    // render view maked with EDGE JS to be add as a HTML Elements to create a PDF File
    const fileRendered = response.render('print/printcenter', {
        componentName: documentTarget,
        componentId: docTargetId,
        withoutFooterLayout: true
    });

    // to create a pdf file that I want to render after 
    createPdfFile('./renderedFile.pdf', fileRendered)
}

4

0 回答 0