Skip to main content
Participant
June 30, 2022
Answered

Adobe Acrobat Pro DC - zoomen/verschieben von eingefügtem Bild in Bildfeld - JavaScript

  • June 30, 2022
  • 2 replies
  • 966 views

Hallo,

gibt es die Möglichkeit ein Bild, das in einer fertigen PDF in einem Bildfeld eingefügt wird zu zoomen und verschieben?
Könnte man mit einem JavaScript die Funktion anpassen?
Code Beispiele (siehe unten) für Webbrowser habe ich im Internet gefunden aber ich bekomme sie in Adobe nicht zum laufen, da fehlt mir die Erfahrung.

Benötigt wird die Funktion, da eingefügte Bilder auf die jeweils längere Seite skaliert werden, dadurch können diese teils zu klein sein und der Inhalt wird nichtmehr erkannt.

 

Über Tipps wäre ich sehr dankbar!

 

Vielen Dank!

 

<style>
.active {
 cursor: move;
}

input[type="range"]#zoomer {
 width: 450px;
 vertical-align: middle;
}

div.scroll {
 width: 500px;
 height: 400px;
 overflow: hidden;
}

img#img {
 width: 500px;
 height: 400px;
 pointer-events: none;
 user-select: none;
}
</style>

<p>
  <label>Zoom: <input type="range" id="zoomer" value="1" min="1" max="2.5" step="0.01"></label>
</p>

<div class="scroll">
 <img src="m.jpg" id="img" alt="">
</div>

<script>
document.getElementById("zoomer").addEventListener("input", e => {
 var z = e.target.value;
 var img = document.getElementById("img");
 img.style.transform = " scale(" + z + ", " + z + ")";
 img.style.width = (z * 100) + "%";
 img.style.height = (z * 100 ) + "%";
});

const slider = document.querySelector(".scroll");
let isDown = false;
let startX;
let startY;
let scrolllLeft;
let scrolllTop;

slider.addEventListener("pointerdown", e => {
 if (document.getElementById("zoomer").value > 1) {
  isDown = true;
  slider.classList.add("active");
  startX = e.pageX - slider.offsetLeft;
  scrolllLeft = slider.scrollLeft;
  startY = e.pageY - slider.offsetTop;
  scrolllTop = slider.scrollTop;
 }
});

slider.addEventListener("pointerleave", () => {
 isDown = false;
 slider.classList.remove("active");
});

slider.addEventListener("pointerup", () => {
 isDown = false;
 slider.classList.remove("active");
});

slider.addEventListener("pointermove", e => {
 if (!isDown) return;
 e.preventDefault();
 var x = e.pageX - slider.offsetLeft;
 slider.scrollLeft = scrolllLeft - (x - startX);
 var y = e.pageY - slider.offsetTop;
 slider.scrollTop = scrolllTop - (y - startY);
});
</script>

 

This topic has been closed for replies.
Correct answer try67

The code you found is irrelevant to a script running in a PDF file.

You can't use a script to change the location of an image within an image field. You can only do that manually, through the Properties dialog.

What can be done with a script is to set the Scaling options of the field, through the following properties:

buttonFitBounds

buttonScaleHow

buttonScaleWhen

See the Acrobat JS API Reference for details on how to use them correctly.

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 4, 2022

The code you found is irrelevant to a script running in a PDF file.

You can't use a script to change the location of an image within an image field. You can only do that manually, through the Properties dialog.

What can be done with a script is to set the Scaling options of the field, through the following properties:

buttonFitBounds

buttonScaleHow

buttonScaleWhen

See the Acrobat JS API Reference for details on how to use them correctly.

Bernd Alheit
Community Expert
Community Expert
June 30, 2022

What properties does you use at the image field?

Gian213Author
Participant
July 1, 2022

Run JavaScript, if mouse button released.

 

event.target.buttonImportIcon();

 

You can choose and insert the image, but you can´t transform it.

Bernd Alheit
Community Expert
Community Expert
July 1, 2022

I mean this: