- Posts: 37
- Thank you received: 1
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
How to add a single point to PDF page content
11 years 1 month ago #8455
by ashughes
How to add a single point to PDF page content was created by ashughes
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:
However, when I tried just adding a small amount to the point passed into LineTo(), it did work:
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
Code:
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();
Code:
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();
Thanks,
Andrew
11 years 1 month ago #8525
by radaee
Replied by radaee on topic How to add a single point to PDF page content
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.
to draw single point: add a small rectangle to page is better.
11 years 1 month ago #8546
by ashughes
Replied by ashughes on topic How to add a single point to PDF page content
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
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
11 years 3 weeks ago #8577
by ashughes
Replied by ashughes on topic How to add a single point to PDF page content
This is what I ended up doing to work around the issue:
It seems like a better solution would be to add a
or
that uses the width from
or even adding something to Path that adds a point.
Thanks,
Andrew
Code:
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
Code:
PageContent.DrawPoint(float x, float y, float width)
Code:
PageContent.StrokePoint(float x, float y)
Code:
PageContent.SetStrokeWidth(width)
Thanks,
Andrew
11 years 2 weeks ago #8597
by radaee
Replied by radaee on topic How to add a single point to PDF page content
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.
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.
Time to create page: 0.411 seconds