Skip to content
On this page

Export pdf

Below we will introduce how to use mxcad plug-in to achieve the export pdf function in CAD drawings. In this function, users can choose the drawing range and export the document in pdf format. The drawing to pdf function improves the readability and shareability of the file, and is also convenient for storage and processing, which is a very practical data conversion function.

Function implementation

  1. Set the export range

We can call MxCADUiPrPoint Method Obtain the export range.

ts
// Select export range.
let getPoint = new MxCADUiPrPoint();
getPoint.setMessage("\n Specifies the first point of the output range:");
// Gets the first corner of the range
let pt1 = await getPoint.go();
if (!pt1) return;

getPoint.setMessage("\n Specifies the second point of the output range:");
// Set the selection range dynamic fill style
getPoint.setUserDraw((currentPoint: McGePoint3d, worldDraw) => {
    // Set range box color as position
    worldDraw.setColor(0xFF0000);
    let pl = new McDbPolyline();
    pl.addVertexAt(pt1);
    pl.addVertexAt(new McGePoint3d(pt1.x, currentPoint.y))
    pl.addVertexAt(currentPoint);
    pl.addVertexAt(new McGePoint3d(currentPoint.x, pt1.y))
    pl.constantWidth = MxFun.screenCoordLong2Doc(2);
    pl.isClosed = true;
    worldDraw.drawMcDbEntity(pl);
    // Set the fill style in the range box
    let points = [];
    points.push(pt1.toVector3());
    points.push(new McGePoint3d(pt1.x, currentPoint.y).toVector3());
    points.push(currentPoint.toVector3());
    points.push(new McGePoint3d(currentPoint.x, pt1.y).toVector3())
    worldDraw.setColor(0x003244);
    worldDraw.drawSolid(points, 0.5)

});
// Set disable capture and ortho tracking
getPoint.setDisableOsnap(true);
getPoint.setDisableOrthoTrace(true);
// Gets the second corner of the range
let pt2 = await getPoint.go();
if (!pt2) return;
  1. Export the pdf

In the above steps we have obtained the scope of the pdf on the drawing, So we can direct call McObject.saveFileToUrl() Method to export target pdf. If you do not set the scope for exporting drawings, all drawings are exported by default.

ts
// Set parameters
let param = {
width: "2100",// length of drawing
height: "2970",// width of the drawing
bd_pt1_x: "" + pt1.x, // corner 1x
bd_pt1_y: "" + pt1.y, // corner 1y
bd_pt2_x: "" + pt2.x, // corner 2x
bd_pt2_y: "" + pt2.y // Corner point 2y
};
// Save the mxweb file to the server and convert it to pdf.
// printPdfUrl: back-end request interface
MxCpp.getCurrentMxCAD().saveFileToUrl(printPdfUrl, (iResult: number, sserverResult: string) => {
try {
    let ret = JSON.parse(sserverResult);
    if (ret.ret == "ok") {
     // filePath:The URL for downloading the file
    MxTools.downloadFileFromUrl(filePath, ret.file);
    }
    else {
    console.log(sserverResult);
    }
} catch {
    console.log("Mx: sserverResult error");
}
}, undefined, JSON.stringify(param));~

TIP

注意: Attention: Drawings to PDF to call node. Js back-end services, therefore, please call the above method before starting development kit cloud services in the background. If you are not sure how to start the service with Cloud Mapping Kit, please refer to Getting Started with Cloud Mapping Kit

Functional practice

Practical effects are as follows:

  • Click the Export jpg button to perform the Export jpg method
  • Click the left mouse button to select the export range according to the command line prompt
  • Click the left mouse button again to end the box selection
  • Successfully exported the contents of the target range of drawings to jpg format