- Posts: 16
- Thank you received: 0
Microsoft Windows Phone 8.1 support ends (13 Jul 2017)
Microsoft has ended support for Windows Phone 8.1
Questions about Android development and PDF
Bitmap Annotations does not show image
10 years 5 months ago #9395
by Haktic
Bitmap Annotations does not show image was created by Haktic
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();
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();
10 years 5 months ago - 10 years 5 months ago #9397
by Davide
Replied by Davide on topic Bitmap Annotations does not show image
Last edit: 10 years 5 months ago by Davide.
10 years 5 months ago #9399
by Haktic
Replied by Haktic on topic Bitmap Annotations does not show image
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
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
10 years 5 months ago #9400
by Davide
Replied by Davide on topic Bitmap Annotations does not show image
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.
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.
10 years 5 months ago - 10 years 5 months ago #9401
by Haktic
Replied by Haktic on topic Bitmap Annotations does not show image
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 .. ?
And I am using RadaeePDF AndroidStudio 3.5 version , which is latest, do you think updating to this beta version will resolve the problem .. ?
Last edit: 10 years 5 months ago by Haktic.
Time to create page: 0.453 seconds