2015-04-24 62 views
0

在进行PDF编程时,在屏幕上添加许多可见材质(如文字,多边形绘图,图片,颜色,边框等)。是否有显示网格的选项,用于在屏幕上编程可见材料的位置?

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

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

谢谢。

P.S. - 此外,我们不必打印出纸张并将塑料网格放在其上进行测量。保存文件并转为绿色。 ;-)

+0

您可以根据PDF小丑样品HelloWorldSample.javathis sample做到像如何绘制它?在开发过程中,只需添加用于将网格绘制到页面内容的操作。 – mkl

回答

1

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

E.g.

// 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(); 
    } 
} 

这导致这样的事情:

Sample result

相关问题