I am using the GDI+ assemblies 1_31 and Migradoc to create PDF's from multiple TIFF files. I can view the PDF fine in other readers like PDF Complete and Nuance. If the PDF is opened in Adobe Reader X, they get an "Insuficient Data for an image" message and none of the pages below are visible.
I read two different forum messages about this issue:
1) stated they used the GDI+ and it was fixed but I am already using that
2) stated they had to save each tiff as a seperate PDF page and them combine into a single PDF
Hoping someone out there has a better suggestion. Please?
Below is the code I am using. I uncompress a zip file. Pull an *.asc file and open it. That doc tells me what TIFF images belong in each grouping (single PDF file).
Code:
Imports MigraDoc.Rendering
Imports MigraDoc.DocumentObjectModel
Imports MigraDoc.RtfRendering
Imports ICSharpCode.SharpZipLib.Zip
Function ProcessIndexFile(ByVal myFileName As String, ByVal myFilePath As String) As Boolean
Dim sFileReader As System.IO.StreamReader
Dim sInputLine As String
Dim sWholeLine As String
Dim sDate As String
Dim sControl As String
Dim sRteNum As String
Dim sDocNum As String
Dim sImgFileName As String
Dim hDocNum As String
Dim hDate As String
Dim hRteNum As String
Dim fStart, fNewDoc As Boolean
Dim myerr As String
Dim myDoc As Document
Dim myRend As PdfDocumentRenderer
Dim mySec As Section
Dim myImg As MigraDoc.DocumentObjectModel.Shapes.Image
Dim myPS As MigraDoc.DocumentObjectModel.Orientation
fStart = True
fNewDoc = True
myPS = Orientation.Landscape
On Error GoTo errorhandler
sFileReader = System.IO.File.OpenText(myFileName) '*****Open File
sInputLine = sFileReader.ReadLine
Do Until sInputLine Is Nothing '*****Loop Line by Line through file
sWholeLine = sInputLine '*****Create variable to store line
'******************************************************
'*****Pull field values from line based on position
'******************************************************
sDate = Mid(sWholeLine, 1, 8)
sDate = Replace(sDate, "/", "")
sControl = Mid(sWholeLine, 18, 14)
sRteNum = Mid(sWholeLine, 18, 6)
sDocNum = Mid(sWholeLine, 29, 3)
sImgFileName = Mid(sWholeLine, 63, 12)
Debug.Print(sDate & Chr(9) & sControl & Chr(9) & sDocNum & Chr(9) & sImgFileName)
If fStart = True Then '*****Sets comp for first line of file
hRteNum = sRteNum
hDocNum = sDocNum
hDate = sDate
fStart = False
End If
If sDocNum <> hDocNum Then
'*****Document changed, write previous file and start new one
MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(myDoc, "MigraDoc.mdddl")
myRend = New PdfDocumentRenderer(True, PdfSharp.Pdf.PdfFontEmbedding.Always)
myRend.Document = myDoc
myRend.RenderDocument()
myRend.PdfDocument.Save("c:\Me\processed\Me_" & hDate & "_" & hRteNum & "_" & hDocNum & ".pdf")
hDocNum = sDocNum
fNewDoc = True
End If
If fNewDoc = True Then
myDoc = New Document
myDoc.Info.Title = "Process Documents"
myDoc.Info.Subject = sControl
myDoc.Info.Author = "Me"
fNewDoc = False
End If
mySec = myDoc.AddSection
myImg = mySec.AddImage(myFilePath & "\" & sImgFileName)
myImg.LockAspectRatio = True
myImg.Width = New Unit(7, UnitType.Inch)
'mySec.AddPageBreak()
sInputLine = sFileReader.ReadLine '*****Go to next line in file
Loop
sFileReader.Close()
ProcessIndexFile = True
Exit Function
errorhandler:
myerr = "This file did not parse correctly. Please contact Me with error code and copy of zip file." & Chr(13) & Chr(13)
MsgBox(myerr & Err.Number & ": " & Err.Description)
Debug.Print(Err.Number & " - " & Err.Description & ": " & Err.Source)
ProcessIndexFile = False
End Function