I followed the example of how to code to convert a TIF to a PDF using the Aspose.Words product and it ran fine. But when I went to open the PDF, I get the message: Adobe Reader could not open ‘1234.pdf’ because it is eather a not supported file type or because the file has been damaged. Is there something else that needs to be done that is not in the code example? I am doing this in a vb.net v2.0(vs2005) program and I used the Aspose Words DLL runtime version v2.0.50727.
Here is my code:
Imports Aspose.Words Imports Aspose.Words.Drawing Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Imports System.Reflection Imports Microsoft.VisualBasic Public Class clsImgConvert Public Sub ConvertImageToPdf(ByVal inputFileName As String, ByVal outputFileName As String) Dim fileName As String = "C:\Licenses\Aspose.Total.lic" Dim fInfo As FileInfo = New FileInfo(fileName) Dim wordLic As Aspose.Words.License = New Aspose.Words.License() If fInfo.Exists Then wordLic.SetLicense(fileName) End If ' Create Aspose.Words.Document and DocumentBuilder. ' The builder makes it simple to add content to the document. Dim doc As New Aspose.Words.Document() Dim builder As New Aspose.Words.DocumentBuilder(doc) ' Read the image from file, ensure it is disposed. Using image As Image = image.FromFile(inputFileName) ' Get the number of frames in the image. Dim framesCount As Integer = image.GetFrameCount(FrameDimension.Page) ' Loop through all frames. For frameIdx As Integer = 0 To framesCount - 1 ' Insert a section break before each new page, in case of a multi-frame TIFF. If frameIdx <> 0 Then builder.InsertBreak(BreakType.SectionBreakNewPage) End If ' Select active frame. image.SelectActiveFrame(FrameDimension.Page, frameIdx) ' We want the size of the page to be the same as the size of the image. ' Convert pixels to points to size the page to the actual image size. Dim ps As PageSetup = builder.PageSetup ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution) ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution) ' Insert the image into the document and position it at the top left corner of the page. builder.InsertImage(image, RelativeHorizontalPosition.Page, 0, RelativeVerticalPosition.Page, 0, ps.PageWidth, ps.PageHeight, WrapType.None) Next frameIdx End Using ' Save the document to PDF. doc.Save(outputFileName) End Sub End Class
This message was posted using Page2Forum from How-to: Convert an Image to PDF - Aspose.Words for .NET