-1

from my research Itext is the easiest way but it is not completely for free. Another option seek to convert to image which might affect quality. so please any suggestion how to convert a whole xml layout content to word or pdf file?

i want make something like this make something like this

  • Does this answer your question? [Android How to turn a XML layout into a PDF?](https://stackoverflow.com/questions/16479337/android-how-to-turn-a-xml-layout-into-a-pdf) – R7G Jul 15 '22 at 10:05

1 Answers1

1

You can use the built in PdfDocument class, this provides a Canvas to draw in to either directly or in your case you can get your layout to draw itself to this canvas.

Some things to think about, there are three option on sizing, you can either create a PDF page the size of your display screen, allow the layout to use all the space it needs or match your layout to standard paper sizes (probably better if you want the PDF printed)

You also have to think about scrollable content, depending on the sizing option you chose it will determine how much of the content you will get in the PDF, for standard page sizes it can get complicated as you probably want to create multiple pages so you will have to work out how to split content across pages.

This answer has an rough example of the points and how to draw a layout to PDF https://stackoverflow.com/a/72702185/2373819

The key point from XML is Inflate Layout -> Set layout parameters -> Measure -> Layout -> Draw to PDF canvas

Andrew
  • 8,198
  • 2
  • 15
  • 35