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

Free Support Forum - aspose.com

Convert (ReferenceParagraphID /PositioningType.ParagraphRelative) from old Aspose.Pdf.Generator to Aspose.Pdf

I’m trying to get the same result in the new Aspose.pdf







private void AddAttachment(Section sec1) {



List pdfatt = PdfData.GetPdfAttachement(Session[“RapportID”].ToString());



foreach (PdfAttachment att in pdfatt)

{



Aspose.Pdf.Generator.Attachment fileAttachmentList = new Aspose.Pdf.Generator.Attachment();

sec1.Paragraphs.Add(fileAttachmentList);

fileAttachmentList.AttachmentType = Aspose.Pdf.Generator.AttachmentType.File;

fileAttachmentList.AttachedStream = PdfData.OpenDocument(att.Documentid);

fileAttachmentList.AttachedFileName = att.Name;

fileAttachmentList.AttachedFileType = att.Extention;

fileAttachmentList.FileIconType = Aspose.Pdf.Generator.FileIconType.PaperClip;

fileAttachmentList.ID = att.Documentid.ToString();



Aspose.Pdf.Generator.Text attName = new Aspose.Pdf.Generator.Text(sec1, att.Name);



//Add the text paragraph to paragraphs collection of the section

sec1.Paragraphs.Add(attName);

attName.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;

attName.Left = 15;

attName.Top = 0;

attName.ReferenceParagraphID = att.Documentid.ToString();





}

}

Hello Jorn,


Thanks for posting your inquiry.

By looking at your code, it seems that you want to add text with a link to embedded file(s) in a PDF document. We have tried following code snippet to achieve the purpose but we did not get much success, as link was not referencing to embedded file but external one.

We have logged a feature request as PDFNET-40886 in our issue tracking system for the requirement and as soon as we have some feedback from product team, we will definitely inform you. Please be patient and spare us little time.


Document pdfDocument = new Document();<o:p></o:p>

pdfDocument.Pages.Add();<o:p></o:p>

pdfDocument.Pages[1].Paragraphs.Add(new TextFragment(“Click Here to Get Attachment.”));<o:p></o:p>

pdfDocument.Save(new MemoryStream());<o:p></o:p>

TextFragmentAbsorber absorber = new TextFragmentAbsorber(“Click Here to Get Attachment.”);<o:p></o:p>

pdfDocument.Pages[1].Accept(absorber);<o:p></o:p>

foreach(TextFragment tf in absorber.TextFragments)<o:p></o:p>

{<o:p></o:p>

FileSpecification fs = new FileSpecification(dataDir + “target.pdf”, “This is attachment.”);<o:p></o:p>

FileAttachmentAnnotation file = new FileAttachmentAnnotation(tf.Page, new Aspose.Pdf.Rectangle(40, 800, 60, 820), fs);<o:p></o:p>

file.Color = Color.Transparent;<o:p></o:p>

file.Hyperlink = new FileHyperlink(dataDir + “target.pdf”);<o:p></o:p>

file.Contents = “This is Attachment.”;<o:p></o:p>

file.Icon = FileIcon.Paperclip;<o:p></o:p>

tf.Page.Annotations.Add(file);<o:p></o:p>

LinkAnnotation link = new LinkAnnotation(tf.Page, tf.Rectangle);<o:p></o:p>

link.Action = new GoToRemoteAction(dataDir + “target.pdf”, 1);<o:p></o:p>

tf.Page.Annotations.Add(link);<o:p></o:p>

}<o:p></o:p>

pdfDocument.Save(dataDir + “output.pdf”);



We are sorry for the inconvenience.


Best Regards,

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan