Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Aug 21, 2018 3:34 pm

Hello, I am converting a pdf, of 12 pages that weighs 2639 kb, when converting it it is weighing 25000kb

Public Function CreaTiff(ByVal cadena As String, ByVal xnguia As String) As String
Dim input As String = cadena
Dim document As PdfDocument = New PdfDocument()
document.LoadFromFile(cadena)
JoinTiffImages(SaveAsImage(document), "D:\Sitios\Xue2\xue2\rpts\" & xnguia & "-Crt.tiff", EncoderValue.CompressionLZW)
System.Diagnostics.Process.Start("D:\Sitios\Xue2\xue2\rpts\" & xnguia & "-Crt.tiff")
Dim result As String = ""
Return result
End Function

Private Shared Function SaveAsImage(ByVal document As PdfDocument)
Dim images() As Image = New Image(document.Pages.Count - 1) {}
Dim i As Integer
For i = 0 To document.Pages.Count - 1 Step i + 1
images(i) = document.SaveAsImage(i)
Next
Return images
End Function

Private Shared Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
Dim encoders() As ImageCodecInfo = ImageCodecInfo.GetImageEncoders()
Dim j As Integer
For j = 0 To encoders.Length - 1 Step j + 1
If encoders(j).MimeType = mimeType Then
Return encoders(j)
End If
Next
Throw New Exception(mimeType + " mime type not found in ImageCodecInfo")
End Function

Public Shared Sub JoinTiffImages(ByVal images() As Image, ByVal outFile As String, ByVal compressEncoder As EncoderValue)
'use the save encoder
Dim enc As Encoder = Encoder.SaveFlag
Dim ep As EncoderParameters = New EncoderParameters(2)
ep.Param(0) = New EncoderParameter(enc, CType(EncoderValue.MultiFrame, Long))
ep.Param(1) = New EncoderParameter(Encoder.Compression, CType(compressEncoder, Long))

Dim pages As Image = images(0)
Dim frame As Integer = 0
Dim info As ImageCodecInfo = GetEncoderInfo("image/tiff")
Dim img As Image
For Each img In images
If frame = 0 Then
pages = img
'save the first frame
pages.Save(outFile, info, ep)
Else
'save the intermediate frames
ep.Param(0) = New EncoderParameter(enc, CType(EncoderValue.FrameDimensionPage, Long))
pages.SaveAdd(img, ep)
End If

If frame = images.Length - 1 Then
'flush and close.
ep.Param(0) = New EncoderParameter(enc, CType(EncoderValue.Flush, Long))
pages.SaveAdd(ep)
End If
frame = frame + 1
Next
End Sub

bigsas
 
Posts: 1
Joined: Thu Jul 05, 2018 5:08 pm

Wed Aug 22, 2018 6:25 am

Hello,

Thanks for your letter.
I prefer to recommend that you upgrade to the latest version( Spire.PDF Pack(Hot Fix) Version:4.8.8) to have a try. If the issue still occurs after trying, please provide your original Pdf file so that we can have a better investigation. You could send it to us via email( [email protected]).

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1534
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF

cron