Processing PDFs to reduce file size / and or complexity - android

I have PDF files I need to prepare for viewing on mobile devices. The worse case would be ~50 pages, with lots full color images and vector art, file size approx. 40MB. This is acceptable for PC viewing on broadband, but not great for mobile viewing due to long download times and very laggy scrolling on mobile (At least on my overclocked Droid). Are there any tools or libraries for processing the files to simply the vector stuff, downsample/recompress the images, that sort of thing?
Output in pdf format is not absolutely essential, but it needs to be something readable on android and iOS devices without software downloads.

There are a few main things that can blow up the size of a PDF on mobile devices:
hi-resolution pictures (where lo-res would suffice)
embedded fonts (where content would still be readable "good enough" without them)
PDF content not required any more for the current version/view (older version of certain objects)
embedded ICC profiles
embedded third-party files (using the PDF as a container)
embedded job tickets (for printing)
embedded Javascript
and a few more
FOSS software: Ghostscript can try to size down your PDFs, mainy be re-sampling the pictures used and by removing older versions ("generations") of PDF objects which were replaced by newer ones:
gswin32c.exe ^
-o sized-down.pdf ^
-sDEVICE=pdfwrite ^
-dPDFSETTINGS=/ebook ^
-dEmbedAllFonts=false ^
-c ".setpdfwrite <</AlwaysEmbed [ ]>>" ^
-f blown-up.pdf
You can add more parameters to above commandline to size down certain PDFs even more (f.e. by setting a lower max resolution, etc.) Here is an example to enforce a downsampling for color and grayscale images to 72dpi:
gswin32c.exe ^
-o sized-down.pdf ^
-sDEVICE=pdfwrite ^
-dPDFSETTINGS=/ebook ^
-dEmbedAllFonts=false ^
-dColorImageDownsampleThreshold=1.0 ^
-dColorImageDownsampleType=/Average ^
-dColorImageResolution=72 ^
-dGrayImageDownsampleThreshold=1.0 ^
-dGrayImageDownsampleType=/Average ^
-dGrayImageResolution=72 ^
-c ".setpdfwrite <</AlwaysEmbed [ ]>>" ^
-f blown-up.pdf
Commercial+closed source software: callas pdfToolbox4 is able to reduce file sizes even more by applying a custom profile to the PDF downsizing process (it can even un-embed fonts and ICC profiles).
Update 2: See also the following (new) question with the answer:
How can I remove all images from a PDF?
It provides some sample PostScript code which completely removes all (raster) images from the PDF, leaving the rest of the page layout unchanged. This is useful in cases where you do not want the (raster) images, but only the text parts in order to reduce file size.

Adobe Acrobat Professional has two built-in tools for optimizing PDF files:
"PDF Optimizer" - http://www.adobe.com/designcenter/acrobat/articles/acr7optimize.html, which will simplify vectors and removed unneeded content (among other things)
and
"Optimize Scanned PDF" -http://help.adobe.com/en_US/Acrobat/9.0/Standard/WS58a04a822e3e50102bd615109794195ff-7f71.w.html#WS0BEFAC0B-47D9-47b8-9AF8-4DE2FE9C9736.w, which will downsample and compress embedded raster images.
Both are the best tools for what they do that I have used. However, the focus of most PDF optimization tools is to reduce file size not improve rendering speed.
If you want to drastically improve rendering performance on your device you should consider pre-rendering the PDFs to bitmap images. If you scale them up a bit before rasterizing (to allow for on-device zooming) and stick to an indexed color scheme you should be able to produce rasters for each page that are an acceptable file size and resolution. They will draw much more quickly on the device than vector content would.

There are options in Acrobat to reduce image size and improve PDF filesize/speed. Have you looked this option?

Are you planning on the user having the PDF files stored on their phone for viewing offline? If not, could you batch convert the PDF files into HTML? You could also post-process any images to lower the quality/filesize.
Some options for converters include:
Email either a link to the PDF, or the actual PDF to pdf2html#adobe.com. You will receive back an HTML version of the PDF. More info on the Adobe site
Use standalone software such as pdf995 or pdf2html
Use a commercial Adobe Acrobat plugin, such as LD-Converter
I'm sure there are even more options for performing the conversion.
As an outside bet, have you tried viewing your PDF's from your phone using the google online reader?

Some time ago (a few years) I used to reduce the size of PDFs by converting them to djvu (say, through http://any2djvu.djvuzone.org/ or the locally-installed free command-line tools). The results were very nice (small).
At that time, AFAIK, PDF didn't include the support for encodings of the same efficiency in size as djvu, but now I have been told that the PDF format has included the encodings that are as good as djvu. So, there must be tools that do a similarly good optimization for PDF. Look for them.
Or you could distribute djvus, but I'm not sure djvu-reading software is pre-installed in your OSes.

it needs to be something readable on android and iOS devices without software downloads.
You can pre-process your PDF with a tool like k2pdfopt.
It changes this ===================> to this:
______
From its sources, the project started in 2012.

Related

Qt Android: Put videos inside app directory files

I have around 10 video files in the sizes of 10 MB each. I want to have them inside the /data/user/0/org.my.app/files. Somehow they need to be included in the .apk and installed here.
Right now they are living in this structure in Qt project:
DISTFILES += \
assets/video/video1.mp4
The goal is to be able to play the videos using
Video {
source: appPath + "/assets/video/video1.mp4"
}
The ideal way is just using .qrc but it has been problems before when putting videos there.
With video, it's usually impractical to try to make it a resource since the size of the QRC will explode and result in long compile times and a large executable.
I've had luck delivering videos with a Qt Android app by using the native Java AssetManager: https://developer.android.com/reference/android/content/res/AssetManager
You'll need to use a CustomActivity in Java-land and integrate with it using JNI as demonstrated here: https://doc.qt.io/qt-5/qtandroidextras-customactivity-example.html
Or as #splaytreez points out you can use Qt's builtin support for Android Assets as documented here: https://doc.qt.io/qt-5/porting-to-android.html
Also, depending on the size of your video and what it does to your APK size, you may want to use the AAB bundle as discussed here: https://developer.android.com/guide/app-bundle/

How to display a TIFF image in a Flutter app on an Android device?

Our application allows users to set up a library of various types of resources such as PDFs, spreadsheets, etc. I.e. just about any MIME type of document, which we store on S3.
When a user clicks to view any of these resources we basically determine if we are on an iOS device or Android. On iOS we use url_launcher to basically show just about anything.
Android is a bit more complex, but if the mime type is an image we just also use url_launcher. If not we download the file to a local file and invoke the OpenFile package to show the result (if we can).
This works generally pretty good, except for TIFF image types, which don't display natively in the browser...
Is there an easy way to show TIFF images in a full flutter screen (similar to showing it in a browser) on the Android platform? Actually for image/ mime types is there an easier way to show them rather than url_launcher in general?
The other Stack Overflow question about TIFF on Android does not address this issue as that is for a native Android app and this is for Flutter and that solution doesn't lend itself (easily that I can see) to a Flutter application.
The question is quite old but i still want to answer it :)
What you can do with the Image Library is to decode the image (whatever it is) and then encode it as a png and then pass it to the Image Widget.
Why PNG??? => in widgets/images.dart it says
/// This only accepts compressed image formats (e.g. PNG). Uncompressed
/// formats like rawRgba (the default format of [dart:ui.Image.toByteData])
/// will lead to exceptions.
Todo:
I had to import the Image Library as imgLib otherwise it was colliding with the Image Widget from Flutter...
import 'package:image/image.dart' as imgLib;
....
imgLib.Decoder dec = imgLib.findDecoderForData(response.data);
Image.memory(imgLib.encodePng(dec.decodeImage(response.data)))
Then you have an Image Widget for displaying it on the UI

Mupdf compile with only pdf support

I was working on a lightweight pdf viewer, and I wanted the size to be of the range of 5 MBs,
I am using mupdf , but the compiled .so file itself is around 16.6 MBs,
Is there a way to compile mupdf with only pdf support and not the others like xps, images, etc.
Like this app on google play, the file of .so file is just 3 MBs
https://play.google.com/store/apps/details?id=de.geraldthaler.octopuspdf,
Any help will be greatly appreciated.
I figured, It was because of the font packs,
compiling without extra font packs generates very small .so's
If this is still relevant:
There is a configuration file In MuPDF source that lets you throw out features before you generate the library, called config.h located in directory mupdf/include/fitz.
By setting the appropriate #define statements, XPS, EPUB, etc. can be opted out. The biggest space saver is however opting out certain fonts. In essence you can restrict your library to PDF's Base-14 (Helvetica, Times-Roman, Courier, Symbol and ZapfDingbats) fonts. You also can opt out support for various image format support.
Taking all that together should bring you down well below 5 MB.

A library for cross-platform (C++/Android) lossless/low noise video compression/decompression

I have a need to compress a video stream to transfer it from a C++ library to a Java platform (Android) by network and decompress it there.
The requirements are as follows:
The library must be available both for Android platform and C++ (or, 2 separate libraries using a common format)
Compression must be lossless OR lossy with minimal artifacts
Library(-ies) must be free/opensource
The specifics of the task are that the video stream will be an aircraft MFD type, so there will be large number of pixels which will stay same across multiple frames. This should help much in the compression.
Is there any "easy path" for the above?
Search from open source video codecs. Seems that two are listed lossless there. How useful these are on Android or how portable is hard to tell. I don't think there are any easier paths.

Graphic for Android/iPhone

I'm making a illustrated instruction for how to use an app that will be needed
for Android/iPhone
I'm not much into coding for Android and I though the client just needed the
illustration but he asks:
"We will need the illustration saved to a file that we can run on mobile devices (iPhone/Android) as well as the source code."
Isn't jpg enough? is there some additional code that you android programmers are
aware of?
No. In Android you can just use a Drawable. This can be a number of different file formats, including your jpeg. It may be good to have a look at Android Asset Studio. With this tool you can get a nice zip file for all your different screen densities. If you keep the file structure that asset studio outputs then Android will do all the heavy lifting for you.
It might also help you to know something about 9-patches. This is how Android knows how to resize and stretch your image. Asset Studio has an option to set this as well.

Categories

Resources