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

TOPIC:

How to add a single point to PDF page content 10 years 2 months ago #8455

  • ashughes
  • ashughes's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 37
  • Thank you received: 1
I need to draw only a single point in the content of a PDF page. I tried to draw a line from and to the same x,y point, but no point appears in the PDF. For example:
PageContent content = new PageContent();
content.GSSave();
content.SetStrokeColor(color);
content.SetStrokeJoin(1); // round
content.SetStrokeCap(1); // round
content.SetStrokeWidth(width);
Path path = new Path();
path.MoveTo(x1, y1);
path.LineTo(x1, y1);
content.StrokePath(path);
path.Destroy();
content.GSRestore();
pdfPage.AddContent(content, false);
content.Destroy();
However, when I tried just adding a small amount to the point passed into LineTo(), it did work:
PageContent content = new PageContent();
content.GSSave();
content.SetStrokeColor(color);
content.SetStrokeJoin(1); // round
content.SetStrokeCap(1); // round
content.SetStrokeWidth(width);
Path path = new Path();
path.MoveTo(x1, y1);
path.LineTo(x1+0.001f, y1+0.001f); // <- Added 0.001f to the point
content.StrokePath(path);
path.Destroy();
content.GSRestore();
pdfPage.AddContent(content, false);
content.Destroy();
Is this what I need to do? Or is there a more correct way to draw a single point to the content of a PDF page? Or is this a bug in the SDK?

Thanks,
Andrew

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

How to add a single point to PDF page content 10 years 2 months ago #8525

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
it is checked in native library, if moveto is same to lineto point, shall ignored lineto point.
to draw single point: add a small rectangle to page is better.

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

How to add a single point to PDF page content 10 years 2 months ago #8546

  • ashughes
  • ashughes's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 37
  • Thank you received: 1
Thanks for the clarification. I don't see any methods in PageContent or Path to draw a rectangle. Could you clarify what you mean?

Are there any issues with the way I mentioned in my original post (adding a second point to a line that is very slightly different than the first point)?

Thanks,
Andrew

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

How to add a single point to PDF page content 10 years 2 months ago #8577

  • ashughes
  • ashughes's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 37
  • Thank you received: 1
This is what I ended up doing to work around the issue:
private void drawPoint(PageContent content, float x, float y, float width) {
    content.SetStrokeWidth(width);
    Path path = new Path();
    path.MoveTo(x, y);
    path.LineTo(Float.intBitsToFloat(Float.floatToIntBits(x) + 1), Float.intBitsToFloat(Float.floatToIntBits(y) + 1)); // This adds one bit to the floats x and y, causing them to be the smallest possible difference from x and y
    content.StrokePath(path);
    path.Destroy();
}

It seems like a better solution would be to add a
PageContent.DrawPoint(float x, float y, float width)
or
PageContent.StrokePoint(float x, float y)
that uses the width from
PageContent.SetStrokeWidth(width)
or even adding something to Path that adds a point.

Thanks,
Andrew

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

How to add a single point to PDF page content 10 years 2 months ago #8597

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
to draw single point:
Path path = new Path();
path.MoveTo(x1, y1);
path.LineTo(x1, y1 + 1);
path.LineTo(x1 + 1, y1 + 1);
path.LineTo(x1 + 1, y1);
path.ClosePath();
content.FillPath(path);
path.Destroy();
//todo: add content to page.

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

  • Page:
  • 1
Powered by Kunena Forum