We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pdf to Image to Pdf

I’ve had a look at this link as a reference http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/how-to-convert-memorystream-image-to-pdf.html

Basically what I am trying to do is convert a Pdf to an Image, if the Image is upside down, I rotate it then save it back to Pdf and then back to the database. However when I try to view the Pdf after rotation, the file appears to be damaged.

1. Read Pdf from database and convert to Image
2. RotateFlip the Image and save it to memory stream
3. Create a pdf document and place this image into the document
4. Save the pdf and overwrite the existing pdf in the database.

Any ideas?

Hi Quang,

Thanks for using our products. I think as per your requirements, you can simply read the source PDF document from database and if you think the page needs to be rotated, you can simply use the following code to rotate the page without first converting it into image format, rotate it and then convert it back to PDF. Please try using the following approach and if you still encounter any issue, please feel free to contact. We are sorry for your inconvenience.

[C#]
// open the source PDF document
Document doc = new Document(@“d:\pdftest\Source.pdf”);
// convert the first page to 180 degree
doc.Pages[1].Rotate = Rotation.on180;
// save the updated document
doc.Save(@“d:\pdftest\PageRotated.pdf”);

PS, for your reference, I have also attached the source PDF and the resultant file that I have generated. Please take a look.

Thanks this works fine.

I test the save to file which is correct but when I save to a memory stream and save it to the database and then try to view it again it says its damaged. Therefore I think its a problem with how I’m saving this memory stream and not on Aspose end.

Cheers,
Quang

It turns out I just had to restart the memory stream at position 0.

rotatedMemoryStream.Seek(0, SeekOrigin.Begin);

then save to database.

Cheers,
Quang

When I do the rotation and save it is ok. When I open this new rotated page and rotate again and save it doesn’t rotate back to the original. So if you rotate the PageRotated.pdf after saving, does this work for you?

It turns out I need to use .None to get it back to the original position which is a bit weird, I would have thought you can just rotate it again another 180.

Cheers,
Quang