Layout for PdfDocument
up vote
0
down vote
favorite
I have done some looking around and have gotten a decent understanding of how to generate a Pdf with the native android tools. I'm still a bit confused on how the xml/view should be structured. Because for me, it never gets loaded. I'll start with the xml. which is shown below
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/dh_pdf_viewer_root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.duethealth.lib.pdfviewer.ui.PdfDocumentView
android:id="@+id/dh_pdf_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/dh_pdf_page_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="@dimen/dh_padding_default"
android:background="@color/dh_color_background_75"
android:gravity="center"
android:padding="@dimen/dh_padding_default"
android:textAppearance="@style/DuetHealth.TextAppearance.ListLine2"/>
<include layout="@layout/dh_include_loading_50"/>
So the TextView at the bottom is used to display my page counter(if its needed), I dont need to extend ViewPager, its just a place holder.
public class PdfDocumentView extends ViewPager {
public void writePdf(File file)
PdfDocument document = new PdfDocument();
PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create();
Page page = document.startPage(pageInfo);
View content = findViewById(R.id.dh_pdf_view);
content.measure(800, 480);
content.layout(0, 0, 800, 480);
content.draw(page.getCanvas());
document.finishPage(page);
try
FileOutputStream fileOutputStream = new FileOutputStream(file.getPath());
document.writeTo(fileOutputStream);
document.close();
fileOutputStream.close();
catch (IOException e)
Timber.e(e, "Error writing PDF");
I dont understand what ViewGroup I should be extending for PdfDocumentView
or can the whole document just go into an ImageView or something? When I go through the DEBUG, everything seems to be working, the PDF is being successfully pulled from URL into byte stream then written out to a file and then to memory and there are no errors. Seems my problem is somewhere with the View itself.
java android pdf pdf-generation android-view
add a comment |
up vote
0
down vote
favorite
I have done some looking around and have gotten a decent understanding of how to generate a Pdf with the native android tools. I'm still a bit confused on how the xml/view should be structured. Because for me, it never gets loaded. I'll start with the xml. which is shown below
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/dh_pdf_viewer_root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.duethealth.lib.pdfviewer.ui.PdfDocumentView
android:id="@+id/dh_pdf_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/dh_pdf_page_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="@dimen/dh_padding_default"
android:background="@color/dh_color_background_75"
android:gravity="center"
android:padding="@dimen/dh_padding_default"
android:textAppearance="@style/DuetHealth.TextAppearance.ListLine2"/>
<include layout="@layout/dh_include_loading_50"/>
So the TextView at the bottom is used to display my page counter(if its needed), I dont need to extend ViewPager, its just a place holder.
public class PdfDocumentView extends ViewPager {
public void writePdf(File file)
PdfDocument document = new PdfDocument();
PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create();
Page page = document.startPage(pageInfo);
View content = findViewById(R.id.dh_pdf_view);
content.measure(800, 480);
content.layout(0, 0, 800, 480);
content.draw(page.getCanvas());
document.finishPage(page);
try
FileOutputStream fileOutputStream = new FileOutputStream(file.getPath());
document.writeTo(fileOutputStream);
document.close();
fileOutputStream.close();
catch (IOException e)
Timber.e(e, "Error writing PDF");
I dont understand what ViewGroup I should be extending for PdfDocumentView
or can the whole document just go into an ImageView or something? When I go through the DEBUG, everything seems to be working, the PDF is being successfully pulled from URL into byte stream then written out to a file and then to memory and there are no errors. Seems my problem is somewhere with the View itself.
java android pdf pdf-generation android-view
"I dont understand what ViewGroup I should be extending for PdfDocument" --PdfDocument
is not aView
. It is something that creates PDFs for printing. That PDF is not going to be displayed, unless you do something to display it. I do not know whatcom.duethealth.lib.pdfviewer.ui.PdfDocumentView
is, but if that is a widget that is supposed to view PDF files, you would need to do something to teach it about your PDF.
– CommonsWare
Nov 11 at 0:38
@CommonsWare, I have edit the question. My class isPdfDocumentView
it needs to extend a viewgroup in order to display my PDF. I understandPdfDocument
is not a view but a tool for creating PDF's. I have a PDF created but it is not appearing in my view, which is the 1st chunk of code in the original question.
– Kyle
Nov 11 at 0:49
Android does not have a widget that views PDFs. If you are trying to write one, that will take a very long time. You might want to consider some existing options for viewing PDFs or simply display the PDF in a third-party PDF viewer app.
– CommonsWare
Nov 11 at 0:51
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have done some looking around and have gotten a decent understanding of how to generate a Pdf with the native android tools. I'm still a bit confused on how the xml/view should be structured. Because for me, it never gets loaded. I'll start with the xml. which is shown below
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/dh_pdf_viewer_root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.duethealth.lib.pdfviewer.ui.PdfDocumentView
android:id="@+id/dh_pdf_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/dh_pdf_page_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="@dimen/dh_padding_default"
android:background="@color/dh_color_background_75"
android:gravity="center"
android:padding="@dimen/dh_padding_default"
android:textAppearance="@style/DuetHealth.TextAppearance.ListLine2"/>
<include layout="@layout/dh_include_loading_50"/>
So the TextView at the bottom is used to display my page counter(if its needed), I dont need to extend ViewPager, its just a place holder.
public class PdfDocumentView extends ViewPager {
public void writePdf(File file)
PdfDocument document = new PdfDocument();
PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create();
Page page = document.startPage(pageInfo);
View content = findViewById(R.id.dh_pdf_view);
content.measure(800, 480);
content.layout(0, 0, 800, 480);
content.draw(page.getCanvas());
document.finishPage(page);
try
FileOutputStream fileOutputStream = new FileOutputStream(file.getPath());
document.writeTo(fileOutputStream);
document.close();
fileOutputStream.close();
catch (IOException e)
Timber.e(e, "Error writing PDF");
I dont understand what ViewGroup I should be extending for PdfDocumentView
or can the whole document just go into an ImageView or something? When I go through the DEBUG, everything seems to be working, the PDF is being successfully pulled from URL into byte stream then written out to a file and then to memory and there are no errors. Seems my problem is somewhere with the View itself.
java android pdf pdf-generation android-view
I have done some looking around and have gotten a decent understanding of how to generate a Pdf with the native android tools. I'm still a bit confused on how the xml/view should be structured. Because for me, it never gets loaded. I'll start with the xml. which is shown below
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/dh_pdf_viewer_root"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.duethealth.lib.pdfviewer.ui.PdfDocumentView
android:id="@+id/dh_pdf_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/dh_pdf_page_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="@dimen/dh_padding_default"
android:background="@color/dh_color_background_75"
android:gravity="center"
android:padding="@dimen/dh_padding_default"
android:textAppearance="@style/DuetHealth.TextAppearance.ListLine2"/>
<include layout="@layout/dh_include_loading_50"/>
So the TextView at the bottom is used to display my page counter(if its needed), I dont need to extend ViewPager, its just a place holder.
public class PdfDocumentView extends ViewPager {
public void writePdf(File file)
PdfDocument document = new PdfDocument();
PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create();
Page page = document.startPage(pageInfo);
View content = findViewById(R.id.dh_pdf_view);
content.measure(800, 480);
content.layout(0, 0, 800, 480);
content.draw(page.getCanvas());
document.finishPage(page);
try
FileOutputStream fileOutputStream = new FileOutputStream(file.getPath());
document.writeTo(fileOutputStream);
document.close();
fileOutputStream.close();
catch (IOException e)
Timber.e(e, "Error writing PDF");
I dont understand what ViewGroup I should be extending for PdfDocumentView
or can the whole document just go into an ImageView or something? When I go through the DEBUG, everything seems to be working, the PDF is being successfully pulled from URL into byte stream then written out to a file and then to memory and there are no errors. Seems my problem is somewhere with the View itself.
java android pdf pdf-generation android-view
java android pdf pdf-generation android-view
edited Nov 11 at 0:48
asked Nov 11 at 0:21
Kyle
16713
16713
"I dont understand what ViewGroup I should be extending for PdfDocument" --PdfDocument
is not aView
. It is something that creates PDFs for printing. That PDF is not going to be displayed, unless you do something to display it. I do not know whatcom.duethealth.lib.pdfviewer.ui.PdfDocumentView
is, but if that is a widget that is supposed to view PDF files, you would need to do something to teach it about your PDF.
– CommonsWare
Nov 11 at 0:38
@CommonsWare, I have edit the question. My class isPdfDocumentView
it needs to extend a viewgroup in order to display my PDF. I understandPdfDocument
is not a view but a tool for creating PDF's. I have a PDF created but it is not appearing in my view, which is the 1st chunk of code in the original question.
– Kyle
Nov 11 at 0:49
Android does not have a widget that views PDFs. If you are trying to write one, that will take a very long time. You might want to consider some existing options for viewing PDFs or simply display the PDF in a third-party PDF viewer app.
– CommonsWare
Nov 11 at 0:51
add a comment |
"I dont understand what ViewGroup I should be extending for PdfDocument" --PdfDocument
is not aView
. It is something that creates PDFs for printing. That PDF is not going to be displayed, unless you do something to display it. I do not know whatcom.duethealth.lib.pdfviewer.ui.PdfDocumentView
is, but if that is a widget that is supposed to view PDF files, you would need to do something to teach it about your PDF.
– CommonsWare
Nov 11 at 0:38
@CommonsWare, I have edit the question. My class isPdfDocumentView
it needs to extend a viewgroup in order to display my PDF. I understandPdfDocument
is not a view but a tool for creating PDF's. I have a PDF created but it is not appearing in my view, which is the 1st chunk of code in the original question.
– Kyle
Nov 11 at 0:49
Android does not have a widget that views PDFs. If you are trying to write one, that will take a very long time. You might want to consider some existing options for viewing PDFs or simply display the PDF in a third-party PDF viewer app.
– CommonsWare
Nov 11 at 0:51
"I dont understand what ViewGroup I should be extending for PdfDocument" --
PdfDocument
is not a View
. It is something that creates PDFs for printing. That PDF is not going to be displayed, unless you do something to display it. I do not know what com.duethealth.lib.pdfviewer.ui.PdfDocumentView
is, but if that is a widget that is supposed to view PDF files, you would need to do something to teach it about your PDF.– CommonsWare
Nov 11 at 0:38
"I dont understand what ViewGroup I should be extending for PdfDocument" --
PdfDocument
is not a View
. It is something that creates PDFs for printing. That PDF is not going to be displayed, unless you do something to display it. I do not know what com.duethealth.lib.pdfviewer.ui.PdfDocumentView
is, but if that is a widget that is supposed to view PDF files, you would need to do something to teach it about your PDF.– CommonsWare
Nov 11 at 0:38
@CommonsWare, I have edit the question. My class is
PdfDocumentView
it needs to extend a viewgroup in order to display my PDF. I understand PdfDocument
is not a view but a tool for creating PDF's. I have a PDF created but it is not appearing in my view, which is the 1st chunk of code in the original question.– Kyle
Nov 11 at 0:49
@CommonsWare, I have edit the question. My class is
PdfDocumentView
it needs to extend a viewgroup in order to display my PDF. I understand PdfDocument
is not a view but a tool for creating PDF's. I have a PDF created but it is not appearing in my view, which is the 1st chunk of code in the original question.– Kyle
Nov 11 at 0:49
Android does not have a widget that views PDFs. If you are trying to write one, that will take a very long time. You might want to consider some existing options for viewing PDFs or simply display the PDF in a third-party PDF viewer app.
– CommonsWare
Nov 11 at 0:51
Android does not have a widget that views PDFs. If you are trying to write one, that will take a very long time. You might want to consider some existing options for viewing PDFs or simply display the PDF in a third-party PDF viewer app.
– CommonsWare
Nov 11 at 0:51
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244721%2flayout-for-pdfdocument%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"I dont understand what ViewGroup I should be extending for PdfDocument" --
PdfDocument
is not aView
. It is something that creates PDFs for printing. That PDF is not going to be displayed, unless you do something to display it. I do not know whatcom.duethealth.lib.pdfviewer.ui.PdfDocumentView
is, but if that is a widget that is supposed to view PDF files, you would need to do something to teach it about your PDF.– CommonsWare
Nov 11 at 0:38
@CommonsWare, I have edit the question. My class is
PdfDocumentView
it needs to extend a viewgroup in order to display my PDF. I understandPdfDocument
is not a view but a tool for creating PDF's. I have a PDF created but it is not appearing in my view, which is the 1st chunk of code in the original question.– Kyle
Nov 11 at 0:49
Android does not have a widget that views PDFs. If you are trying to write one, that will take a very long time. You might want to consider some existing options for viewing PDFs or simply display the PDF in a third-party PDF viewer app.
– CommonsWare
Nov 11 at 0:51