Hyperlink as hidden text

hello

i would like to achieve the following (using document with mergefields):

show a hyperlink in the PDF display, but hide when PDF is printed.

is this possible?

can this be done by setting the formatting of the mergefield to hidden, and then adding the hyperlink via movetomergefield + inserthyperlink? it seems the formatting is lost, when the hyperlink is added…

thanks for your response…

best regards,
alex

Hi Alex,

Thanks for your query. Please use the following code snippet to insert hyperlink at mail merge field.

<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>PL</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:10.0pt; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:47.9pt; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

Document doc = new Document(DirDoc + "in.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

//move to the Merge Field and insert hyperlink

builder.MoveToMergeField("Link");

builder.Font.StyleIdentifier = StyleIdentifier.Hyperlink;

builder.InsertHyperlink("Google", "www.google.com", false);

doc.Save(DirDoc + "AsposeOut.docx");



It would be great if you please share some more information about your following question.

show a hyperlink in the PDF display, but hide when PDF is printed.

hi tahir

thanks for your response.

i would like for the hyperlink to be visible, when the user opens the PDF
in his PDF viewer or browser, so that he can navigate from there.

however it would be great if these hyperlinks would not appear on the
printed version of the PDF (physically on paper), as it only disrupts the
layout and the links can not be used anyway on paper…

thanks for a feedback on this!

best regards,
alex

Hi Alex,

Thanks for sharing the information. You can remove all hyperlinks from document before printing the document. Please use the following code snippet.

<span style=“font-family: “Courier New”; color: rgb(43, 145, 175);” lang=“EN-GB”>Document<span style=“font-family: “Courier New”;” lang=“EN-GB”> doc = new
Document(DirDoc + “in.docx”);<o:p></o:p>

NodeCollection fields = doc.GetChildNodes(NodeType.FieldStart, true);

foreach (FieldStart start in fields)

{

if (start.FieldType == Aspose.Words.Fields.FieldType.FieldHyperlink)

start.ParentNode.Remove();

}

doc.Print();



Please let us know if you have any more queries.

hello tahir

thanks for your reply.

actually the idea is, that we send the PDF file to our customer, and when
he opens it he sees the hyperlinks.

however when the customer prints the PDF, the hyperlinks should not
be printed.

at this point of action there is no code running, so i suppose the hyperlinks
should have some property “do not print” in the PDF file. is that possible?

best regards
alex

Hi Alex,

Thanks for sharing the information. Aspose.Words mimics the same behavior as MS Words do. You can not avoid printing the links inside PDF by using Aspose.Words.

You may achieve your requirement by using Aspose.Pdf. I am moving this thread to Aspose.Pdf forum and my colleagues will reply you shortly.

Hi Alex,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I am afraid, Aspose.Pdf for .NET does not support such a feature at the moment. I have requested the development team to look into this feature and let us know if such a feature can be support. I have created an issue in our issue tracking system with issue id: PDFNEWNET-34037. We will notify you via this forum thread regarding any updates or feedback from the development team.

Sorry for the inconvenience,

@xss

Thanks for your patience.

After further investigation of earlier logged issue, we have concluded that you cannot make non-printable common text in PDF. Instead, you can make non-printable annotation of any kind in the PDF document. We recommend you to use WatermarkAnnotation for creating non-printable text and LinkAnnotation for creating hyperlink.

Please consider the following code:

Document doc = new Document();
Page page = doc.Pages.Add();

page.Paragraphs.Add(new TextFragment("Hello world"));

FormattedText ft = new FormattedText("Hyperlink", System.Drawing.Color.Blue, System.Drawing.Color.Transparent);

WatermarkAnnotation watermark = new WatermarkAnnotation(page, new Rectangle(100, 650, 200, 670));
watermark.SetText(ft);
watermark.Flags &= ~AnnotationFlags.Print;

LinkAnnotation linkAnnotation = new LinkAnnotation(page, new Rectangle(100, 650, 200, 670));
linkAnnotation.Action = new GoToURIAction("https://www.aspose.com");
linkAnnotation.Border = new Border(linkAnnotation);
linkAnnotation.Border.Width = 0;

page.Annotations.Add(watermark);
page.Annotations.Add(linkAnnotation);

doc.Save(myDir + "Hyperlink_sample.pdf");

For your reference, we have also attached the output PDF document and its print output.

Hyperlink_sample.pdf (2.6 KB)
Hyperlink_sample.zip (6.5 KB)

For more information regarding Annotations, you may please visit “Working with Annotations” article(s) in our API documentation. In case of any further assistance, please feel free to let us know.