문제 설명
표 셀에 사각형을 그리는 방법은 무엇입니까? (How to draw rectangles in a Table cell?)
셀이 있는 테이블이 있고 그 안에 가로 막대 차트를 배치하고 싶습니다. 다른 라이브러리를 피하기 위해 이 셀에 직사각형으로 이 차트를 칠하고 싶습니다.
사각형을 그리려면 캔버스가 필요합니까? 캔버스를 셀에 배치하는 방법과 셀의 오른쪽 페이지에 캔버스를 만드는 방법은 무엇입니까?
감사합니다!
참조 솔루션
방법 1:
iText7 has two kinds of canvas objects:
A layout Canvas
, a high‑level object that acts as a bridge between high‑and low‑level operations that allows you to add high‑level objects to a specified area. This canvas has no concept of a page.
A PdfCanvas
that allows you to do low‑level operations on either a specific page or form XObject
, such as drawing lines, adding text at absolute positions, ...
The constructors of Canvas
require either a form XObject
or a PdfCanvas
, so a page can be specified for Canvas
this way.
Now, in order to draw rectangles into cells, I recommend implementing your own cell‑event, and using PdfCanvas to draw the rectangles inside the event handling code.
Some useful links: Tutorial part on event handlers (final example is the one you want): http://developers.itextpdf.com/content/itext‑7‑jump‑start‑tutorial/chapter‑3‑using‑renderers‑and‑event‑handlers
Drawing using pdfCanvas: http://developers.itextpdf.com/content/itext‑7‑jump‑start‑tutorial/chapter‑2‑adding‑low‑level‑content
(by Gerrit、Samuel Huylebroeck)