How to draw path on pdf canvas using itext pdf?


User 123456

I am implementing a pdf editing application using itextpdf. I added a text to the pdf and used the canvas.drawPath() method to draw a name on the android system canvas like I want to draw a name on the pdfCanvas?

I tried some examples of drawing curves and rectangles on pdf canvas, but no exact solution was given. For the example of drawing the curve on the pdf canvas, I am using "PdfContentByte". In this class I found some methods

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

In this method, after saving, I use curveFromTo() to give the mirrored path instead of the original.

Means that if I draw the PDF on the android canvas, it rotates like a mirror image.

Is it possible to draw paths on PDF files. Is there a method like canvas.drawPAth();?

Bruno Lowagie

First things first: there are no methods canvas.drawPath()in iText .

Now the remaining question is: there are methods to draw text on PDF pages using low-level functions and methods to draw text on top of text using high-level functions.

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

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

At a higher level, one ColumnText.showTextAligned()method can replace the entire sequence .

At the highest level you can create an ColumnTextobject, define Rectangleit as a column, add objects like Paragraph, PdfPTable... to the column and execute go()methods.

But: you make a big mistake when you say the following:

After saving it gave the mirror path instead of the original.

Means that if I draw the PDF on the android canvas, it rotates like a mirror image.

Besides bad English, you are ignoring ISO-32000-1. By reading this ISO standard, you'll see that you're making wrong assumptions about the PDF's coordinate system. In the newly created PDF, the origin of the coordinates can be found in the lower left corner. X access rights extend to the right. The Y channel extends upwards.

Android uses a different coordinate system. When converting Android coordinates to PDF coordinates, you need to make sure to convert the coordinates.

Related


How to draw path on pdf canvas using itext pdf?

User 123456 I am implementing a pdf editing application using itextpdf. I added a text to the pdf and used the canvas.drawPath() method to draw a name on the android system canvas, just like I want to draw a name on the pdfCanvas? I tried some examples of draw

How to draw graphics to PDF using iText?

jimdrang : I'm trying to complete an example that draws a graph and writes it to a PDF, but I keep getting the error that the PDF has no pages. If I add something simple with document.add() after opening it works fine, I never see the graph. Here is my code: D

How to draw graphics to PDF using iText?

jimdrang : I'm trying to complete an example that draws a graph and writes it to a PDF, but I keep getting the error that the PDF has no pages. If I add something simple with document.add() after opening it works fine, I never see the graph. Here is my code: D

How to draw graphics to PDF using iText?

jimdrang : I'm trying to complete an example that draws a graph and writes it to a PDF, but I keep getting the error that the PDF has no pages. If I add something simple with document.add() after opening it works fine, I never see the graph. Here is my code: D

Draw a rectangle in a PDF document using iText

