pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chitgoks <chitg...@gmail.com>
Subject Re: freetext, drawing, polygon annotation
Date Tue, 07 Mar 2017 02:05:04 GMT
Hi tilman. this is my code.

COSDictionary ddict = new COSDictionary();
ddict.setName(COSName.SUBTYPE, PDAnnotationMarkup.SUB_TYPE_INK);

COSArray newInklist = new COSArray();
for (DrawingPosition dp : getDrawingPositions()) {
    float[] drawPointXY = new float[2];
    drawPointXY[0] = dp.getX();
    drawPointXY[1] = dp.getY();

    COSArray newArray = new COSArray();
    newArray.setFloatArray(drawPointXY);
    newInklist.add(newArray);
}
ddict.setItem(COSName.INKLIST, newInklist);

PDAnnotationMarkup inkAnnot = new PDAnnotationMarkup(ddict);
inkAnnot.setRectangle(location);

PDBorderStyleDictionary drawBorderDict = new PDBorderStyleDictionary();
drawBorderDict.setWidth(2);
drawBorderDict.setStyle(PDBorderStyleDictionary.STYLE_SOLID);
inkAnnot.setBorderStyle(drawBorderDict);

The array of x,y points looks like this

COSArray{[COSArray{[COSFloat{462.9}, COSFloat{549.6}]},
COSArray{[COSFloat{462.9}, COSFloat{550.8}]},
COSArray{[COSFloat{462.30002}, COSFloat{552.6}]},
COSArray{[COSFloat{460.5}, COSFloat{554.4}]},
COSArray{[COSFloat{459.30002}, COSFloat{556.2}]},
COSArray{[COSFloat{455.69998}, COSFloat{559.8}]},
COSArray{[COSFloat{450.9}, COSFloat{564.0}]},
COSArray{[COSFloat{443.69998}, COSFloat{570.0}]},
COSArray{[COSFloat{431.1}, COSFloat{576.6}]}, COSArray{[COSFloat{420.9},
COSFloat{583.8}]}, COSArray{[COSFloat{409.5}, COSFloat{590.4}]},
COSArray{[COSFloat{395.1}, COSFloat{595.8}]}, COSArray{[COSFloat{383.1},
COSFloat{600.6}]}, COSArray{[COSFloat{370.5}, COSFloat{603.6}]},
COSArray{[COSFloat{357.9}, COSFloat{607.2}]}, COSArray{[COSFloat{347.1},
COSFloat{610.2}]}, COSArray{[COSFloat{338.7}, COSFloat{610.2}]},
COSArray{[COSFloat{330.9}, COSFloat{610.2}]}, COSArray{[COSFloat{323.7},
COSFloat{609.0}]}, COSArray{[COSFloat{318.9}, COSFloat{606.6}]},
COSArray{[COSFloat{314.1}, COSFloat{603.6}]}, COSArray{[COSFloat{307.5},
COSFloat{598.2}]}, COSArray{[COSFloat{300.9}, COSFloat{590.4}]},
COSArray{[COSFloat{296.1}, COSFloat{583.8}]}, COSArray{[COSFloat{291.3},
COSFloat{574.2}]}, COSArray{[COSFloat{287.1}, COSFloat{567.0}]},
COSArray{[COSFloat{282.3}, COSFloat{558.0}]}, COSArray{[COSFloat{278.1},
COSFloat{549.0}]}, COSArray{[COSFloat{273.3}, COSFloat{540.0}]},
COSArray{[COSFloat{269.1}, COSFloat{532.8}]}, COSArray{[COSFloat{264.3},
COSFloat{526.8}]}, COSArray{[COSFloat{250.5}, COSFloat{512.4}]},
COSArray{[COSFloat{246.3}, COSFloat{510.0}]},
COSArray{[COSFloat{240.90001}, COSFloat{507.6}]},
COSArray{[COSFloat{234.3}, COSFloat{504.6}]}, COSArray{[COSFloat{227.7},
COSFloat{502.8}]}, COSArray{[COSFloat{221.09999}, COSFloat{501.0}]},
COSArray{[COSFloat{214.5}, COSFloat{500.4}]}, COSArray{[COSFloat{208.5},
COSFloat{500.4}]}, COSArray{[COSFloat{200.09999}, COSFloat{500.4}]},
COSArray{[COSFloat{194.7}, COSFloat{501.0}]}, COSArray{[COSFloat{188.7},
COSFloat{501.6}]}, COSArray{[COSFloat{184.5}, COSFloat{503.4}]},
COSArray{[COSFloat{179.7}, COSFloat{504.6}]}, COSArray{[COSFloat{176.7},
COSFloat{506.4}]}, COSArray{[COSFloat{173.7}, COSFloat{507.6}]},
COSArray{[COSFloat{171.9}, COSFloat{508.8}]}, COSArray{[COSFloat{170.1},
COSFloat{510.0}]}, COSArray{[COSFloat{168.9}, COSFloat{511.8}]},
COSArray{[COSFloat{168.9}, COSFloat{512.4}]}, COSArray{[COSFloat{168.9},
COSFloat{513.0}]}]}

Attached is the result


Website/Java Games: http://www.chitgoks.com
My Blogs:
http://tech.chitgoks.com
http://wuhtevah.chitgoks.com
http://disneyusa.blogspot.com

On Tue, Mar 7, 2017 at 1:25 AM, Tilman Hausherr <THausherr@t-online.de>
wrote:

> Am 06.03.2017 um 10:14 schrieb chitgoks:
>
>> i got it to work. my first mistake was that the subtype is Ink not
>> InkList.
>>
>> it shows the drawing now. however, the issue is that the points are
>> scattered and not interconnected. I expected pdfbox to link the points so
>> they would be displayed as one continuous drawing.
>>
>> any idea on what might be lacking? perhaps a COSName?
>>
>
>
> I can't comment much without looking at your PDF (upload it somewhere).
> When I wrote "an array of arrays", I mean this from the PDF specification:
>
> "An array of n arrays, each representing a stroked path. Each array shall
> be a series of alternating horizontal and vertical coordinates in default
> user space, specifying points along the path. When drawn, the points shall
> be connected by straight lines or curves in an implementation-dependent
> way."
>
> Maybe you put one coordinate pair in one array, instead of all points of a
> line in one array?
>
> "Array of arrays" means that if you have only one path with 8 points, then
> you have one array with one element, this element is an array with 16
> numbers. To see how an inklist is, open the file from PDFBOX-2583 in
> PDFDebugger.
>
> Tilman
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Mime
View raw message