You can use the PDFDebuger to look at the content stream of the original page 
and the cloned one stored in the xform object (which is in the resources of the 
target page).
The /Alt token should be in the properties of a BDC operator right before the 
actual text.
It should be in an inline dictionary, but for example pdfbox likes to create 
dicitonaries stored in the resources instead.
Maybe it isn't where it should be, or the dictionary resource went missing 
after cloning.
Shouldn't happen, though.

So maybe it's a whole different thing: Your original PDF uses a structure 
hierarchy. I have no idea if that is cloned over and not much of an idea of 
that beast altogether.
You will still see BDC operators but have something like << /MCID 0 >> as 
property.
You can also inspect that with the debugger in the Show Internal Structure 
view, the StructTreeRoot but it's kinda confusing (to my eyes).

gunnar

-----Ursprüngliche Nachricht-----
Von: Mark Gibson <[email protected]> 
Gesendet: Freitag, 9. April 2021 19:12
An: [email protected]
Betreff: LayerUtility and /Alt 

Hi

We're using the LayerUtility class to copy a page from one PDF in to a page in 
a different PDF.  Mostly, it has worked well up until now.  However, when 
checking ADA compliance, we noticed the alternative text is not copied over to 
the target PDF page.

I've tried two variations, but neither copy the Alternative text (/Alt token)

        PDFormXObject firstForm = layerUtility.importPageAsForm( fromDoc, 
fromPage );
        PDPage targetPage = targetDoc.getPage( targetPageIndex );
        AffineTransform af = new AffineTransform(  );
        layerUtility.wrapInSaveRestore( targetPage );
        layerUtility.appendFormAsLayer( targetPage, firstForm, af, "unique name 
generated here" );

and

        PDFormXObject firstForm = layerUtility.importPageAsForm( fromDoc, 
fromPage );
        PDPage targetPage = targetDoc.getPage( targetPageIndex );
        try( PDPageContentStream pdfDocPageContents = new PDPageContentStream( 
targetDoc, targetPage, AppendMode.PREPEND, true, false ); ) {
            pdfDocPageContents.drawForm( firstForm );
        }

My low-level PDF foo is very small, so currently am at a bit of a loss.

Can anyone make any suggestions?  Give me code examples of a working copy for 
/Alt?  Confirm that it's not possible?  Anything to help open my eyes.

Many thanks
Mark





Reply via email to