Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

vb.net to highlight PDF without editing the contents

Community Beginner ,
Mar 23, 2023 Mar 23, 2023

When working with developing applications using vb.net to highlight pdf , I tried Adobe Acrobat SDK . 

I found out that there are two ways which I could highlight pdf. I could either copy my document to another document and highlight that document (using Page.CreatePageHilite, non-javascript) OR I could manipulate using javascript objects.

 

My priority is to preserve the integrity of the contents of the PDF i.e. ensure that the contents in the PDF are none editable but could be highlighted only. 

 

May I check with you all which  method is preferable - using javascript OR using the copy method and highlighting on the copied version (using Page.CreatePageHilite) (non-javascript).

 

Thank you very much for the help. 

TOPICS
Acrobat SDK and JavaScript , Windows
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2023 Mar 23, 2023

It makes no difference at all to the PDF.  However, the JS/VB boundary is an extra layer. It's adds inefficiency  and can be problematic, so if you don't need to use JS, then don't. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 24, 2023 Mar 24, 2023

Createpagehite doesn't edit the PDF. It is equivalent to selecting text. It doesn't save with the document, and disappears if the user selects text. Is that what you want? Despite the "hilite" name it is not what I normally think of as a highlight. In PDF, highlights are actual marks, which edit the file, and are saved with it. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 24, 2023 Mar 24, 2023

I want to highlight and make actual marks on the PDF File. Is it possible to do it without javascript objects? I read the acrobat adobe sdk documentation and they provided a code for highlighting using C#/C++ (I guess from the code syntax). Is it possible to do it using visual basic? Thanks for the reply. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2023 Mar 24, 2023

Sounds like you'll need a Highlight annotation, which is saved with the PDF. To do this the VB script will need to use the JSO(JavaScript Object) to perform this task in JavaScript.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 25, 2023 Mar 25, 2023

There is a contradiction, though. Adding annotations is surely editing the PDF. I don't see how you can combine "PDF is not edited" with "I add annotations (highlights) to the PDF". If you narrow the definition of "PDF is not edited" to "PDF text contents are not changed" it's OK.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 26, 2023 Mar 26, 2023

You are right. I should have narrowed the definition to "PDF text contents are not changed". Thank you for the reply. 🙂 Sorry for the mistake. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 26, 2023 Mar 26, 2023

Thank you very much for the reply. I will try out JavaScript object instead. 🙂 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 26, 2023 Mar 26, 2023

Hi Thom, I have tried to add annots using the code given in the documentation. 

However, with the following code: 

this.addAnnot({
page: 0,
type: "Highlight",
rect: "72.02400207519531,767.760009765625,158.48907470703125,767.760009765625",
name: "hts123",
author: "hts123",
contents: "This section needs revision"
});

The highlighted part always appear at the bottom-left corner of the pdf no matter what values were changed in the rect. 

 

May I check with you how should I edit the code such that I could highlight the word that I want. 

E.g. I have found out that the quads belonging to the word which I want to highlight are : 

"72.02400207519531,767.760009765625,158.48907470703125,767.760009765625,72.02400207519531,756.719970703125,158.48907470703125,756.719970703125"

 

How should I go about changing it to the rect format such that it can highlight the word which I want to highlight? 

 

Thank you very much for your patience and reply. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 26, 2023 Mar 26, 2023

A quad and a text are not the same thing. A quad is any quadrilateral (four sided shape), not just a rectangle. A rect is a rectangle aligned with the aces (that is, rotated only 0:90/180/270 degrees). Let's suppose a page has an "M" at 45 degrees. The quad is a diamond. You cannot make a rect match it. The best you can do is put the smallest rectangle containing the diamond. To get the coordinates of the enclosing rect, take low x, low t and high x, high y. 

You have a more fundamental problem; your rect value must be an array, not a string. Eg not "1 2 3 4" but [1 2 3 4].

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 26, 2023 Mar 26, 2023
LATEST

The highlight appears at the wrong location partly the rectangle specification is in incorrect, but also, highlight annotations are not applied with a rectangle but with an array of quads. In fact, you can pass the quads for the word directly to addAnnot for applying the highlight. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines