Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

Add bitmap to certain position 6 years 5 months ago #13050

  • msanchezv
  • msanchezv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 7
  • Thank you received: 0
Hi!

I'm testing how the SDK works with images. I have created a view where I draw some lines, then i get its bitmap (i have checked it's not null setting it in an ImageView) and have tried to insert it in the PDF unsuccesfuly.

I have used this method I create in PDFLayoutView:
public void addImage(Bitmap image) {
		Page page = m_doc.GetPage(m_pageno);
		if (page != null)
		{
			Document.DocImage docImage = m_doc.NewImage(image, true);
			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();
			ResImage rimage = page.AddResImage(docImage);
			pageContent.DrawImage(rimage);
			pageContent.GSRestore();
			page.AddContent(pageContent, false);
			pageContent.Destroy();
			page.Close();
			m_doc.Save();
		}
	}

The bitmap has been created with a canvas, drawing on it. When i execute that method, there is no feedback or behaviour in the UI lo let me know anything has happened to that PDF (the image is not inserted). When I re-open the app the PDF document has no changes.

Why the method is not working? How can I add an image in a certain position from the pdf page (for example, at the bottom Y pdf from the bottom and X from the right, like a signature?

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

Last edit: by msanchezv.

Add bitmap to certain position 6 years 5 months ago #13051

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
Hi,
are you testing it with the demo project or in your own app?
If you are using your project without a premium license, some methods will not work, I suggest you to check this article for the tests www.radaeepdf.com/support/knowledge-base?view=kb&kbartid=4

You can use this to refresh the view and see the changes :
public void refreshView(int pageToRefresh){
   if(m_layout != null) {
      m_layout.vRenderSync(m_layout.vGetPage(pageToRefresh));
      invalidate();
   }
}

To change image position, you have to change Matrix values.

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

Add bitmap to certain position 6 years 5 months ago #13052

  • msanchezv
  • msanchezv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 7
  • Thank you received: 0
I am using the test app with the following configuration:
        public static int mLicenseType = 2;
	public static String mCompany = "radaee";
	public static String mEmail = "radaee_com@yahoo.cn";
	public static String mKey = "LNJFDN-C89QFX-9ZOU9E-OQ31K2-FADG6Z-XEBCAO";

I have debugged and see that this line return null:
Document.DocImage docImage = m_doc.NewImage(image, true);

my image value is not null but docImage yes. What is the problem?

And, matrix params (sx,sy,x0,y0) What do they represent? (sx and sy) Screen phone pixel? Because I don't know the screen pixel, what I need is something "relative", example: I need the image at the bottom right, with X pixels in document margin right and X below.

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

Last edit: by msanchezv. Reason: Debug and find null values

Add bitmap to certain position 6 years 5 months ago #13053

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Thank you received: 65
Hi,
I have checked your code with the demo project and it works properly.
Please check if page.AddContent(pageContent, false); returns true. If this returns false the problem is related to the license activation.
For NewImage method try to change the bitmap you are using for tests

In the matrix the 0,0 position is in the bottom-left.
Here you will find the documentation about matrix : www.radaeepdf.com/documentation/javadocs...daee/pdf/Matrix.html

I suggest you to check the PDFTestAct, here you will find some examples about creating page contents.

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

Add bitmap to certain position 6 years 5 months ago #13054

  • msanchezv
  • msanchezv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 7
  • Thank you received: 0
Hi, I am testing with other image (this time, some png image found on the Internet), but newImage is still returning null.

It it's usefull... I have tried some codes from PDFTestAct like this:
Document.DocGState dgs = m_doc.NewGState();
etc

But even that line return null... Is anything wrong with the opened doc?

I opened it by this way:
PDFAssetStream stream = new PDFAssetStream();
        stream.open(getAssets(), getIntent().getStringExtra("file"));
        final Document doc = new Document();

        int ret = doc.OpenStream(stream, null);


        pdf_view.PDFOpen(doc, this);

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

Last edit: by msanchezv. Reason: More info

Add bitmap to certain position 6 years 5 months ago #13055

  • msanchezv
  • msanchezv's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 7
  • Thank you received: 0
Even with the fragment of code from PDFTestAct doesn't work:
PageContent content = new PageContent();
		content.GSSave();
		Bitmap bmp = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);//must be ARGB_8888
		bmp.eraseColor(0xc0000080);
		Document.DocImage dimg = m_doc.NewImage(bmp, true);

newImage(...) returns null.

Anyone could imagine where's the origin of the problem?

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

  • Page:
  • 1
  • 2
Powered by Kunena Forum