Bitmap Annotations does not show image - 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

TOPIC: Bitmap Annotations does not show image

Bitmap Annotations does not show image 3 years 4 months ago #9395

  • Haktic
  • Haktic's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0
Bitmap Annotations shows image only for the first time when pdf opens and didn't show again once i close and open the pdf again.
Here's my code to draw the bitmap annotations.
Bitmap linkIcon = BitmapFactory.decodeResource(getResources(), R.drawable.linkhighlight);
PDFVPage vpage = m_view.vGetPage(pageNo);
Page page = vpage.GetPage();
Annotation annot = page.GetAnnot(ac);
float rect[] = page.GetAnnot(ac).GetRect(); //new float[4];

float rect_dib[] = new float[4];

Matrix mat = new Matrix(1, 1, 0, m_doc.GetPageHeight(m_cur_page));

Global.ToDIBRect(mat, rect, rect_dib);//mat is Matrix object that passed to Page.Render() or Page.RenderToBmp()
float left = rect[0];
float top = rect[1];
float right = rect[2];
float bottom = rect[3];

float anWidth = right - left;
float anHeight = bottom - top;

left = rect[0];
top = rect[1];
rect[0] = left + xOffset;
rect[1] = top + yOffset;
rect[2] = rect[0] + iconWidth;
rect[3] = rect[1] + iconWidth;
page.AddAnnotBitmap(videoIcon, true, rect);
page.AddAnnotURI(rect, uriString);
mat.Destroy();
page.Close();
m_view.vRenderAsync(m_view.vGetPage(pageNo));
linkIcon.recycle();
page.ObjsStart();

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

Bitmap Annotations does not show image 3 years 4 months ago #9397

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Karma: 18
  • Thank you received: 65
Hi,
you have to save the document!
document.Save();

I suggest you to look at this article ..

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

Last edit: by Davide.

Bitmap Annotations does not show image 3 years 4 months ago #9399

  • Haktic
  • Haktic's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0
I really appreciate your quick response, but that didn't worked well, please let me know if i am adding this on the right place, Here's my function to add the Bitmap Annotations:

private void drawBitmapAnnot(){

//set annotation image of page
int lc;// loop count: 2 for landscape dualpage and 1 for portrait singlepage
int orientation =getResources().getConfiguration().orientation;

//rotation is equal 0 portrait
if(orientation == Configuration.ORIENTATION_PORTRAIT)
lc = 1;
else
lc = 2;
for(int j = 0; j < lc; j++) {
int pageNo = m_pageno + j;
try {
PDFVPage vpage = m_view.vGetPage(pageNo);
// if( vpage != null ) {
Page page = vpage.GetPage();//get page from PDFVPage, in this case, Page object no need to close.

int annotCount = page.GetAnnotCount();
if (page.GetAnnotCount() > 0) {
for (int ac = 0; ac < annotCount; ac++) {

boolean uriContainsVideoExtension = false;
page.ObjsStart();
Annotation annot = page.GetAnnot(ac);
if (annot.GetURI() != null) {

String uriString = page.GetAnnot(ac).GetURI(); //page.GetAnnotURI(page.GetAnnot(ac));
String videoExtensions[] = {".mp4", ".mov", ".3gp"};
String[] splitUri = uriString.split("#");
Log.d("PDF", ":uriString: " + uriString);
Log.d("PDF", ":uriString: " + splitUri[0]);

for (int i = 0; i < videoExtensions.length; i++) {
uriContainsVideoExtension = uriString.toLowerCase().indexOf(videoExtensions.toLowerCase()) != -1;
if (uriContainsVideoExtension)
break;
}

float rect[] = page.GetAnnot(ac).GetRect(); //new float[4];

float rect_dib[] = new float[4];

Matrix mat = new Matrix(1, 1, 0, m_doc.GetPageHeight(m_cur_page));
Global.ToDIBRect(mat, rect, rect_dib);//mat is Matrix object that passed to Page.Render() or Page.RenderToBmp()
float left = rect[0];
float top = rect[1];
float right = rect[2];
float bottom = rect[3];

float anWidth = right - left;
float anHeight = bottom - top;

Log.d("PDF", "moi schaun: ");
Log.d("PDF", " - left: " + left);
Log.d("PDF", " - right: " + right);

float xOffset = (anWidth - iconWidth) / 2;
float yOffset = (anHeight - iconWidth) / 2;

if (splitUri.length > 1) {
Log.d("PDF", " - xOffset: " + xOffset);
Log.d("PDF", " - #pos: " + splitUri[1]);

if (splitUri[1].equals("tl")) {
xOffset = 0;
yOffset = (anHeight - iconWidth);
}
if (splitUri[1].equals("tc")) {
xOffset = (anWidth - iconWidth) / 2;
yOffset = (anHeight - iconWidth);
}
if (splitUri[1].equals("tr")) {
xOffset = anWidth - iconWidth;
yOffset = (anHeight - iconWidth);
}
if (splitUri[1].equals("cl")) {
xOffset = 0;
yOffset = -(anHeight - iconWidth) / 2;
}
if (splitUri[1].equals("cr")) {
xOffset = anWidth - iconWidth;
yOffset = -(anHeight - iconWidth) / 2;
}
if (splitUri[1].equals("bl")) {
xOffset = 0;
yOffset = 0;
}
if (splitUri[1].equals("bc")) {
xOffset = (anWidth - iconWidth) / 2;
yOffset = 0;
}
if (splitUri[1].equals("br")) {
xOffset = anWidth - iconWidth;
yOffset = 0;
}
}

left = rect[0];
top = rect[1];
rect[0] = left + xOffset;
rect[1] = top + yOffset;
rect[2] = rect[0] + iconWidth;
rect[3] = rect[1] + iconWidth;


if (uriContainsVideoExtension) {
Boolean flag=page.AddAnnotBitmap(videoIcon, false, rect);
page.AddAnnotURI(rect, uriString);
} else {
Boolean flag =page.AddAnnotBitmap(linkIcon, false, rect);
page.AddAnnotURI(rect, uriString);
}

}
}
page.Close();
m_view.vRenderAsync(m_view.vGetPage(pageNo));
page.ObjsStart();
m_doc.Save();
}
}catch (NullPointerException e){
Log.d("exception in adding image annotation",e.toString());
}
}
}

Annotation Image loads perfect for first time when i see the pdf but once i close and open again, links works fine but image didn't show up.
Also the color of rectangle for annotation where the image should display get darker blue on each loading means it loads again and again. can you please suggest ? thansk

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

Bitmap Annotations does not show image 3 years 4 months ago #9400

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Karma: 18
  • Thank you received: 65
Hi,
what version of the library are you using?
Can you reproduce this issue with the last version ?

Have you checked this article ?
I also suggest you to look at PDFSetStamp() method of Demo Project.

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

Bitmap Annotations does not show image 3 years 4 months ago #9401

  • Haktic
  • Haktic's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 0
Yes I have checked this code sample, but in this Document.DocImage docimage = m_doc.NewImage(linkIcon, true); returns a null object.
And I am using RadaeePDF AndroidStudio 3.5 version , which is latest, do you think updating to this beta version will resolve the problem .. ?

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

Last edit: by Haktic.

Bitmap Annotations does not show image 3 years 4 months ago #9402

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Karma: 18
  • Thank you received: 65
Hi,
to use this method you need a Premium license.
Are you passing a correct bitmap to this method?

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

Powered by Kunena Forum