Converting creates empty files

Hello. This is my first post to this forum. My company have a license for Aspose.Total and Ive been set to develope a solution that converts documents from a SharePoint library to PDF and sends it to another library (same web collection or a different web collection).<div><br></div><div>My problem is that I cant get the content of the file inside the PDF-document when its created. It always ends up empty. Im using Client Object Model so I can send the document to which SharePoint web collection I want. Ive tried with several versions of Aspose.pdf (6.4.0.0 to 7.2.0.0), but I dont think the problem lies there. There must be some errors in my code. I`m converting a HttpWebRequest to a stream, then puts it into a byte array. Reads it with a MemoryStream og then save it as a pdf file, I then convert it to a byte array again and upload it to a SharePoint library. The file gets uploaded, but it contents is empty.


Aspose 6.4.0.0 - 7.2.0.0
SharePoint 2010

###########################################
My code:


Aspose.Pdf.Generator.Pdf pdfDocument = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section sec = pdfDocument.Sections.Add();

List docLib = context.Web.Lists.GetByTitle(documentLibrary);
FileCreationInformation newFile = new FileCreationInformation();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(documentURL);
request.UseDefaultCredentials = true;
WebResponse response = request.GetResponse();

byte[] bytefile = null;

Stream stream = response.GetResponseStream();

using (MemoryStream ms = new MemoryStream())
{
byte[] buffer = new byte[16 * 1024];
int read;

while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}

bytefile = ms.ToArray();
}

MemoryStream pdfFil = new MemoryStream(bytefile);
pdfDocument.Save(pdfFil);

byte[] nyttDokument = null;

byte[] buff = new byte[16 * 1024];
int leser;

while ((leser = pdfFil.Read(buff, 0, buff.Length)) < 0)
{
pdfFil.Write(buff, 0, leser);
}

nyttDokument = pdfFil.ToArray();

pdfFil.Close();

newFile.Content = nyttDokument;
newFile.Overwrite = true;
newFile.Url = spURL + documentLibrary + ā€œ/ā€ + destinationFileURL;
nyefila = newFile.Url;
Microsoft.SharePoint.Client.File uploadFile = docLib.RootFolder.Files.Add(newFile);
context.ExecuteQuery();

Hi Christian,

Thanks for your inquiry. Please check following documentation link for creating a simple PDF file using API. Hopefully it will help you to achieve your requirements. You have to add a paragraph containing text or image object in your newly created section. As Iā€™m unable to find this part in your above shared code.

Moreover, we will recommend you to use latest API as over the time we have made number of enhancement and fixes in our API.

Please feel free to contact us for any further assistance.

Best Regards,