I have a task of displaying pdf-files in a browser. As the files are stored in the tif image format I need to convert the files to PDF. I have experimented with code provided on the Aspose web site. However, it doesnt seem to work consistently. Can you help me out here?
To test I used the chrysanthemum.jpg example image that comes with Windows. I edited it in paint.NET and saved it as a tif file. I also edited the image by copy pasting the image content. That gave me an image around 10Mb. The files are attached.
My test results show that when swithing the IsBlackWhite property:
Converting the small Tif image works in both color and black n white
Converting the large Tif image works in black n white
Converting the large Tif image in color DOES NOT WORK. The generated pdf file has a size of zero bytes.
My setup:
-Windows 7 Pro 64bit
-Aspose.pdf 8.3.0.0 .NET 3.5
My code:
Private Sub DoItLikeAspose()
Dim outDir As String = “C:\temp\tifftest”
'get a list of tiff image files
Dim files As New List(Of String)
files.Add(“c:\temp\tifftest\chrysanthemumBIG.tif”)
'Instantiate a Pdf object
Dim pdf1 As New Aspose.Pdf.Generator.Pdf()
'navigate through the files and them in the pdf file
Dim myFile As String
For Each myFile In files
'Load all tiff files in byte array
Dim fs As New FileStream(myFile, FileMode.Open, FileAccess.Read)
Dim tmpBytes As Byte() = New Byte(fs.Length - 1) {}
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length))
Dim mystream As New MemoryStream(tmpBytes)
Dim b As New Bitmap(mystream)
'Create a new section in the Pdf document
Dim sec1 As New Aspose.Pdf.Generator.Section(pdf1)
'Set margins so image will fit, etc.
sec1.PageInfo.Margin.Top = 5
sec1.PageInfo.Margin.Bottom = 5
sec1.PageInfo.Margin.Left = 5
sec1.PageInfo.Margin.Right = 5
sec1.PageInfo.PageWidth = (b.Width / b.HorizontalResolution) * 72
sec1.PageInfo.PageHeight = (b.Height / b.VerticalResolution) * 72
'Add the section in the sections collection of the Pdf document
pdf1.Sections.Add(sec1)
'Create an image object
Dim image1 As New Aspose.Pdf.Generator.Image(sec1)
'Add the image into paragraphs collection of the section
sec1.Paragraphs.Add(image1)
image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff
'set IsBlackWhite property to true for performance improvement
'image1.ImageInfo.IsBlackWhite = True
'Set the ImageStream to a MemoryStream object
image1.ImageInfo.ImageStream = mystream
Next
'Save the Pdf
pdf1.Save(outDir + “OutputFile.pdf”)
End Sub
Sorry for the inconvenience faced. While using Aspose.Pdf for .NET 8.3.0, I’ve managed to reproduce this issue on my side and logged the issue in our bug tracking system as PDFNEWNET-35716 for further investigation and resolution. I’ve also linked your request to this issue and you will be notified via this thread as soon as it is resolved.
Please feel free to contact us for any further assistance.
Can you tell me if a fix for this is in your development pipeline? To be able to plan my development, I would like to know when a fix for this can be expected.
Thanks for your inquiry. Our development team is looking into issue and I’m afraid its not resolved completely. We are coordinating with our development for the updates and will also update you accordingly.
the issue seems to have been resolved. It states that:
Exceptions:
Exception is occurring while creating a PDF document
OutOfMemoryError during large PDF generation
TIFF to PDF conversion throws exception
Exception while flattening the PDF document
OutOfMemoryException during Image to PDF conversion
Exception while opening the PDF file
NullReferenceException when loading PDF file
And further below:
TIFF to PDF - Resultant PDF is 0KB
So it would seem as though the error has been resolved. Now I dont get the 0kb error any longer. I do, however, get an OutOfMemoryException. I notice that in my dev environment that about 400Mb RAM is used when calling Pdf.Save(stream).So this raises the following questions:
1. Has the original error been resolved?
2. If yes, should I not have been informed?
3. If yes, how much RAM should be available for TIFF to pdf conversion? Given the changelog, I assume you have some kind og table comparing file size/Ram requirements. Tiff-files are often greater in size that a jpeg so 10Mb should be no problem in my world.
Thanks for your inquiry. I am afraid your reported issue is still not resolved. Our development team has investigated the issue and found it is because of GDI limitations. So our development team is working over to implement our custom image encoder(Aspose.Imaging) in Aspose.Pdf. Your issue will be fixed as soon as it is implemented.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.