如何绘制网格?只需添加操作即可在开发过程中将其绘制到页面内容中。
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();
}
}
这导致这样的事情:
来源
2015-04-24 22:28:13
mkl
您可以根据PDF小丑样品HelloWorldSample.java在this sample做到像如何绘制它?在开发过程中,只需添加用于将网格绘制到页面内容的操作。 – mkl