是否有显示网格的选项,用于编程屏幕上可见 material 的位置?

Is there an option to display grid, for programming positions of visible material on screen?

在做PDF编程时,同时在屏幕上添加很多可见的material(例如文本、多边形绘图、图片、颜色、边框等)。

有没有办法打开或显示网格(可以是点)来测量x和y轴定位?如果是这样,我应该在 PDFClown 中寻找什么对象?

我发现测量物体的位置和 width/height 比花时间计算点和犯错误更容易。

谢谢。

P.S。 - 此外,我们不必打印出纸张并将塑料网格放在上面进行测量。节省纸张并走向绿色。 ;-)

绘制网格如何?只需在开发时在页面内容中添加绘制操作即可。

例如你可以像 this sample based on the PDF Clown sample HelloWorldSample.java:

那样做
// 1. Instantiate a new PDF file!
/*
 * NOTE: a File object is the low-level (syntactic) representation of a
 * PDF file.
 */
org.pdfclown.files.File file = new org.pdfclown.files.File();

// 2. Get its corresponding document!
/*
 * NOTE: a Document object is the high-level (semantic) representation
 * of a PDF file.
 */
Document document = file.getDocument();

// 3. Insert the contents into the document!
populate(document);

// 3.5 Add a grid to the content
addGrid(document);

// 4. Serialize the PDF file!
file.save(new File(RESULT_FOLDER, "helloWorld-grid.pdf"), SerializationModeEnum.Standard);

file.close();

使用辅助方法addGrid:

void addGrid(Document document)
{
    for (Page page: document.getPages())
    {
        Dimension2D pageSize = page.getSize();
        PrimitiveComposer composer = new PrimitiveComposer(page);
        composer.beginLocalState();

        composer.setStrokeColor(new DeviceRGBColor(1, 0, 0));
        for (int x = 0; x < pageSize.getWidth(); x+=20)
        {
            composer.startPath(new Point2D.Float(x, 0));
            composer.drawLine(new Point2D.Double(x, pageSize.getHeight()));
        }

        for (int y = 0; y < pageSize.getHeight(); y+=20)
        {
            composer.startPath(new Point2D.Float(0, y));
            composer.drawLine(new Point2D.Double(pageSize.getWidth(), y));
        }

        composer.stroke();

        composer.end();
        composer.flush();
    }
}

结果如下: