Free Support Forum - aspose.com

Attachment issue in PDF

Latest package looks much better. Thx for all your efforts.

Regarding the image problem (5th point), I just noticed image is getting rendered properly but right side of the image is going out of the coordinates. Please find the attached ( page number 3 ) for your reference.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

How to link/embed the attachment from PDF files. I tried the following code block but don’t see attachment in the pdf. Do we need to set any properties to get this done Or Am I missing anything? Can you give a try from your end & let me know the output.

//open document

Document pdfDocument = new Document("input.pdf");

//setup new file to be added as attachment

FileSpecification fileSpecification = new FileSpecification("test.txt", "Sample text file");

//add attachment to document's attachment collection

pdfDocument.EmbeddedFiles.Add(fileSpecification);

//save new output

pdfDocument.Save("output.pdf");

Please answer all the queries from this post as we are waiting for WORDSNET-7890

Hi Viswanathan,


Thanks for your inquiry. In reference to image rendering issue, Could you please share your sample code and source document here? So we test it and provide you more information accordingly.

Furthermore in reference to attachment issue. I’m unable to observe any issue, while using Aspose.Pdf for .NET 7.7.0. Please download and try latest Aspose.Pdf API. Hopefully your issue will be resolved. If issue persist then please share your sample output document for further investigation. Please also refer to following documentation for attachment feature details.


Please feel free to contact us for any further assistance.

Best Regards,

Point 1

Please find the attached pdf (HTMLImageDemo.pdf ) & image ( Picture-of-something.jpg) for your reference. Her is the code block

Aspose.Words.Document dd = new Aspose.Words.Document(@"c:\Template1.doc");

Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(dd);

//db.InsertImage( 'C:/TopHeading.jpg");

db.InsertHtml("");

dd.Save("c:\\HTMLImageDemo.pdf");

Point 2

Yes you are right here. I have replicated the similar result as you.

  • How do we opent the left side panel ( Index) when you open the pdf document. ( By default its close & I will have to click on the attachment button to open open up . ) Please advise.
  • We need to show the attachment something similar as attached in AttachmentDemo.doc file. We would like to show the file icon ( Plse see the attach word file ) as needed during the PDF generation at any given position . How do we get this using aspose.pdf?

Please answer all three points from this post .

Hi Viswanathan,


Thanks for providing additional information. In reference to point 2, Please check following code snippet for the purpose. As point 1 relates to Aspose.Words, so my colleague from Aspose.Words will answer you soon.


Document doc = new Document(“test.pdf”);
Page firstPage = doc.Pages[1];
FileSpecification fs = new FileSpecification(“test1.pdf”, “Test”);
FileAttachmentAnnotation fileAnnot = new FileAttachmentAnnotation(firstPage, new Aspose.Pdf.Rectangle(100,100, 130, 130), fs);
fileAnnot.Icon = FileIcon.Paperclip;
firstPage.Annotations.Add(fileAnnot);
doc.Save(“Attach_out.pdf”);

Please feel free to contact us for any further assistance.

Best Regards,
Hi Viswanathan,

Thanks for your inquiry.
Viswanathan:

Point 1

Please find the attached pdf (HTMLImageDemo.pdf ) & image ( Picture-of-something.jpg) for your reference. Her is the code block

Aspose.Words.Document dd = new Aspose.Words.Document(@"c:\Template1.doc");

Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(dd);

//db.InsertImage( 'C:/TopHeading.jpg");

db.InsertHtml("");

dd.Save("c:\\HTMLImageDemo.pdf");

The problem occurs because your image is wider than the Page width. To overcome this problem either you should increase the width of Page in Word document using PageSetup.PageWidth property or the size of the image should be resized to the width of the Page. Please use the following code snippet to achieve this:

...

...

...

db.InsertHtml("");

foreach (Shape img in doc.GetChildNodes(NodeType.Shape, true))

{

if (img.HasImage)

{

Section parentSection = (Section)img.GetAncestor(NodeType.Section);

double pageWidth = parentSection.PageSetup.PageWidth - (parentSection.PageSetup.LeftMargin + parentSection.PageSetup.RightMargin);

double pageHeight = parentSection.PageSetup.PageHeight - (parentSection.PageSetup.TopMargin + parentSection.PageSetup.BottomMargin);

bool widthLonger = (img.Width > img.Height) ? true : false;

double ratio;

if (widthLonger)

ratio = pageWidth / img.Width;

else

ratio = pageHeight / img.Height;

img.Width = img.Width * ratio;

img.Height = img.Height * ratio;

}

}

doc.Save(@"C:\Temp\out.pdf");

I hope, this helps.

Best regards,