Aspose PDF Arrow Annotation 문의

안녕하세요.
Aspose PDF 를 활용하여 Annotation 을 추가하는 작업을 하고 있습니다.

커스텀하게 사용하고 싶은 Annotation 이 있어 가능할지 문의드립니다.

image.png (5.0 KB)

제가 원하는 건 이런 화살표 주석이구요.

현재 화살표 추가는 LineAnnotation 에 ClosedArrow 사용 중입니다.

        // 화살표 추가
        public static void AddArrowAnnotation(Page page, double x1, double y1, double x2, double y2, int thickness, Aspose.Pdf.Color color)
        {
            LineAnnotation arrow = new LineAnnotation(page, new Aspose.Pdf.Rectangle(x1, y1, x2, y2),
                new Aspose.Pdf.Point(x1, y1), new Aspose.Pdf.Point(x2, y2));

            arrow.Color = color;
            arrow.Border = new Border(arrow) { Width = thickness };
            arrow.EndingStyle = LineEnding.ClosedArrow;
            page.Annotations.Add(arrow);
        }

image.png (1.1 KB)

결과물은 이렇게 나오는데 원하는 모양은 아니여서요.

해당 화살표를 만들고 싶은데 방법이 있는지 확인 부탁드립니다.

감사합니다.

@wjchae

안녕하세요! 원하는 화살표 주석을 만들기 위해서는 LineAnnotationEndingStyle 속성을 조정하는 것 외에도, 화살표의 모양을 커스터마이즈할 수 있는 방법이 필요합니다. 현재 사용하고 계신 ClosedArrow 스타일은 기본적인 화살표 모양을 제공하지만, 원하는 형태를 얻기 위해서는 추가적인 설정이 필요합니다.

원인: 화살표의 모양이 기본 스타일로는 원하는 형태를 충족하지 못할 수 있습니다.

해결책: 화살표의 두께와 색상을 조정하는 방법을 포함한 코드 예시를 제공하겠습니다:

public static void AddCustomArrowAnnotation(Page page, double x1, double y1, double x2, double y2, int thickness, Aspose.Pdf.Color color)
{
    LineAnnotation arrow = new LineAnnotation(page, new Aspose.Pdf.Rectangle(x1, y1, x2, y2),
        new Aspose.Pdf.Point(x1, y1), new Aspose.Pdf.Point(x2, y2));

    arrow.Color = color;
    arrow.Border = new Border(arrow) { Width = thickness };
    arrow.EndingStyle = LineEnding.ClosedArrow; // 기본 화살표 스타일
    // 추가적인 스타일 조정이 필요할 경우, 여기서 설정
    page.Annotations.Add(arrow);
}

이 코드를 사용하여 화살표의 두께와 색상을 조정할 수 있습니다. 만약 더 복잡한 화살표 모양이 필요하다면, 사용자 정의 그래픽을 사용하여 화살표를 그리는 방법도 고려해볼 수 있습니다.

다음 단계: 위의 코드를 적용해 보시고, 원하는 화살표 모양이 구현되는지 확인해 주세요. 추가적인 질문이나 도움이 필요하시면 언제든지 말씀해 주세요!

도움이 되었으면 좋겠습니다!

추가적인 스타일 조정이 어떤 것이 있나요?
Rectangle 을 그릴 때 전달한 사각형 좌표가 EndingStyle 설정 시 축소되어 보이는데 유지할 수 있을까요?

LineAnnotation 외에 Arrow 모양의 주석을 그리기 위한 방법은 무엇이 있나요??

답변이 늦어 죄송합니다.
귀하의 경우에는 PolygonAnnotation이 더 적합합니다.
이 예제는 원하는 스타일로 주석을 그리는 데 도움이 됩니다.

using Aspose.Pdf;
using Aspose.Pdf.Annotations;

namespace ForumTask
{
    internal class Program
    {
        private const string DataDir = @"E:\Samples";
        private const string InputFile = "sample.pdf";
        private const string OutputFile = "sample_polygon.pdf";
        private const int BaselineY = 350;
        private const int ArrowWidth = 80;
        private const int BodyWidth = 30;
        private const int BodyLength = 295;
        private const int xStart = 50;
        private const int xEnd = 450;

        static void Main(string[] args)
        {
            try
            {
                var inputPath = System.IO.Path.Combine(DataDir, InputFile);
                var outputPath = System.IO.Path.Combine(DataDir, OutputFile);

                using var document = new Document(inputPath);

                // Define polygon points for the annotation
                var points = new[]
                {
                    new Point(xStart, BaselineY + BodyWidth / 2),
                    new Point(xStart+BodyLength, BaselineY + BodyWidth / 2),
                    new Point(xStart+BodyLength, BaselineY + ArrowWidth / 2),
                    new Point(xEnd, BaselineY),
                    new Point(xStart+BodyLength, BaselineY - ArrowWidth / 2),
                    new Point(xStart+BodyLength, BaselineY - BodyWidth / 2),
                    new Point(xStart, BaselineY - BodyWidth / 2),
                };

                // Create the polygon annotation
                var polygonAnnotation = new PolygonAnnotation(document.Pages[1],
                    new Rectangle(xStart, BaselineY - BodyWidth / 2, xEnd, BaselineY + BodyWidth / 2), points)
                {
                    Title = "John Smith",
                    Subject = "Polygon",
                    Color = Color.Blue,
                    InteriorColor = Color.BlueViolet,
                    Opacity = 0.25,
                    Popup = new PopupAnnotation(document.Pages[1], new Rectangle(842, 196, 1021, 338))
                };

                document.Pages[1].Annotations.Add(polygonAnnotation);
                document.Save(outputPath);

                Console.WriteLine($"Polygon annotation added and saved to: {outputPath}");
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"Error: {ex.Message}");
            }
        }
    }
}