Large document size after saving - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about Android development and PDF
  • Page:
  • 1

TOPIC: Large document size after saving

Large document size after saving 3 years 5 months ago #9187

  • mzuber23
  • mzuber23's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 12
  • Thank you received: 0
In my app, I'm trying to support the creation of a PDF document where every page is generated from a Bitmap. I have the code working for this, but there are two things that concern me. The first is the amount of time this takes to complete, and the second is the resulting size of the PDF. For example, if I take the ~3.75 MB PDF file that I've attached, render each page to a Bitmap, take that bitmap and put it in a new document I've created, the new document is about 48 MB after it is saved. I believe this may be due to the fact that the original PDF is using 300 dpi grayscale images, but I don't have any tools that can tell me this for certain. Even if I could product grayscale images to use with RadaeePDF, in theory it would be 1/4th the size, or 10 MB, which is still much larger than the original. So, that leads me to the following questions:

1) I'm currently using the same code as PDFTestAct.java to build each page in the document from the bitmap. Is this the best way to do it, or is there a more efficient way I'm unaware of?
2) Is there any way I can detect if a page is using grayscale images?
3_ Is there any way I can create a page using grayscale image data without using an existing grayscale JPEG file? Would I have to build the JPEG data in code and feed that through a byte array? Is there any method in the current api that would allow 1 byte of pixel data per index in the array?

I realize that RadaeePDF supports the ability to merge existing PDF pages, and I plan to leverage this, as I imagine it will be more efficient and will keep the document size smaller. Some of the pages I will create do not come from PDFs, and instead come from Bitmaps I generate, so I need to make sure I'm using the best approach for creating pages from Android Bitmaps.

Thanks for the help and guidance.
Mike

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

Large document size after saving 3 years 5 months ago #9188

  • support
  • support's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 571
  • Karma: 6
  • Thank you received: 46
It seems you are looking for a code like that below:
File file = new File(Environment.getExternalStorageDirectory(), "/test_image.jpg");
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
Page page = document.GetPage(0);
PageContent pageContent = new PageContent();
pageContent.Create();
pageContent.GSSave();
com.radaee.pdf.Matrix mat = new com.radaee.pdf.Matrix(200, 112.5f, 100, 300);
pageContent.GSSetMatrix(mat);
mat.Destroy();
Document.DocImage docimage = document.NewImage(bitmap, true);
Page.ResImage rimage = page.AddResImage(docimage);
pageContent.DrawImage(rimage);
pageContent.GSRestore();
res = page.AddContent(pageContent, false);
pageContent.Destroy();
page.Close();
document.Save();

When adding a bitmap to a page starting from a dib or bmp image stored in memory, image data are stored as uncompressed stream, so you are experiencing the creation of huge file.

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

Large document size after saving 3 years 5 months ago #9192

  • mzuber23
  • mzuber23's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 12
  • Thank you received: 0
That code basically matches what I am doing. Is there any way I can easily compress the stream before adding it to the PDF? Or would I have to save out the bitmap as a compressed JPEG first, and then use the NewImageJPEG function? I imagine that would be pretty slow, but if it will significantly reduce the size of the PDF, it's probably worth it.

What about grayscale images? Is there any support for detecting or adding them? Or would I have to take an Android bitmap, convert to grayscale using a filter, then compress that to a JPEG file, and then import that into RadaeePDF?

Thanks,
Mike

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

Last edit: by mzuber23.

Large document size after saving 3 years 5 months ago #9197

  • support
  • support's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 571
  • Karma: 6
  • Thank you received: 46
JavaDocs aren't updated yet as the method is available in 3.5beta releases.

You should look at:
/**
     * create an image from JPEG/JPG byte array.<br/>
     * supported image color space:<br/>
     * --GRAY<br/>
     * --RGB<br/>
     * --CMYK<br/>
     * a premium license is needed for this method.
     * @param data byte array include whole jpg file.
     * @param len byte length of data.
     * @return DocImage object or null.
     */
    public DocImage NewImageByMem( byte[] data, int len )
    {
        long ret = newImageJPEGByArray(hand_val, data, len);
        if( ret != 0 )
        {
            DocImage img = new DocImage();
            img.hand = ret;
            return img;
        }
        else return null;
    }
The following user(s) said Thank You: mzuber23

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

  • Page:
  • 1
Powered by Kunena Forum