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.










share|improve this question























  • "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










  • 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














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.










share|improve this question























  • "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










  • 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












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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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










  • 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










  • @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















"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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto