Add alternative text for an image in Tagged PDF in C#

一个人想着一个人 提交于 2019-12-25 09:44:40

问题


I need your help with this:

public void manipulatePdf(String src, String dest)
    throws IOException, DocumentException {
    PdfReader reader = new PdfReader(src);
    PdfDictionary catalog = reader.getCatalog();
    PdfDictionary structTreeRoot =
        catalog.getAsDict(PdfName.STRUCTTREEROOT);
    manipulate(structTreeRoot);
    PdfStamper stamper = new PdfStamper(
        reader, new FileOutputStream(dest));
    stamper.close();
}

public void manipulate(PdfDictionary element) {
    if (element == null)
        return;
    if (PdfName.FIGURE.equals(element.get(PdfName.S))) {
        element.put(PdfName.ALT,
            new PdfString("Figure without an Alt description"));
    }
    PdfArray kids = element.getAsArray(PdfName.K);
    if (kids == null) return;
    for (int i = 0; i < kids.size(); i++)
        manipulate(kids.getAsDict(i));
}

I can port this Java example to C#:

Get the root dictionary from the PdfReader object, Get the root of the structure tree (a dictionary), Loop over all the kids of every branch of that tree, When a lead is a figure, add an /Alt entry. Once this is done, use PdfStamper to save the altered file.

But how could I do it?

Could you help me please?

Thank's!

来源:https://stackoverflow.com/questions/43938326/add-alternative-text-for-an-image-in-tagged-pdf-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!