Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

How to render(View) pdf file 6 years 3 months ago #7372

  • asliyanage
  • asliyanage's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 100
  • Thank you received: 0
Can you provide simple example?Demo project contains the large number of files?I need to view pdf file in my app?

Please Log in or Create an account to join the conversation.

How to render(View) pdf file 6 years 3 months ago #7373

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Karma: 18
  • Thank you received: 65
Hi,
please check in the demo project the PDFReader and PDFReaderAct class.
This will help you!

Please Log in or Create an account to join the conversation.

Last edit: by poudel.

How to render(View) pdf file 6 years 3 months ago #7378

  • asliyanage
  • asliyanage's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 100
  • Thank you received: 0
can you provide a simple code to load pdf file from a given path ?

Please Log in or Create an account to join the conversation.

How to render(View) pdf file 6 years 3 months ago #7380

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Karma: 18
  • Thank you received: 65
Hi,

try to add this in the InitView() void in PDFReaderAct class..

m_doc = new Document();
m_doc.Open( your_pdf_path, your_pdf_password );
m_reader.PDFOpen(m_doc, false, this);

Please Log in or Create an account to join the conversation.

How to render(View) pdf file 6 years 2 months ago #7586

  • asliyanage
  • asliyanage's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 100
  • Thank you received: 0
How to call this in a fragment as last argument is PDFReader.PDFReaderListener ?.In a activity we can implement this listener.I need to view pdf five in a viewpager which has several fragments.


Below is my fragments code.

package com.sph.pdf;

import java.io.File;
import java.io.InputStream;

import com.radaee.pdf.Document;
import com.radaee.pdf.Global;
import com.radaee.pdf.Page.Annotation;
import com.radaee.reader.PDFReader;
import com.radaee.reader.PDFReader.PDFReaderListener;
import com.radaee.util.PDFThumbView;
import com.radaee.view.PDFVPage;

import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MyFragment extends Fragment implements PDFReaderListener {
	public static final String EXTRA_MESSAGE = "EXTRA_MESSAGE";
	public static int count = 1;

	static String file;
	TextView txt;

	private PDFThumbView m_thumb = null;
	private Document m_doc = new Document();
	private RelativeLayout m_layout;
	private PDFReader m_reader = null;
	private RelativeLayout mContentView;

	public static final MyFragment newInstance(String message) {
		MyFragment f = new MyFragment();
		Bundle bdl = new Bundle(1);
		bdl.putString(EXTRA_MESSAGE, message);
		f.setArguments(bdl);
		file = message;
		return f;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		mContentView = new RelativeLayout(getActivity());
		mContentView.setLayoutParams(new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

		openDoc("/mnt/sdcard/pdf/1.pdf");
		
		return mContentView;
	}

	public void openDoc(String path) {

		try {
			File sdCard = Environment.getExternalStorageDirectory();
			File imageFolder = new File(sdCard.getAbsolutePath());
			String rootPaperFolder = imageFolder.toString();

			// View v = inflater.inflate(R.layout.pdf_fragment, container,
			// false);

			Global.Init(getActivity());

			m_layout = (RelativeLayout) LayoutInflater.from(getActivity()).inflate(R.layout.reader, null);
			m_reader = (PDFReader) m_layout.findViewById(R.id.view);

			
			
			Log.e("m_reader.PDFOpen", ""+m_reader);			m_doc.Close();
			
			int ret = m_doc.Open(path, null);
			if (ret == 0) {
				// m_doc.SetCache( Global.tmp_path + "/temp.dat" );
				m_reader.PDFOpen(m_doc, false, this);
				

			}

			

		} catch (Exception e) {
			e.printStackTrace();
			Log.e("m_reader.PDFOpen", ""+m_reader);
		}

	}

	@Override
	public void onDestroyView() {

		super.onDestroyView();
		// Log.d("PDFVIEW", "onDestroyView");

		try {

			if (m_thumb != null) {
				m_thumb.thumbClose();
				m_thumb = null;
			}
			if (m_reader != null)
				m_reader.PDFClose();
			if (m_doc != null)
				m_doc.Close();
			Global.RemoveTmp();
			super.onDestroy();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public void OnPageModified(int pageno) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnPageChanged(int pageno) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnAnnotClicked(PDFVPage vpage, Annotation annot) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnSelectEnd(String text) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnOpenURI(String uri) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnOpenJS(String js) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnOpenMovie(String path) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnOpenSound(int[] paras, String path) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnOpenAttachment(String path) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnOpen3D(String path) {
		// TODO Auto-generated method stub

	}

}
it gives me 10 for ret value.But if i put the same code in activity it gives me 0 for ret varible.

int ret = m_doc.Open(path, null);

Please Log in or Create an account to join the conversation.

Last edit: by Docrishav.

How to render(View) pdf file 6 years 2 months ago #7695

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Karma: 18
  • Thank you received: 65
Hi,
ret = 10 means access denied or invalid file path.
Please check the path.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum