We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word document with a hyperlink with base64 encoded parameter was decoded when convert to PDF

Hi,

I have a Word file (docx) with hyperlink routed to web site using a base64 parameter with url encode applied "http://localhost/d/Gf%2b8ZCEb0M9ME24RAYOz8A%3d%3d", but when the Word file is saved as PDF format only the hyperlink in the PDF file change to "http://localhost/d/Gf+8ZCEb0M9ME24RAYOz8A==".

Either using Aspose.Word or manually with Microsoft Word, later when converting to PDF the encoding of the url is lost.
Is it necessary to pass options when saving as PDF to avoid decoding the encoded URL?

Code for save as PDF:

private string ToPdf(string filepath)
{
	var doc = filepath.ToWord(); //return Aspose.Words.Document;

	doc.Save($"{Guid.NewGuid().ToString()}.pdf", SaveFormat.Pdf);
}

As a reference I include this code:

public class ReplacingHyperlinkCallback : IReplacingCallback
{
	string text;
	string hyperlink;

	public ReplacingHyperlinkCallback(string text, string hyperlink)
	{
		this.text = text;
		this.hyperlink = hyperlink;
	}

	public ReplaceAction Replacing(ReplacingArgs args)
	{
		var node = args.MatchNode;

		DocumentBuilder builder = new DocumentBuilder(node.Document as Document);

		builder.MoveTo(node);
		builder.Font.Color = Color.Blue;
		builder.InsertHyperlink(text, hyperlink, false);

		return ReplaceAction.Skip;
	}
}

private void ReplaceToHyperlink(string wordpath, string tagname, string hyperlink)
{
	var doc = wordpath.ToWord();
	var pattern = $@"({tagname})";
	var options = RegexOptions.IgnoreCase | RegexOptions.Singleline;

	foreach (Section section in doc.Sections)
	{
		foreach (Node bodyNode in section.Body)
		{
			Paragraph paragraph = (bodyNode.NodeType == NodeType.Paragraph) ? (Paragraph)bodyNode : null;

			if (paragraph != null)
			{
				var paraText = paragraph.GetText();

				var match = Regex.Match(paraText, pattern, options);
				if (match.Success)
				{
					doc.Range.Replace(new Regex(pattern), new ReplacingHypelinkCallback(hyperlink, hyperlink), false);
					doc.Range.Replace(new Regex(pattern), "");
				}
			}
		}
	}

	doc.Save(wordpath);
}

Thanks and regards.
Francisco

@fpereiracalvo

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Hi, Thanks for answering.

I uploading a zip file with two word documents for both cases.

QrPage.zip (17.5 KB)

@fpereiracalvo

Thanks for sharing the detail. Please use PdfSaveOptions.EscapeUri property as shown below to get the desired output.

Document doc = new Document(MyDir + @"QrPage2.docx");
PdfSaveOptions options = new PdfSaveOptions();
options.EscapeUri = false;
doc.Save(MyDir + "18.8.pdf", options);