You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Mark Gibson <ma...@staff.bluematrix.com> on 2021/04/09 17:12:16 UTC

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






RE: LayerUtility and /Alt

Posted by Mark Gibson <ma...@staff.bluematrix.com>.
Thanks for your response Gunnar

I spent most of Friday with PDFDebugger and various other tools.  It looks like the Alt text is stored in an object in the structure hierarchy (StructTreeRoot).

Would anyone more familiar with PDF specs and PDFBox be able to tell me if there's any features of LayerUtility, or other utilities that include the associated structure elements when copying the content?  Or be able to give me some guidance on how to selectively pick the correct structure elements associated with each piece of content and then rebuild them in the target document?

Thanks
Mark

-----Original Message-----
From: Gunnar Brand <Gu...@interface-projects.de> 
Sent: 09 April 2021 19:03
To: users@pdfbox.apache.org
Subject: AW: LayerUtility and /Alt 

[EXTERNAL]

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 <ma...@staff.bluematrix.com>
Gesendet: Freitag, 9. April 2021 19:12
An: users@pdfbox.apache.org
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





B�KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKCB��[��X��ܚX�KK[XZ[
�\�\��][��X��ܚX�P��� �\X�K�ܙ�B��܈Y][ۘ[��[X[��K[XZ[
�\�\��Z[��� �\X�K�ܙ�B�

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: LayerUtility and /Alt

Posted by Mark Gibson <ma...@staff.bluematrix.com>.

-----Original Message-----
From: Gunnar Brand <Gu...@interface-projects.de> 
Sent: 09 April 2021 19:03
To: users@pdfbox.apache.org
Subject: AW: LayerUtility and /Alt 

[EXTERNAL]

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 <ma...@staff.bluematrix.com>
Gesendet: Freitag, 9. April 2021 19:12
An: users@pdfbox.apache.org
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





B�KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKCB��[��X��ܚX�KK[XZ[
�\�\��][��X��ܚX�P��� �\X�K�ܙ�B��܈Y][ۘ[��[X[��K[XZ[
�\�\��Z[��� �\X�K�ܙ�B�

AW: LayerUtility and /Alt

Posted by Gunnar Brand <Gu...@interface-projects.de>.
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 <ma...@staff.bluematrix.com> 
Gesendet: Freitag, 9. April 2021 19:12
An: users@pdfbox.apache.org
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