0

在做PDF编程的时候,同时在屏幕上添加了很多可见的素材(比如文字、多边形绘制、图片、颜色、边框等)。

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

我发现测量对象的位置和宽度/高度比花时间计算点和犯错误更容易。

谢谢。

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

4

1 回答 1

1

How about drawing a grid? Simply add operations for drawing it to the page content during development.

E.g. you can do it like in 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();

using the helper method 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();
    }
}

This results in something like this:

Sample result

于 2015-04-24T22:28:13.617 回答