Milhous: Is it possible to draw rectangles in PDF documents in iText? Milhous: Here is the solution. Thanks Dylan McClung. PdfWriter writer = ...; PdfContentByte cb = writer.getDirectContent(); cb.saveState(); cb.setColorStroke(Color.black); cb.rectangle(x,y,x

Draw a rectangle in a PDF document using iText

Milhous: Is it possible to draw rectangles in PDF documents in iText? Milhous: Here is the solution. Thanks Dylan McClung. PdfWriter writer = ...; PdfContentByte cb = writer.getDirectContent(); cb.saveState(); cb.setColorStroke(Color.black); cb.rectangle(x,y,x

Draw a rectangle in a PDF document using iText

Milhous: Is it possible to draw rectangles in PDF documents in iText? Milhous: Here is the solution. Thanks Dylan McClung. PdfWriter writer = ...; PdfContentByte cb = writer.getDirectContent(); cb.saveState(); cb.setColorStroke(Color.black); cb.rectangle(x,y,x

itext pdf, how to draw a string to a specific position?

Rogers I am trying to output some strings to PDF using Itext. Currently, I can print them to the document, but I want to draw/write them to a specific (x,y) in the document. How will I deal with it? Or are there any tutorials or resources that can help you? An

Draw rectangle with loaded pdf file in canvas using pdf.js

Sharma Vikram I am trying to draw rectangles on a pdf file. When I draw rectangles in pdf, the rectangles are not drawn correctly. I want to draw only one rectangle at a time, when I draw the new one, the old one should be deleted, but this is not happening. H

Draw rectangle with loaded pdf file in canvas using pdf.js

Sharma Vikram I am trying to draw rectangles on a pdf file. When I draw rectangles in pdf, the rectangles are not drawn correctly. I want to draw only one rectangle at a time, when I draw the new one, the old one should be deleted, but this is not happening. H

Draw rectangle with loaded pdf file in canvas using pdf.js

Sharma Vikram I am trying to draw rectangles on a pdf file. When I draw rectangles in pdf, the rectangles are not drawn correctly. I want to draw only one rectangle at a time, when I draw the new one, the old one should be deleted, but this is not happening. H

Draw rectangle with loaded pdf file in canvas using pdf.js

Sharma Vikram I am trying to draw rectangles on a pdf file. When I draw rectangles in pdf, the rectangles are not drawn correctly. I want to draw only one rectangle at a time, when I draw the new one, the old one should be deleted, but this is not happening. H

Draw rectangle with loaded pdf file in canvas using pdf.js

Sharma Vikram I am trying to draw rectangles on a pdf file. When I draw rectangles in pdf, the rectangles are not drawn correctly. I want to draw only one rectangle at a time, when I draw the new one, the old one should be deleted, but this is not happening. H

itext7 - How to draw horizontal dashed lines in PDF?

suushiemaniac: I am using the community version of itext7 (version 7.1.9) . I want to create a PDF document in which I insert paragraphs of text and horizontal separators like this: some interesting text ----------- more interesting text ----------- still inte

itext7 - How to draw horizontal dashed lines in PDF?

suushiemaniac: I am using the community version of itext7 (version 7.1.9) . I want to create a PDF document in which I insert paragraphs of text and horizontal separators like this: some interesting text ----------- more interesting text ----------- still inte

itext7 - How to draw horizontal dashed lines in PDF?

suushiemaniac: I am using the community version of itext7 (version 7.1.9) . I want to create a PDF document in which I insert paragraphs of text and horizontal separators like this: some interesting text ----------- more interesting text ----------- still inte

itext7 - How to draw horizontal dashed lines in PDF?

suushiemaniac: I am using the community version of itext7 (version 7.1.9) . I want to create a PDF document in which I insert paragraphs of text and horizontal separators like this: some interesting text ----------- more interesting text ----------- still inte

itext7 - How to draw horizontal dashed lines in PDF?

suushiemaniac: I am using the community version of itext7 (version 7.1.9) . I want to create a PDF document in which I insert paragraphs of text and horizontal separators like this: some interesting text ----------- more interesting text ----------- still inte

itext7 - How to draw horizontal dashed lines in PDF?

suushiemaniac: I am using the community version of itext7 (version 7.1.9) . I want to create a PDF document in which I insert paragraphs of text and horizontal separators like this: some interesting text ----------- more interesting text ----------- still inte

HTML to PDF using iText: how to generate a checkbox

RealHowTo: I have a simple HTML page from which iText can generate a PDF. Great, but the checkbox is ignored. what should I do? import java.io.FileOutputStream; import java.io.StringReader; import com.itextpdf.text.Document; import com.itextpdf.text.PageSize;

How to know if a document claims to be PDF/A using itext

alexyz78: I would at least check if the documentation claims it is PDF/A compliant. How to do this with iText? Tag memory: what. The PDF/A spec contains the answer (which won't do well unless someone pays to get it). You can dig the same information from iText

How to write content to pdf using iText?

Memory leak: Now, I use iText to automatically generate pdf. My problem is that when the content is very large, I need to calculate the height and width of the content and then add a new page... which is really inconvenient. So I wonder if there is such a meth

How to rotate watermark (text) in PDF using iText?

Allegiance: I'm using iText to watermark a PDF file (text: "SuperEasy You Done") as described in How to watermark a PDF with text or image ? ( TransparentWatermark2.java ). Check out the project source code on GitHub . Right now, an example of the PDF I get is

How to put ByteArrayInputStream content into PDF using iText?

Andre Nobili I have the following situation and I have a method: ByteArrayInputStream fis = new ByteArrayInputStream(Bean.getValoreString("PDFmulti", "PDF").getBytes()); As you can see FIS varialbe is ByteArrayInputStream and Bean.getValoreString("PDFmulti",

How to know if a document claims to be PDF/A using itext

alexyz78: I would at least check if the documentation claims it is PDF/A compliant. How to do this with iText? Tag memory: what. The PDF/A spec contains the answer (which won't do well unless someone pays to get it). You can dig the same information from iText

How to write content to pdf using iText?

Memory leak: Now, I use iText to automatically generate pdf. My problem is that when the content is very large, I need to calculate the height and width of the content and then add a new page... which is really inconvenient. So I wonder if there is such a meth

How to write PDF to HttpResponseMessage using iText 7

joy 8 I am trying to use iText 7 and iText7.pdfHtml library to generate PDF and write it to HTTP response. The HTML content of the PDF is stored in an StringBuilderobject. Not sure what the correct procedure is to do this, because once used HtmlConverter.Conve

HTML to PDF using iText: how to generate a checkbox

RealHowTo: I have a simple HTML page from which iText can generate a PDF. Great, but the checkbox is ignored. what should I do? import java.io.FileOutputStream; import java.io.StringReader; import com.itextpdf.text.Document; import com.itextpdf.text.PageSize;

How to rotate watermark (text) in PDF using iText?

Allegiance: I'm using iText to watermark a PDF file (text: "SuperEasy You Done") as described in How to watermark a PDF with text or image ? ( TransparentWatermark2.java ). Check out the project source code on GitHub . Right now, an example of the PDF I get is