Pages

Showing posts with label pdf. Show all posts
Showing posts with label pdf. Show all posts

Friday, June 9, 2017

Display PDF in assets folder inside APK

Display PDF in assets folder inside APK


The example "Display PDF using PdfRenderer" show how to display PDF stored in sdcard, this example show how to display PDF stored in assets inside APK.


First, you have to create assets folder and copy your PDF into it.


Then you have to edit aaptOptions in build.gradle (Module: app), not to compass "pdf" file.


aaptOptions {
noCompress "pdf"
}


Layout file, refer to the example "Create PDF using PdfDocument".

MainActivity.java
package com.blogspot.android_er.androidpdf;

import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.pdf.PdfRenderer;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.IOException;

public class MainActivity extends AppCompatActivity {

ImageView pdfView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

pdfView = (ImageView)findViewById(R.id.pdfview);

try {
openPDF();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this,
"Something Wrong: " + e.toString(),
Toast.LENGTH_LONG).show();
}
}

private void openPDF() throws IOException {

//open file in assets

AssetManager assetManager = getAssets();
AssetFileDescriptor assetFileDescriptor =
assetManager.openFd("test.pdf");
ParcelFileDescriptor fileDescriptor =
assetFileDescriptor.getParcelFileDescriptor();

//open file from sdcard
/*
String targetPdf = "/sdcard/test.pdf";
File file = new File(targetPdf);

ParcelFileDescriptor fileDescriptor = null;
fileDescriptor = ParcelFileDescriptor.open(
file, ParcelFileDescriptor.MODE_READ_ONLY);
*/

//min. API Level 21
PdfRenderer pdfRenderer = null;
pdfRenderer = new PdfRenderer(fileDescriptor);

final int pageCount = pdfRenderer.getPageCount();
Toast.makeText(this,
"pageCount = " + pageCount,
Toast.LENGTH_LONG).show();

//Display page 0
PdfRenderer.Page rendererPage = pdfRenderer.openPage(1);
int rendererPageWidth = rendererPage.getWidth();
int rendererPageHeight = rendererPage.getHeight();
Bitmap bitmap = Bitmap.createBitmap(
rendererPageWidth,
rendererPageHeight,
Bitmap.Config.ARGB_8888);
rendererPage.render(bitmap, null, null,
PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);

pdfView.setImageBitmap(bitmap);
rendererPage.close();

pdfRenderer.close();

assetFileDescriptor.close();
}

}




Remark:If you reported with the error "java.io.IOException: not create document. Error:", read next post.

Read more »

Sunday, April 16, 2017

Difference Between EPUB PDF MOBI and AZW E Book Standards

Difference Between EPUB PDF MOBI and AZW E Book Standards


People often ask what is the difference between an e-book and a PDF file? Well, I must say that it is indeed pretty frequently asked question. An e-book and a plain PDF file are not very different from each other �but if you go in finer details, the differences will appear. I will explain this difference towards the end of this article. Today let�s understand the difference among EPUB, AZW, MOBI and PDF eBook formats.
What is an eBook?
Let�s begin with understanding the basic question, what is an e-book? An e-book is essentially an electronic document. In simple terms, it is just a computer file. In modern terminology, electronic book or e-book is the electronic version of a printed book. Electronic book can be read using computer or a custom designed mobile device.


