AsciiDoc: How can I place graphical hints on an image - pdf-generation

I am using AsciiDoc with Asciidoctor Gradle Plugin to generate technical documentation as PDF.
When I used M$ Word, I could easily place forms on an image, for example
colored rectangles,
boxes with numbers or
even links to sections within the document,
to better point out interesting areas within the image.
Example:
On the example image I have placed two rectangles and each one contains a link (starting with the word «Dialogbereich») leading to a other sections within the document.
Is it possible to achieve something like this (directly) in AsciiDoc?
Note that the answers to asciidoc: how to add callouts asciidoc to image do not apply here as the Asciidoctor PDF backend does not use DocBook to generate the PDF.
I know I could create a layered image in GIMP to at least place the rectangles. However, that wouldn't help me with the links.

Related

Why are images in pdf sometimes sliced into multiple images?

Noticed that images sometimes are sliced up in PDFs.
Steps:
insert an image with a high resoultion (3000x1800) into a .docx
use "Microsoft Print to PDF" option of Word to convert to PDF
extracting all images with pdfimages or pymupdf
Result:
Image is sliced horizontally into three images
Questions:
What exactly happens in the in the transition from .docx to pdf (or in generell in the process to pdf) that makes the converter slice it up into three images instead of one?
Do the individuell XObjects of the sliced images contain information which says that these three images belong to originally one?
How do I know how the images are sliced (horizontally / vertically) and what if originally there were two images inserted into the .docx file and both of them are sliced. Can you tell if slice x belongs to original image y or z?
So, as you have found out: because the code which generates the PDF choose to do so.
The technical reasons may be various - it could be that historically there were printers which would only have so much memory, and would need to get limiterd size-images when printing, and someone at some point when writing the PDF export code present in Microsoft Office choose to apply this limit.
Anyway, technically, as put in the comments, an image in a PDF file could be composed of unlimited smaller images collated together.
Now, the second part, and your actual question: to know whether images ibn a PDF file belong together in a single original image one would need a custom extractor tool to check the geometry of all images in the document and find out which images have no margins or boundaries with others - it would not be that hard to do for well behaved files (which we can't know if MS Office generated files are: there are ways to obfuscate image positioning by making it indirectly). The metadata in the image-parts may or may not contain information that would allow one to recompose the original image: it would be up to the code generating the PDF to include this metadata or not - but the geometry can't lie in this case: if the final document presents a single image visually, it is possible to detect that when fetching the images.

Does AsciiDoc support layers or text on images?

I'm making a poster (sort of) and would like to do these things, but I'm not sure if AsciiDoc or AsciiDoctor can do them, and if so, how:
Background image that can be stretched to the poster's dimensions
A rectangle with some transparency and a border, basically a bright frame, with text in it.
An image with text in it.
Text inside an image inside a rectangle.
(Bonus question: Is it possible to free-form specify where something goes, e.g. x=80%, y = 20% for something in the top right corner?)
I'm not sure that it makes sense to use AsciiDoc to source poster output, as opposed to a desktop publishing tool or a graphics program.
But if you are converting to HTML, you should be able to accomplish most of this with clever sourcing and some CSS/JavaScript on the front end. That is, you can source some of the metadata you want to impose on the final image, then have front-end code do the manipulation and imposition. For instance, you can provide a caption, classes, a title, and other info in the source, but AsciiDoc is intentionally agnostic about how that stuff is handled in output.
However, unless you need to create these things as part of technical documents, especially ones getting built/generated recuringly with automation, you're likely better off with a specialized tool.

Extract Images and their Labels from PDFs

I am facing a problem extracting images with their labels (not metadata!) from pdf files. By label I mean the text that is assigned to the image to describe it regeardless of it's possition, underneath or above. I've tried alot of known parsers, such as iText, Tika, PDFbox and pdf2html but i found no way of how to do this. Any suggestions?

Unit of measure for image dimensions in AsciiDoc/AsciiDoctor documents

There is no indication neither in the docs nor on first three pages of Google search results about what is the unit of measure of the images in AsciiDoc documents. This is significant topic, because AsciiDoc converts both to HTML (native unit is pixel) and to PDF (native unit is either cm or pt).
So, can someone answer and/or add a section to documentation about the following:
When I write image::path/to/image.png["Caption",300,200], what is those 300 and 200? Pixels?
When I produce a PDF from the AsciiDoc document, what DPI it uses, if we are using pixels? Can I control it in some configuration setting?
If those dimensions are in some abstract units, then, what is the widths of HTML and PDF pages in those units?
Is there any way to make output-agnostic AsciiDoc document with images? I don't want pixel-perfect identical layout in both formats, but it would be great to preserve the relative sizes of images at least.
I am using asciidoctor -b html for HTML output and asciidoctor-fopub for PDF. I will not use asciidoctor-pdf until it'll support at least the same feature set as fopub.
Thank you beforehand.
For html, it's pixels: https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/converter/html5.rb#L520-L523
For pdf, I'm not really sure, but it probably depends on Apache FOP, as that's what's being used. The xslt seems to indicate inches without any scaling. You'll have to dig into that whole mess to actually figure out what's being used and how to modify it.

Extract Images and Words with coordinates and sizes from PDF

I've read much about PDF extractions and libraries (as iText) but i just haven't found a solution to extract images and text (with coordinates) from a PDF.
The task is to scan PDF with catalog of products and extract each image. There is an image code printed next to each image and also a list of product codes for products that are shown on the image.
I know that there is no way to extract structured info from a PDF like this but with coordinates of all image and text objects I could write code to identify linked text by its distance from the image. Then I could split text using a RegExp and find out what is a product code, what is an image code etc.
Could you recommend a good and working solution for the task?
Use XPDF (http://www.foolabs.com/xpdf/)
It can extract all the characters in the PDF with co-ordinates (pdftotext -bbox [sourcefile] [outputfile]) and also all the images and SVGs in the PDF.
It's open source (GPLv2) and supports a lot of additional extraction functionalities as well.
Several Java libraries can do this. Have you looked at JPedal or PdfBox?
If a commercial library is an option for you, you could try Amyuni PDF Creator .Net or Amyuni PDF Creator ActiveX. You could use the method IacDocument.GetObjectsInRectangle to retrieve all the "graphic objects" of your interest, then use the ObjectType attribute to separate images from text. The library already provides an algorithm for putting close text together. From the documentation:
IacDocument.GetObjectsInRectangle Method
The GetObjectsInRectangle method gets all the objects that are in the specified rectangle.
Usual disclaimer applies.

Resources