Unable convert image form Sharepoint library

HI
Aspose,


When I try to convert am Image,which is in normal website,the conversion is working fine.But when the image is from sharepoint document library,I was thrown Exception.Can you please look into the problem?

Hello Surendrababu,

Thanks for using our products.

Can you please share the image file that is causing the issue so that we can test the scenario at our end. We apologize for your inconvenience.

Any file ,which is stored in sharepoint image library.The exception thrown is

The remote server returned an error: (401) Unauthorized.

I have used the following C# code.

Pdf pdf3 = new Pdf();

Section sec3 = pdf3.Sections.Add();

Aspose.Pdf.Image img3 = new Aspose.Pdf.Image(sec3);

sec3.Paragraphs.Add(img3);

sec3.TextInfo.Alignment = AlignmentType.Center;

img3.ImageInfo.Alignment = AlignmentType.Center;

img3.ImageInfo.File = @“http://spp2011:5454/rameshgk/RLibrary/testimage1.JPG”;

img3.ImageInfo.ImageFileType = ImageFileType.Jpeg;

pdf3.Save(@“C:\Documents and Settings\rameshgandhik\Desktop\testing.pdf”)

Kindly review the above and provide me with a solution.

Thanking You

Surendrababu J

Hello Surendrababu,

Thanks for your patience and sorry for replying you late.

You are getting error: (401) Unauthorized because you are not being authenticated to get the image contents from sharepoint site. Therefore in order to retrieve information from location that requires authentication, you need to specify the login credentials. Please take a look over the following code snippet that I have used to test the scenario and as per my observations, the image contents are properly being retrieved and are being placed inside the PDF.

In case it does not resolve your problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

[C#]

// Image url
String Image_URL = http://localhost/sites/test1/Site%20Images/picformainpage.JPG;
// create Network credential object and specify the user name, password and domain name
NetworkCredential network_credential = new NetworkCredential("nayyer", "nayyer", "mydomain");
// Create a WebClient object
WebClient wc = new WebClient();
// Pass Network credentials object to WebClient object
wc.Credentials = network_credential;
// read the contents of image into Byte array
Byte[] pageData = wc.DownloadData(Image_URL);
// create a memory Stream object while passing byte array contents
MemoryStream memoryStream = new MemoryStream(pageData);

// create PDF object
Pdf pdf3 = new Pdf();
// create a section and add it to PDF document
Section sec3 = pdf3.Sections.Add();
// create image object
Aspose.Pdf.Image img3 = new Aspose.Pdf.Image(sec3);
// add the image to paragraphs collection of section
sec3.Paragraphs.Add(img3);
// set the textinfo alignment information as center aligned
sec3.TextInfo.Alignment = AlignmentType.Center;
// set the image horizontal alignment information as center aligned
img3.ImageInfo.Alignment = AlignmentType.Center;
// specify the image file type
img3.ImageInfo.ImageFileType = ImageFileType.Jpeg;
// pass the contents of memory stream object to image object
img3.ImageInfo.ImageStream = memoryStream ;
// save the resultant PDF
pdf3.Save(@"D:\pdftest\SharePoint-Image-Issue.pdf");