user123456
user123456

Reputation: 123

How to draw a path on pdf canvas by using itext pdf?

I am implementing pdf editing application by using itextpdf. I added a text into pdf and I am drawing a name on android system canvas by using canvas.drawPath() method.Like that I want to draw a names on pdfCanvas is it possible?.

I tried some of the example for drawing curves and rectangle on pdf canvas but is not giving exact solution.For drawing curves on pdf canvas I am using "PdfContentByte".In this class I found some of the methods

curveFromTo(x1,y1,x3,y3) curveTo(x2,y2,x3,y3) curveTo(x1,y1,x2,y2,x3,y3)

in this methods I am using curveFromTo() after saving it's giving mirror path not original path.

means if I draw PDF on android canvas its rotating like mirror image.

Is it possible to draw a path on PDF file.And is there any method like canvas.drawPAth();

Upvotes: 1

Views: 1382

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

First things first: there is no canvas.drawPath() method in iText.

Now for the rest of your question: there are methods to draw text on a PDF page using low-level functionality and methods to draw text using high-level functionality.

At the lowest level, one would use, a sequence of beginText(), setFontAndSize(), setTextMatrix(), showText() and endText() methods. This is called a "text object".

At a higher level, one could replace setTextMatrix() and showText() with a single showTextAligned() method.

At an even higher level, one could replace the complete sequence with a single ColumnText.showTextAligned() method.

At the highest level, on could create a ColumnText object, define a Rectangle for the column, add objects such as Paragraph, PdfPTable,... to the column and execute the go() method.

However: you are making a major mistake when you say:

after saving it's giving mirror path not original path.

means if I draw PDF on android canvas its rotating like mirror image.

Apart from the bad English, you are ignoring ISO-32000-1. By reading this ISO-standard, you'll discover that you are making wrong assumptions about the coordinate system in PDF. In a newly created PDF, the origin of the coordinate can be found in the lower-left corner. The X access extends to the right. The Y access extends upwards.

Android uses a different coordinate system. You need to make sure you transform coordinates when converting Android coordinates to PDF coordinates.

Upvotes: 1

Related Questions