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