Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Cells provides an abstract class DrawObjectEventHandler which has a DrawObjectEventHandler.draw(DrawObject, number, number, number, number) method. The user can implement DrawObjectEventHandler and utilize the DrawObjectEventHandler.draw(DrawObject, number, number, number, number) method to get the DrawObject and bound while rendering Excel to PDF or image. Here is a brief description of the parameters of the DrawObjectEventHandler.draw(DrawObject, number, number, number, number) method.
If you are rendering an Excel file to PDF, you can utilize the DrawObjectEventHandler class with PdfSaveOptions.getDrawObjectEventHandler(). Similarly, if you are rendering an Excel file to an image, you can utilize the DrawObjectEventHandler class with ImageOrPrintOptions.getDrawObjectEventHandler().
Please see the following sample code. It loads the sample Excel file and saves it as output PDF. While rendering to PDF, it utilizes the PdfSaveOptions.getDrawObjectEventHandler() property and captures the DrawObject and bound of existing cells and objects, e.g., images, etc. If the DrawObject type is Cell, it prints its bound and string value. If the DrawObject type is Image, it prints its bound and shape name. Please see the console output of the sample code given below for more help.
const AsposeCells = require("aspose.cells.node");
class ClsDrawObjectEventHandler extends AsposeCells.DrawObjectEventHandler {
draw(drawObject, x, y, width, height) {
console.log("");
// Print the coordinates and the value of a Cell object
if (drawObject.getType() === AsposeCells.DrawObjectEnum.Cell) {
console.log(`[X]: ${x} [Y]: ${y} [Width]: ${width} [Height]: ${height} [Cell Value]: ${drawObject.getCell().getStringValue()}`);
}
// Print the coordinates and the shape name of an Image object
if (drawObject.getType() === AsposeCells.DrawObjectEnum.Image) {
console.log(`[X]: ${x} [Y]: ${y} [Width]: ${width} [Height]: ${height} [Shape Name]: ${drawObject.getShape().getName()}`);
}
console.log("----------------------");
}
}
async function run() {
// Load sample Excel file
const workbook = new AsposeCells.Workbook("sampleGetDrawObjectAndBoundUsingDrawObjectEventHandler.xlsx");
// Specify PDF save options
const opts = new AsposeCells.PdfSaveOptions();
// Assign the instance of DrawObjectEventHandler class
opts.setDrawObjectEventHandler(new ClsDrawObjectEventHandler());
// Save to PDF format with the specified options
await workbook.saveAsync("outputGetDrawObjectAndBoundUsingDrawObjectEventHandler.pdf", opts);
}
run();
[X]: 153.6035 [Y]: 82.94118 [Width]: 103.2035 [Height]: 14.47059 [Cell Value]: This is sample text.
----------------------
[X]: 267.6917 [Y]: 153.4853 [Width]: 160.4491 [Height]: 128.0647 [Shape Name]: Sun
----------------------Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.