How do I underline internal links in an existing PDF using IText7 and C#?

How do I underline internal links in an existing PDF using IText7 and C#?

Content Index :

I think the issue was by ths following , To the best of my knowledge what you are trying to achieve cannot be achieved by purely modifying the annotation objects. It might be possible to try playing with appearance streams but I'm not sure it will work and even if it will it can have some side effects.
Annotations just encode the rectangular area which becomes clickable and the action (or destination) that will be triggered when that area is clicked. It is also possible to configure the border of the annotation but PDF specification does not allow you to do fine-grained tuning and thus you won't be able to just set the bottom border to emulate the underlining.
PdfPage page = pdfDocument.getPage(i);
// Create canvas where we would draw additional lines
PdfCanvas pageCanvas = new PdfCanvas(page);
for (PdfAnnotation annotation : page.getAnnotations()) {
    Rectangle annotationArea = annotation.getRectangle().toRectangle();
    // Draw a line at the bottom of the annotation area
            moveTo(annotationArea.getLeft(), annotationArea.getBottom()).
            lineTo(annotationArea.getRight(), annotationArea.getBottom()).

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to add u3d into existing pdf using itext7 with C#

Tag : chash , By : Lathentar
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The Linked example is for iText5, not iText7. In iText7 this example would look like this
  public static final String DEST = "./target/test/resources/book/part4/chapter16/Listing_16_16_Pdf3D.pdf";
    public static String RESOURCE = "./src/test/resources/img/teapot.u3d";

    public static void main(String args[]) throws Exception {
        new Listing_16_16_Pdf3D().manipulatePdf(DEST);

    public void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));

        Document doc = new Document(pdfDoc);
        Rectangle rect = new Rectangle(100, 400, 400, 400);

        PdfStream stream3D = new PdfStream(pdfDoc, new FileInputStream(RESOURCE));
        stream3D.put(PdfName.Type, new PdfName("3D"));
        stream3D.put(PdfName.Subtype, new PdfName("U3D"));

        PdfDictionary dict3D = new PdfDictionary();
        dict3D.put(PdfName.Type, new PdfName("3DView"));
        dict3D.put(new PdfName("XN"), new PdfString("Default"));
        dict3D.put(new PdfName("IN"), new PdfString("Unnamed"));
        dict3D.put(new PdfName("MS"), PdfName.M);
        dict3D.put(new PdfName("C2W"),
                new PdfArray(new float[]{1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28}));
        dict3D.put(PdfName.CO, new PdfNumber(235));

        Pdf3DAnnotation annot = new Pdf3DAnnotation(rect, stream3D);
        annot.setContents(new PdfString("3D Model"));
    public void manipulatePdf(String dest) {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));

        Document doc = new Document(pdfDoc);
        Rectangle rect = new Rectangle(100, 400, 400, 400);

        PdfStream stream3D = new PdfStream(pdfDoc, new FileInputStream(RESOURCE));
        stream3D.Put(PdfName.Type, new PdfName("3D"));
        stream3D.Put(PdfName.Subtype, new PdfName("U3D"));

        PdfDictionary dict3D = new PdfDictionary();
        dict3D.Put(PdfName.Type, new PdfName("3DView"));
        dict3D.Put(new PdfName("XN"), new PdfString("Default"));
        dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
        dict3D.Put(new PdfName("MS"), PdfName.M);
        dict3D.Put(new PdfName("C2W"),
                new PdfArray(new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }));
        dict3D.Put(PdfName.CO, new PdfNumber(235));

        Pdf3DAnnotation annot = new Pdf3DAnnotation(rect, stream3D);
        annot.SetContents(new PdfString("3D Model"));

itext7 - adding content from existing PDF to a new one

Tag : java , By : HokieGeek
Date : March 29 2020, 07:55 AM
To fix the issue you can do To stamp your template page origPage onto the current first page of pdf instead of a new one, simply replace
PdfPage page = pdf.addNewPage(1, PageSize.A4);
PdfPage page = pdf.getPage(1);

Get all metadata from an existing PDF using iText7

Tag : chash , By : user147496
Date : March 29 2020, 07:55 AM
This might help you In iText 7 the PdfDocumentInfo class unfortunately does not expose a method to retrieve the keys in the underlying dictionary.
But you can simply retrieve the Info dictionary contents by immediately accessing that dictionary from the trailer dictionary. E.g. for a PdfDocument pdfDocument:
PdfDictionary infoDictionary = pdfDocument.GetTrailer().GetAsDictionary(PdfName.Info);
foreach (PdfName key in infoDictionary.KeySet())
    Console.WriteLine($"{key}: {infoDictionary.GetAsString(key)}");

How to write text under underline in itext7

Tag : pdf , By : hlpimfalling
Date : March 29 2020, 07:55 AM
wish of those help This is fairly easy to implement using text rise setting which is a standard setting in PDF. Below is a brief code sample:
Paragraph p = new Paragraph();
p.add("The beginning of the line ");
p.add(new Text("          (fill in your name)          ").setTextRise(-10).setUnderline().setFontSize(8));
p.add(" end of the line");

Add an image to an existing PDF file with iText7

Tag : chash , By : Tetting
Date : March 29 2020, 07:55 AM
wish helps you In iText7, there is no PdfStamper anymore. PdfDocument is responsible for modifying the contents of the document.
To add an image to a page, the easiest way is to use Document class from layout module. With that you almost don't have to care about anything.
// Modify PDF located at "source" and save to "target"
PdfDocument pdfDocument = new PdfDocument(new PdfReader(source), new PdfWriter(target));
// Document to add layout elements: paragraphs, images etc
Document document = new Document(pdfDocument);

// Load image from disk
ImageData imageData = ImageDataFactory.Create(imageSource);
// Create layout image object and provide parameters. Page number = 1
Image image = new Image(imageData).ScaleAbsolute(100, 200).SetFixedPosition(1, 25, 25);
// This adds the image to the page

// Don't forget to close the document.
// When you use Document, you should close it rather than PdfDocument instance
Related Posts Related QUESTIONS :
  • When do Request.Params and Request.Form differ?
  • The imported project "C:\Microsoft.CSharp.targets" was not found
  • Numeric Data Entry in WPF
  • Print a Winform/visual element
  • C# logic order and compiler behavior
  • When to use an extension method with lambda over LINQtoObjects to filter a collection?
  • How to make a button appear as if it is pressed?
  • C# and Arrow Keys
  • How do you resolve a domain name to an IP address with .NET/C#?
  • Should the folders in a solution match the namespace?
  • How can I evaluate C# code dynamically?
  • CSharpCodeProvider Compilation Performance
  • How can I create Prototype Methods (like JavaScript) in C#.Net?
  • DataTable Loop Performance Comparison
  • CSV string handling
  • What is the best way to do unit testing for ASP.NET 2.0 web pages?
  • High availability
  • What to use for Messaging with C#
  • Accessing a Dictionary.Keys Key through a numeric index
  • ConfigurationManager.AppSettings Performance Concerns
  • What Are Some Good .NET Profilers?
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com