Insert TIF file into PDF generate a 0kb file

Hello,



When I add this TIF file into a PDF with code below. The PDF file is corrupt with 0kb size



Can you help me ?







Dim FichierTIF As String = “C:\18_36_1.TIF”

'Instantiate a Pdf object by calling its empty constructor





Dim fs As New FileStream(FichierTIF, FileMode.Open, FileAccess.Read)

Dim tmpBytes As Byte() = New Byte(fs.Length - 1) {}

fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length))

fs.Close()



Dim mystream As New MemoryStream(tmpBytes)



Dim pdf1 As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()

'Create a section in the Pdf object

Dim sec1 As Aspose.Pdf.Generator.Section = pdf1.Sections.Add()

'Create an image object in the section



'sec1.Paragraphs.Add(image1)

sec1.PageInfo.Margin.Top = 5

sec1.PageInfo.Margin.Bottom = 5

sec1.PageInfo.Margin.Left = 5

sec1.PageInfo.Margin.Right = 5

'Set the path of image file

'sec1.PageInfo.PageWidth = (b.Width / b.HorizontalResolution) * 72

'sec1.PageInfo.PageHeight = (b.Height / b.VerticalResolution) * 72

pdf1.Sections.Add(sec1)



Dim image1 As Aspose.Pdf.Generator.Image = New Aspose.Pdf.Generator.Image(sec1)

'Add image object into the Paragraphs collection of the section

sec1.Paragraphs.Add(image1)





'Set the type of image using ImageFileType enumeration

image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff

image1.ImageInfo.IsBlackWhite = True

image1.ImageInfo.ImageStream = mystream

'image1.Margin.Top = 0

'image1.Margin.Bottom = 0

'image1.Margin.Left = 0

'image1.Margin.Right = 0

'image1.ImageScale = 0.95F

'pdf1.Conformance = Aspose.Pdf.Generator.PdfConformance.PdfA1A 'Convert(New MemoryStream(), Aspose.Pdf.PdfFormat.PDF_A_1B, Aspose.Pdf.ConvertErrorAction.Delete)







Dim NomFichierTIF As String = Split(FichierTIF, “”).Last

Dim NomFichierPDF As String = Replace(NomFichierTIF.ToUpper, “.TIF”, “.PDF”)

Dim FichierPDF = Replace(FichierTIF, NomFichierTIF, NomFichierPDF)

pdf1.Save(FichierPDF)

I tried this code too



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__1 As Image = Image.FromFile(“C:\18_36_1.TIF”)

’ Find which dimension the frames in this image represent. For example

’ the frames of a BMP or TIFF are “page dimension” whereas frames of a GIF image are “time dimension”.

Dim dimension As New System.Drawing.Imaging.FrameDimension(image__1.FrameDimensionsList(0))



’ Get the number of frames in the image.

Dim framesCount As Integer = image__1.GetFrameCount(dimension)



’ 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__1.SelectActiveFrame(dimension, 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 ps16 As PageSetup = builder.PageSetup

ps16.PageWidth = ConvertUtil.PixelToPoint(image__1.Width, image__1.HorizontalResolution)

ps16.PageHeight = ConvertUtil.PixelToPoint(image__1.Height, image__1.VerticalResolution)



’ Insert the image into the document and position it at the top left corner of the page.

builder.InsertImage(image__1, Aspose.Words.Drawing.RelativeHorizontalPosition.Page, 0, Aspose.Words.Drawing.RelativeVerticalPosition.Page, 0, ps16.PageWidth, ps16.PageHeight, Aspose.Words.Drawing.WrapType.None)

Next

End Using



’ Save the document to PDF.

doc.Save(“C:\18_36_1.PDF”, SaveFormat.Pdf)















And when I load a the tif file I have an error “A generic error occurred in GDI+”



This issue come from Windows XP, but I’m on Windows 7 up to date.

Hi Nicolas,

Thanks for your inquiry. I have tested your scenario with shared document using Aspose.Pdf for .NET 11.9.0 and noticed the exception. For further investigation, I have logged an issue in our issue tracking system as PDFNET-41251 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

We are sorry for the inconvenience caused.

P.S: We are testing the scenario in reference to Aspose.Words and will update you shortly.

Best Regards,

Hello,



If you try to open my TIF natively in Windows ! It’s doesn’t work ! If I open the file with a specific TIF Viewer (like XNview) it’s work.



After investigation I think the issue come from TIFF Version.



So, now I open and convert the TIF with Aspose Imaging in a Stream.



Dim FichierTIF As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(FileToConvert)

Dim FichierTIFSaveOption As New Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default)

Dim FichierTIFStream As New MemoryStream()

FichierTIF.Save(FichierTIFStream, FichierTIFSaveOption)





After convertion, my PDF is working fine !



Have a nice day

Hi Nicolas,


Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 16.6.0, we managed to reproduce this issue on our end. We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-14010. Your request has also been linked to the appropriate issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Paga16:
Hello,

If you try to open my TIF natively in Windows ! It’s doesn’t work ! If I open the file with a specific TIF Viewer (like XNview) it’s work.

After investigation I think the issue come from TIFF Version.

So, now I open and convert the TIF with Aspose Imaging in a Stream.

Dim FichierTIF As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(FileToConvert)
Dim FichierTIFSaveOption As New Aspose.Imaging.ImageOptions.TiffOptions(Aspose.Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default)
Dim FichierTIFStream As New MemoryStream()
FichierTIF.Save(FichierTIFStream, FichierTIFSaveOption)

After convertion, my PDF is working fine !

Have a nice day

Hi,

Thanks for sharing the details.

The above stated details are associated with earlier logged issue and we will surely consider it during the resolution of earlier reported issue. As soon as we have some definite updates, we will let you know.
Hi,

Regarding WORDSNET-14010, our product team has completed the work on your issue and has come to a conclusion that they won't be able to implement the fix to your issue. Your issue (WORDSNET-14010) will been closed with 'Won't Fix' resolution.

The error occurs in constructor of the System.Drawing.Bitmap class on opening the 18_36_1.TIF file.
I cannot open the file in image viewer/editors that are distributed with Windows: an error occurs too.
The file is successfully opened in Multi-Page TIFF Editor. After re-saving the file in the editor, the error does not happen.

Since the problem occurs in standard .NET libraries Aspose.Words relies on, please contact Microsoft .NET team to report the issue with the TIFF image.

Best regards,

The issues you have found earlier (filed as PDFNET-41251) have been fixed in Aspose.PDF for .NET 24.6.