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();
pdfDocument.Pages.Add();
pdfDocument.Pages[1].Paragraphs.Add(new TextFragment(“Click Here to Get Attachment.”));
pdfDocument.Save(new MemoryStream());
TextFragmentAbsorber absorber = new TextFragmentAbsorber(“Click Here to Get Attachment.”);
pdfDocument.Pages[1].Accept(absorber);
foreach (TextFragment tf in absorber.TextFragments)
{
    FileSpecification fs = new FileSpecification(dataDir + “target.pdf”, “This is attachment.”);
    FileAttachmentAnnotation file = new FileAttachmentAnnotation(tf.Page, new Aspose.Pdf.Rectangle(40, 800, 60, 820), fs);
    file.Color = Color.Transparent;
    file.Hyperlink = new FileHyperlink(dataDir + “target.pdf”);
    file.Contents = “This is Attachment.”;
    file.Icon = FileIcon.Paperclip;
    tf.Page.Annotations.Add(file);

    LinkAnnotation link = new LinkAnnotation(tf.Page, tf.Rectangle);
    link.Action = new GoToRemoteAction(dataDir + “target.pdf”, 1);
    tf.Page.Annotations.Add(link);
}
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