Skip to content

Commit

Permalink
Merge pull request #6 from okcredit/feature/htmlToPdf
Browse files Browse the repository at this point in the history
Added Pdf from html
  • Loading branch information
divydwivedi31 committed Apr 24, 2024
2 parents 1db2951 + a6e215e commit f38c0ed
Show file tree
Hide file tree
Showing 45 changed files with 464 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:theme="@style/Theme.PDFBuilderAndroid"
tools:targetApi="31">
<activity
android:name="tech.okcredit.pdfbuilder_android.PreviewActivity"
android:name="tech.okcredit.pdfbuilder_android.MainActivity"
android:exported="true"
android:theme="@style/ActivityTheme">
<intent-filter>
Expand All @@ -22,6 +22,23 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="tech.okcredit.pdfbuilder_android.PreviewActivity"
android:exported="true"
android:theme="@style/ActivityTheme">
</activity>

<activity
android:name="tech.okcredit.pdfbuilder_android.PdfPreviewActivity"
android:exported="true"
android:theme="@style/ActivityTheme">
</activity>

<activity
android:name="tech.okcredit.create_pdf.activity.PDFViewerActivity"
android:exported="true"
android:theme="@style/ActivityTheme">
</activity>
</application>

</manifest>
316 changes: 316 additions & 0 deletions app/src/main/java/tech/okcredit/pdfbuilder_android/MainActivity.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package tech.okcredit.pdfbuilder_android

import android.os.Bundle
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import tech.okcredit.create_pdf.activity.PDFViewerActivity


class PdfPreviewActivity : PDFViewerActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setBottomUIComposeContent {
Text(
text = "Hello World!",
modifier = Modifier
.fillMaxWidth()
.padding(50.dp),
style = androidx.compose.ui.text.TextStyle(
fontSize = 30.sp,
)
)
}

}
}
66 changes: 66 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical">

<LinearLayout
android:id="@+id/layoutGeneratePdf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_normal"
android:layout_marginBottom="@dimen/margin_normal"
android:background="?android:attr/selectableItemBackground"
android:orientation="horizontal">


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="Demo for generating a PDF file from scratch"
android:textStyle="bold"
android:typeface="monospace" />

</LinearLayout>

<LinearLayout
android:id="@+id/layoutGenerateHtmlPdf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_normal"
android:layout_marginBottom="@dimen/margin_normal"
android:background="?android:attr/selectableItemBackground"
android:orientation="horizontal">


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="Create a PDF file from an Html"
android:textStyle="bold"
android:typeface="monospace" />

</LinearLayout>


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center_horizontal"
android:textStyle="bold"
android:typeface="monospace" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center_horizontal"
android:textStyle="bold"
android:typeface="monospace" />

</LinearLayout>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatTextView
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
Expand All @@ -20,10 +23,12 @@ import java.io.File
import java.util.LinkedList
import java.util.Locale

class PDFViewerActivity : AppCompatActivity() {
open class PDFViewerActivity : AppCompatActivity() {
var pdfFile: File? = null
private set

lateinit var composeView: ComposeView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_pdf_viewer)
Expand Down Expand Up @@ -55,6 +60,16 @@ class PDFViewerActivity : AppCompatActivity() {
FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
)
viewPager.setPageTransformer(true, ZoomOutPageTransformer())
composeView = findViewById(R.id.compose_view)
}

fun setBottomUIComposeContent(composable: @Composable () -> Unit) {
composeView.apply {
ViewCompositionStrategy.DisposeOnLifecycleDestroyed(lifecycle = lifecycle)
setContent {
composable.invoke()
}
}
}

private class PDFViewerPagerAdapter(fm: FragmentManager, behavior: Int) :
Expand Down
17 changes: 13 additions & 4 deletions create_pdf/src/main/res/layout/activity_pdf_viewer.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/grey_800"
tools:context=".activity.PDFViewerActivity">

<com.tejpratapsingh.pdfcreator.custom.ViewPagerForPhotoView
<tech.okcredit.create_pdf.custom.ViewPagerForPhotoView
android:id="@+id/viewPagerPdfViewer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/grey_800"/>

</FrameLayout>
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>
4 changes: 2 additions & 2 deletions create_pdf/src/main/res/layout/item_pdf_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
android:layout_height="match_parent"
android:orientation="vertical">

<com.tejpratapsingh.pdfcreator.custom.TouchImageViewFling
<tech.okcredit.create_pdf.custom.TouchImageViewFling
android:id="@+id/imageViewItemPdfViewer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_800"
android:background="@color/colorWhite"
android:contentDescription="@string/pdf_page_as_image" />

<LinearLayout
Expand Down

0 comments on commit f38c0ed

Please sign in to comment.