Attachments (pdf- doc- xla- ppt...) in PDF

I can insert the Attachments (pdf, doc, xls, ppt…)

into a word doc then I can open these attachments.



If I save it as pdf format then I CAN’T open these attachments any more.



Can Aspose pdf provide me this capability?

Hi there,


Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does.

Could you please share your output Pdf and expected output Pdf here for our reference? We will then provide you more information about your query.

Here’s my output

Hi there,


Thanks for sharing the output Pdf. Please also share your expected output Pdf here for our reference.

Please note that Aspose.Words mimics the same behavior as MS Word does. If you insert the OLE object in document and save it to Pdf using MS Word, you will get the same output.

DocumentBuilder.InsertOleObject returns Shape’s object. You can use Shape.HRef property to set the full hyperlink address for a shape. E.g. full file name: C:\My Documents\SalesReport.doc. However, the document will not open in respective editor.
TECHS:
Can Aspose pdf provide me this capability?
My colleagues from Aspose.Pdf team will reply you shortly about this query.

Please confirm that the attachments can’t be opened in pdf format?

Hi,


Adding more to previous responses, please note that Aspose.Pdf for .NET offers the feature to Add Attachment to PDF and it also offers the feature to Get All Attachments from a PDF Document. However the earlier shared document generated with Aspose.Words has some issues because attachments are not properly rendered in resultant PDF file and they appear to be broken. Once the problem is resolved, you may try using Aspose.Pdf to extract attachments from PDF file.

I got the example codes from your link but nothing happened. Did I miss anything?





Dim MyDir As String = “C:\VS2012”

'Dim pdfDocument As New Document(dataDir & Convert.ToString(“AddAttachment.pdf”))

Dim pdfDocument As New Aspose.Pdf.Document(MyDir + “inFilePDF.pdf”)

Dim fileSpecification As New FileSpecification(MyDir & Convert.ToString(“MyTextFile.txt”), “Sample text file”)

’ Specify Encoding proparty setting it to FileEncoding.None

fileSpecification.Encoding = FileEncoding.None

'If Encoding is set to FileEncoding.None, then attachment is not compressed. The default encoding is FileEncoding.Zip.



pdfDocument.EmbeddedFiles.Add(fileSpecification)

Dim dataDir As String = “C:\VS2012\outFilePDF.pdf”

’ Save the document to disk.

pdfDocument.Save(dataDir)

Hi,

Thanks for sharing the details.

I have tested the scenario using following code snippet and I am unable to notice any issue. As per my observations, the attachment is properly being added to PDF file.

VB.NET Code:

Dim MyDir As String = "C:\pdftest"
'Dim pdfDocument As New Document(dataDir & Convert.ToString("AddAttachment.pdf"))
Dim pdfDocument As New Aspose.Pdf.Document(MyDir + "Table_in_pdf.pdf")
Dim fileSpecification As New FileSpecification(MyDir & Convert.ToString("AsposeTestThreadOld.txt"), "Sample text file")

' Specify Encoding proparty setting it to FileEncoding.None
fileSpecification.Encoding = FileEncoding.None

'If Encoding is set to FileEncoding.None, then attachment is not compressed. The default encoding is FileEncoding.Zip.
pdfDocument.EmbeddedFiles.Add(fileSpecification)

Dim dataDir As String = "C:\pdftest\outFilePDF.pdf"

' Save the document to disk.
pdfDocument.Save(dataDir)

Dim pdfDocument As New Aspose.Pdf.Document(“C:\VS2012\BlankPDF.pdf”)

Dim fileSpecification As New FileSpecification(Convert.ToString(“C:\VS2012\inFileTXT.txt”), “Sample text file”)

fileSpecification.Encoding = FileEncoding.None

pdfDocument.EmbeddedFiles.Add(fileSpecification)

Dim dataDir As String = “C:\VS2012\outFilePDF.pdf”

pdfDocument.Save(dataDir)



Attached are the input files and output file used in this test. Nothing happened.

Hi Dzung,


Thanks for sharing the resource files.

As per my understanding, the PDF file shared earlier has attachment and when we double click it, the TXT file is displayed in notepad. Please take a look over attached image.

Thanks for letting me know I’m supposed to click on the paper clip.

I was looking for the icon in the pdf body.

I had this dilemma: in the old Aspose word version, I need to create word doc then convert to XML them pdf.

I already had extensive word process to create a form using Aspose word. but I now must use Aspose pdf to insert attachments pdf,doc,xls…) into pdf. I can’t attach attachments Aspose.pdf.document to Aspose.word.document.

It’ll require me to rewrite entire process to format a form using Aspose pdf.

Any way I can convert the word doc to pdf and still open attachments from pdf?

Any help how to solve this problem?

Hi Dzung,

Thanks for sharing the details.

In order to accomplish this requirement, you need to try using FileAttachmentAnnotation object. Please take a look over following code snippet to accomplish this requirement.

C# Code

// Open the PDF document
Document doc = new Document();
doc.Pages.Add();

// Get reference of the page to which you need to add the annotation
Page page = doc.Pages[1];

// Create ScreenAnnotation object with .swf multimedia file as an argument
Aspose.Pdf.Annotations.FileAttachmentAnnotation annotation = new Aspose.Pdf.Annotations.FileAttachmentAnnotation(page, new Aspose.Pdf.Rectangle(100, 100, 120, 120), new FileSpecification("c:/pdftest/Sample.pdf"));
annotation.Icon = Aspose.Pdf.Annotations.FileIcon.Paperclip;

// Add the annotation to annotations collection of page
page.Annotations.Add(annotation);

doc.Save(“c:/pdftest/FileAttachmentAnnotation.pdf”);
Hi Dzung,

Thanks for your inquiry.
TECHS:
in the old Aspose word version, I need to create word doc then convert to XML them pdf. I already had extensive word process to create a form using Aspose word.
You are using older version of Aspose.Words that does not convert Word document to Pdf directly.

We have logged a feature request as WORDSNET-14001 to export OLE as attachment and link OLE icon to it in output Pdf. Our product team will look into the possibility of implementation of this feature. Once we have any information about this feature, we will update you via this forum thread.

However, you can add attachments in pdf file and link an image/icon to attachment using Aspose.Pdf. Please check code examples shared in this forum thread.

Please provide me the example for VB codes.
Thanks

Hi Dzung,

Please try using following code snippet.

VB.NET code

' Open the PDF document
Dim doc As Aspose.Pdf.Document = New Aspose.Pdf.Document()
doc.Pages.Add()

' Get reference of the page to which you need to add the annotation
Dim Page As Page = doc.Pages(1)

' Create ScreenAnnotation object with .swf multimedia file as an argument
Dim annotation As Aspose.Pdf.Annotations.FileAttachmentAnnotation = New Aspose.Pdf.Annotations.FileAttachmentAnnotation(Page, New Aspose.Pdf.Rectangle(100, 100, 120, 120), New FileSpecification("c:/pdftest/Sample.pdf"))
annotation.Icon = Aspose.Pdf.Annotations.FileIcon.Paperclip

' Add the annotation to annotations collection of page
Page.Annotations.Add(annotation)

doc.Save("c:/pdftest/FileAttachmentAnnotation.pdf")

I create a word doc including multiple sections. Each section has bookmarks. If users want to save as pdf then it’ll save doc to pdf format.





if I insert attachments into this word doc then convert it to psf later, I can no longer open these attachments in pdf.





I want to read this pdf file, look up the bookmark then insert attachments at these bookmarks. the attachments can be different types such as doc, docx, xls, xlsx, ppt, ppt, pptx, rtf, msg, mpg…



Please advise if aspose pdf can do this.



thanks

In order to accomplish above stated requirement, please open PDF document, try Getting a Bookmark’s Page Number and then try using following code snippet to add FileAttachment on specific page of PDF file.

[C#]

// Instantiate PDF document
Document doc = new Document();
// add page to pages collection of PDF file
doc.Pages.Add();
// Get reference of the page to which you need to add the annotation
Page page = doc.Pages[1];
// Create ScreenAnnotation object with .swf multimedia file as an argument
Aspose.Pdf.Annotations.FileAttachmentAnnotation annotation = new Aspose.Pdf.Annotations.FileAttachmentAnnotation(page, new Aspose.Pdf.Rectangle(0, 400, 600, 700), new FileSpecification("c:/pdftest/C8_1FormProcessPDF.pdf"));
// Add the annotation to annotations collection of page
page.Annotations.Add(annotation);
// Save the update PDF document with annotation
doc.Save("c:/pdftest/WithAttachment.pdf");

I got this error ‘This is not a structured file’ while inserting PPT attachment using Aspose words :





If fileExtension = “PPT” Then

progid = “PowerPoint.Show.8”

Else

progid = “PowerPoint.Show.12”

End If



Using stream As New MemoryStream(File.ReadAllBytes(filePathName))

docBuilder.InsertOleObject(stream, progid, True, Nothing)

End Using

Hi Dzung,

Thanks for your inquiry. Could you please attach your input Word document along with PPT/PPTX file here for testing? We will investigate the issue on our side and provide you more information.