Difference between various e-book formats like EPUB, Mobi, PDF and AZW.
In last one decade, the Internet and electronic gadgets have spread like wildfire all over the world. With this, the habit of reading books on digital devices has also grown. People have accepted e-books. Major Internet companies like Amazon quickly jumped onto this opportunity and developed specialized devices for e-book reading.
A number of e-book standard formats have been developed in order to make e-books compatible with the device specific features.
MOBI E-book Format
Mobipocket (often called just mobi) is an e-book standard format. It was initially launched by Mobipocket SA, a French company, in the year March 2000.
Mobipocket is a free e-book reader software. In 2005, Amazon acquired Mobipocket. E-books created using Mobipocket standard carry .prc or .mobi extensions. In the foundation of this standard is the Open eBook standard. Mobi format uses XHTML, JavaScript and can also include frames.
Mobi e-books can be read using Mobipocket e-book reader. This reader is actually a software and it can be installed on a large number of mobile operating systems and devices like smartphones and PDAs.
AZW E-book Format
When Amazon developed Kindle, its popular e-book reading device, it needed an e-book standard for Kindle. As I told you, Amazon had bought Mobipocket in 2005. So, Amazon modified the MOBI format a little bit and came up with the AZW e-book format.
The primary difference between MOBI and AZW is that AZW uses asterisk instead of dollar sign in the serial number scheme. Also, unlike the original MOBI format, the AZW format does not allow the use of JavaScript.
E-books with extension .prc are fully compatible with the Kindle devices and can be directly read on it.
AZW e-book format is used only on Kindle devices. Kindle does not support EPUB e-book format. But now that EPUB e-book format is also becoming a sort of industry standard, Amazon has released KindleGen software, which can convert .epub e-book into .mobi e-books.
AZW3 or KF8 E-book Formats
Early Kindle devices used AZW e-book format, which was a modified MOBI standard. But as Amazon developed even better versions of Kindle, the AZW e-book format also evolved with time.
AZW3 or KF8 is the e-book format for the fourth generation Kindle devices. This format was introduced when Amazon released Kindle Fire in the market. KF8 stands for Kindle Format 8.
AZW3 is a proprietary format of Amazon. It can not be used by any other company.
AZW3 is a Digital Rights Management (DRM) restricted format. It means that the AZW e-book files are locked to a particular device. These files can not be transferred to another device. This is done to put a stop on piracy.
PDF E-book Format
Adobe Systems developed Portable Document Format (PDF) format in 1993. This is one of the best known e-book formats as it has been there since long. PDF format is so popular that that PDF e-book files are supported by almost all e-book readers.
In 2001, Adobe made the PDF format open source.
Original PDF standard did not support reflow feature. But in 2012, an updated format called PDF/UA was released with reflow features. PDF/UA got only moderate support from the third party hardware and software manufacturers.
Difference between PDF and E-book
As we all have been seeing PDF files since we have learnt to use computers, a large number of people feel that a PDF file is an e-book. But when they see so much talk about e-books they begin to feel that an e-book must be something more sophisticated than a simple PDF file!
Well, actually a PDF file is indeed an e-book. But the modern and popular e-book formats have more features than the plain original PDF. One of such features is reflow. E-book formats like EPUB, MOBI and AZW, support reflow of the book. Reflow means that the same e-book can be read on devices of different dimensions. E-book will automatically adjust the content according to the screen size. Most of the PDFs are not designed to be reflowable. That is one of the major difference between an E-book and a PDF file.
Another big difference is that the original plain PDF format did not have the embedded meta information. Whereas E-books contain hidden meta information about the book itself and about the author, publisher etc.
You can convert any file into a PDF file but to make it a proper e-book, this PDF file should contain all the required meta information. This meta information is required to identify the book and to know about its various properties.
Encryption is yet another aspect that makes a proper e-book different from a plain PDF file. E-books may or may not contain encryption and security measures to allow only the authorized people to read them. Plain PDF files often lack such a security.
EPUB E-Book Format
EPUB is an open standard format for e-book publishing. It was created by the International Digital Publishing Forum (IDPF). Unlike Amazon�s MOBI and AZW formats, EPUB is a public and open standard.
EPUB is supported by a large number of vendors. EPUB can be read by Apple�s iBooks app (iOS), BlackBerry devices, Kobo eReader, Google Books app (Android) and almost all other notable e-book readers.
Only Amazon�s Kindle does not support EPUB. Amazon prefers to use its proprietary AZW format. In fact, as I said before, Amazon�s KindleGen can convert .epub format into .mobi format. So, if you have an e-book created with EPUB format, you can easily convert it into .mobi format and read it on your Kindle device.
Conclusion
Need of having defined formats for e-books was recognized as early as in mid 1990s. Adobe and Amazon have been the front-runners in the race of getting e-book market share. Kindle devices, however, make Amazon the undisputed leader in the e-book industry. MOBI and AZW e-book formats are proprietary and Amazon is using them to strengthen its position in the e-book industry. Widespread use of the open EPUB e-book format has, however, dented the Amazon�s monopoly. In my view, it is important to further develop EPUB. Also more and more vendors should provide support for EPUB e-books.
I hope it was useful for you to know the difference between EPUB, PDF, MOBI and AZW E-book standards. In case you have any questions, please feel free to ask. I will try my best to help you. Thank you for using Truetech4!
Read more »

Thursday, April 13, 2017

Display PDF using PdfRenderer

Display PDF using PdfRenderer



The class android.graphics.pdf.PdfRenderer enables rendering a PDF document. This example show how to:


MainActivity.java
package com.blogspot.android_er.androidpdf;

import android.graphics.Bitmap;
import android.graphics.pdf.PdfRenderer;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.File;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

String targetPdf = "/sdcard/MagPi54.pdf";

ImageView pdfView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

pdfView = (ImageView)findViewById(R.id.pdfview);

try {
openPDF();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this,
"Something Wrong: " + e.toString(),
Toast.LENGTH_LONG).show();
}
}

private void openPDF() throws IOException {
File file = new File(targetPdf);

ParcelFileDescriptor fileDescriptor = null;
fileDescriptor = ParcelFileDescriptor.open(
file, ParcelFileDescriptor.MODE_READ_ONLY);

//min. API Level 21
PdfRenderer pdfRenderer = null;
pdfRenderer = new PdfRenderer(fileDescriptor);

final int pageCount = pdfRenderer.getPageCount();
Toast.makeText(this,
"pageCount = " + pageCount,
Toast.LENGTH_LONG).show();

//Display page 0
PdfRenderer.Page rendererPage = pdfRenderer.openPage(0);
int rendererPageWidth = rendererPage.getWidth();
int rendererPageHeight = rendererPage.getHeight();
Bitmap bitmap = Bitmap.createBitmap(
rendererPageWidth,
rendererPageHeight,
Bitmap.Config.ARGB_8888);
rendererPage.render(bitmap, null, null,
PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);

pdfView.setImageBitmap(bitmap);
rendererPage.close();

pdfRenderer.close();
fileDescriptor.close();
}

}


layout/activity_main.xml, add a ImageView to display the PDF:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout


android_id="@+id/activity_main"
android_layout_width="match_parent"
android_layout_height="match_parent"
android_paddingBottom="@dimen/activity_vertical_margin"
android_paddingLeft="@dimen/activity_horizontal_margin"
android_paddingRight="@dimen/activity_horizontal_margin"
android_paddingTop="@dimen/activity_vertical_margin"
android_orientation="vertical"
tools_context="com.blogspot.android_er.androidpdf.MainActivity">

<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_margin="20dp"
android_layout_gravity="center_horizontal"
android_autoLink="web"
android_text="http://android-er.blogspot.com/"
android_textStyle="bold"/>

<ImageView
android_id="@+id/pdfview"
android_layout_width="match_parent"
android_layout_height="match_parent" />

</LinearLayout>


uses-permission of "android.permission.READ_EXTERNAL_STORAGE" is needed in AndroidManifest.xml to read file from sdcard.
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.blogspot.android_er.androidpdf">

<application
android_allowBackup="true"
android_icon="@mipmap/ic_launcher"
android_label="@string/app_name"
android_supportsRtl="true"
android_theme="@style/AppTheme">
<activity android_name=".MainActivity">
<intent-filter>
<action android_name="android.intent.action.MAIN" />

<category android_name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android_name="android.permission.READ_EXTERNAL_STORAGE"/>

</manifest>

Next:
- Display PDF in assets folder (inside APK)

Related:
- Create PDF using PdfDocument

Read more »

Thursday, April 10, 2014

Fujitsu ScanSnap S1500 Instant PDF Sheet Fed Scanner For PC

Fujitsu ScanSnap S1500 Instant PDF Sheet-Fed Scanner for PC

I have never had a dedicated document scanner before. In the past, I used the Auto-document feeder on my all-in-one printer/scanner/fax machines to scan documents into adobe acrobat. That meant for each batch of papers, I needed to set the color/resolution/paper size/quality settings and then work through Acrobat in order to save each file. It worked, but it was slow going.

Then I bought this new scansnap 1500, based on the ratings of the earlier model (the scansnap 510). I installed only the main program to my computer (the software also includes OCR programs, organizational programs, and acrobat 9, which I already have). I hooked up the scanner and stuck in a stack of old notes I took from some college courses--some notes were in color, some were b&w, some on two sides, some on one side, and some of the pages were upside down. I hit the only button on the machine (SCAN), and to my sheer amazement, it started flying through the stack of notes without any additional prompts or effort. It then automatically saved my file as a pdf--all of the pages were in order, color pages were in color, b&w pages were in b&w, etc. The only issue I noticed was that if there were any marks whatsoever on the back side of my note papers, it included those blank pages in the file.

Review about Fujitsu ScanSnap S1500 Instant PDF Sheet-Fed Scanner for PC

I purchased this scanner as a first step in creating an electronic filing system for a home office. As I accumulated 20 filing cabinet drawers of paper documents going paperless seemed to be an answer.

Purchase of the Fujitsu S1500 was based on the numerous 5 star reviews. I am reasonably tech literate and have used the scanner for about 2 weeks. Here are my initial impressions:

Pros -

1. Speed: This scanner seems blazingly fast. Not a resource hog. Will scan duplex 20-25ppm at default settings on Win2K/1. 8mhz/1gb platform.

2. Scan quality very good at all settings.

3. Size and looks: Small desk footprint. Looks great open or closed.

4. Excellent paper feeding as long as documents are same size and 20# or greater paper weight.

Cons -

1. NO TWAIN DRIVER. I knew this going in but did not appreciate how much this would cripple the device in day to day use. Let me explain. I had envisioned creating a virtual file cabinet in my computer using Windows Directory/Folder/File system then scanning my paper documents into this system as pdf files. The problem is that the native Fujitsu software does not let you append an existing pdf file!!!

As an example take a file for utility bills. D:/Home Expenses/Utilities/Gas_Electric. pdf. You can easily scan in all prior bills(limited by 50 sheet ADF)and a pdf with one page for each bill will be created. But if you had more than 50 prior bills or when next months bill comes then the next scan you perform to include these new documents will create a new pdf and does not allow the option of appending this current scan to the existing pdf. As you can see one could easily end up with 1000s of individual pdf documents in your filing system. The work around is to launch Adobe Acrobat (not reader) and use it to open the old composite pdf and use Acrobat to append the newly created pdf to the prior file. This work around takes longer than scanning in a 30 page document. Twain based scanners easily work with existing windows file structure and allow you to append an existing pdf without invoking Acrobat. .

Features:

  • One button searchable PDF creation
  • Intelligent paper feed detection
  • Blazing 20ppm color scanning
  • 50-page Automatic Document Feeder (ADF)
  • Comes with Adobe Acrobat X Standard

Read more »