PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 5:28 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Aug 18, 2023 3:52 pm 
Offline

Joined: Fri Aug 18, 2023 3:44 pm
Posts: 1
How to create pdf highlight annotation using pdfsharp

I have using the below code to create highlight annotation

Annotation created in pdf, but not displayed in Pdf page.

using PdfSharp.Pdf.Annotations;
using PdfSharp.Pdf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using PdfSharp.Drawing;

namespace PDFAnnotationExtension
{

public class PdfHighlightAnnotation : PdfMarkupAnnotation
{
public PdfHighlightAnnotation()
{
Initialize();
}

public PdfHighlightAnnotation(PdfDocument document)
: base(document)
{
Initialize();
}

void Initialize()
{
Elements.SetName(Keys.Subtype, "/Highlight");
}

}

public class PdfStrikeOutAnnotation : PdfMarkupAnnotation
{
public PdfStrikeOutAnnotation()
{
Initialize();
}

public PdfStrikeOutAnnotation(PdfDocument document)
: base(document)
{
Initialize();
}

void Initialize()
{
Elements.SetName(Keys.Subtype, "/StrikeOut");
}
}

public abstract class PdfMarkupAnnotation : PdfAnnotation
{
protected PdfMarkupAnnotation()
{ }

protected PdfMarkupAnnotation(PdfDocument document)
: base(document)
{ }

public IEnumerable<PdfRectangle> Quadrilaterals
{
set
{
var points = new PdfArray();
foreach (var r in value)
{
points.Elements.AddRange(ToQuadPoints(r));
}
Elements.SetValue("/QuadPoints", points);
}
}

private IEnumerable<PdfItem> ToQuadPoints(PdfRectangle r)
{
// Conversion from PdfRectangle coordinates
//
// Y ^
// | (X2 Y2)
// | +-----------+
// | | |
// | | |
// | +-----------+
// | (X1 Y1)
// |
// +----------------------------->
// X
// to QuadPoints coordinates (x1 y1 x2 y2 x3 y3 x4 y4)
//
// Y ^
// | (x4 y4) (x3 y3)
// | +-----------+
// | | |
// | | |
// | +-----------+
// | (x1 y1) (x2 y2)
// |
// +----------------------------->
// X
//
return new List<PdfItem> { new PdfReal(r.X1), new PdfReal(r.Y1),
new PdfReal(r.X2), new PdfReal(r.Y1),
new PdfReal(r.X1), new PdfReal(r.Y2),
new PdfReal(r.X2), new PdfReal(r.Y2)};
}

}

public static class ArrayElementsExtensions
{
public static void AddRange(this PdfArray.ArrayElements elements, IEnumerable<PdfItem> values)
{
foreach (var v in values)
{
elements.Add(v);
}
}
}
}


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 15, 2024 11:36 am 
Offline
User avatar

Joined: Thu Jul 21, 2022 10:52 am
Posts: 2
Hi,

Did you find a solution to your problem?
I would also like to use QuadPoints with LinkAnnotation.

_________________
Coragi
https://www.coragi.com


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 375 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group