Iam trying to inflate a layout into a pdf with PdfDocument. In the design view everything looks ok, but when the pdf is created, spaces arent preserved. As you can see in pictures i want the spaces exactly like the first one.Any ideas?
Iam trying to inflate a layout into a pdf with PdfDocument. In the design view everything looks ok, but when the pdf is created, spaces arent preserved. As you can see in pictures i want the spaces exactly like the first one.Any ideas?
// create a new document
PdfDocument document = new PdfDocument();
// crate a page description
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(800, 1124, 1).create();
// start a page
PdfDocument.Page page = document.startPage(pageInfo);
// draw something on the page
View content = MainActivity.this.getLayoutInflater().inflate(R.layout.pdf_page, null);
content.measure(800, 1124);
content.layout(0, 0, 800, 1124);
content.draw(page.getCanvas());
// finish the page
document.finishPage(page);
document.writeTo(fos);
Pdf.layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pdf">
<TableRow
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="FullName"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/checkIn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/checkOut"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</TableRow>
</android.support.constraint.ConstraintLayout>
I want this
but i get this
You can try taking
TableLayout
rather thanCoordinatorLayout
Study
android:stretchColumns="1"
attribute ofTableLayout
. Wish your problem will be solved. Have a look on following code: