Add RelativeLayout to PDF page

In this document
chevron_rightXML attributes

CustomRelativeLayout is a RelativeLayout that can be nested under PDFViewCtrl layout with a given page position and page number. All child views of CustomRelativeLayout are displayed on top of PDFViewCtrl. When PDFViewCtrl is scrolling or zooming, CustomRelativeLayout will adjust position and size automatically according to app:zoomWithParent attribute.

The position of CustomRelativeLayout is calculated in PDF page coordinates. In page coordinate, the origin location (0, 0) is at the bottom left corner of the PDF page. The x axis extends horizontally to the right and y axis extends vertically upward. For more information, see: understanding coordinates

Show CustomRelativeLayout

You can add CustomRelativeLayout under PDFViewCtrl in xml layout resource:

<com.pdftron.pdf.PDFViewCtrl
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/pdfviewctrl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical|horizontal" >
    <com.pdftron.pdf.tools.CustomRelativeLayout
        android:layout_width="50dp"
        android:layout_height="50dp"
        app:posX="50"
        app:posY="150"
        app:pageNum="3"
        app:zoomWithParent="true">
        <!--Child views under CustomRelativeLayout-->
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Custom Layout Text View"
            android:textSize="24dp"
            android:elevation="2dp"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/light_gray" />
    </com.pdftron.pdf.tools.CustomRelativeLayout>
</com.pdftron.pdf.PDFViewCtrl>

Adding Custom layout programmatically

Alternatively, you can also add custom layout programmatically like a RelativeLayout.

R.layout.custom_layout_textview:

<com.pdftron.pdf.tools.CustomRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="50dp"
    android:layout_height="50dp"
    app:posX="50"
    app:posY="150"
    app:pageNum="3"
    app:zoomWithParent="true">
    <!--Child views under CustomRelativeLayout-->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Custom Layout Text View"
        android:textSize="24dp"
        android:elevation="2dp"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/light_gray" />
</com.pdftron.pdf.tools.CustomRelativeLayout>

In your activity or fragment:

public void addCustomLayout(PDFViewCtrl pdfViewCtrl) {
  LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view = inflater.inflate(R.layout.custom_layout_textview, pdfViewCtrl);
}
If you deleted the page where CustomRelativeLayout at, the CustomRelativeLayout won't be removed from PDFViewCtrl. Please take care of the CustomRelativeLayout manually.

XML attributes

CustomRelativeLayout lets child views to be displayed inside PDFViewCtrl. XML properties available for positioning view in PDFViewCtrl includes:

app:posX

Specifies the x coordinates in page point.

Default value: 0

app:posY

Specifies the y coordinates in page point.

Default value: 0

app:pageNum

Specifies the page number of the document.

Default value: 1

app:zoomWithParent

Specifies whether the view will be zoom with parent.

Default value: true

android:layout_width

Specifies the width of the view, it has to be a positive integer in PDF page space.

android:layout_height

Specifies the height of the view, it has to be a positive integer in PDF page space.