Skip to content

PDF conversion encodes & in hyperlinks as &, breaking URLs #703

@gbenm

Description

@gbenm

Hey there 👋, could you help me 🙏

Problem

When inserting a hyperlink into a Word template using XDocReport (Velocity) and converting it to PDF via XWPF, any & characters in the URL are automatically encoded as &, resulting in broken links in the generated PDF.

For example, a URL like:

https://www.google.com/search?q=ola&sclient=gws-wiz

The result in the PDF:

https://www.google.com/search?q=ola&sclient=gws-wiz

This causes the link to not function correctly when clicked from the PDF.

Example

InputStream input = new FileInputStream("template.docx");
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(input, TemplateEngineKind.Velocity);

IContext context = report.createContext();
context.put("url", "https://www.google.com/search?q=ola&sclient=gws-wiz");

Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF);
OutputStream output = new FileOutputStream("output.pdf");

report.convert(context, options, output);

The template:

Image

template.docx

Version

  • xdocreport 2.1.0
  • macos 15.5

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions