I've been reading the PDF 1.4 spec about how to embed an ICC profile as well as using the "Work on PDF Objects" sample to work my self through it, however I'm at a dead end. I can't seem to get any of the pdf objects I've created to actually end up in the pdf.
Here's the code I'm using:
Code:
Public Enum IccProfile As Integer
Gray = 1
RGB = 3
CMYK = 4
End Enum
Public Sub AttachIccProfile(ByVal IccProfile As IccProfile, ByRef Document As PdfDocument)
If Document Is Nothing Then Throw New ArgumentNullException("Document")
Dim ProfilePath As String = ""
Select Case IccProfile
Case IccProfile.Gray
ProfilePath = "grayscale.icc"
Case IccProfile.RGB
ProfilePath = "rgb.icc"
Case IccProfile.CMYK
ProfilePath = "cmyk.icc"
Case Else
Throw New ArgumentOutOfRangeException("IccProfile")
End Select
Dim IccArray As New PdfArray(Document)
Dim IccDict As New PdfDictionary(Document)
Dim FilterArray As New PdfArray(Document)
FilterArray.Elements.Add(New PdfName("/FlateDecode"))
Using EncodedIcc As New MemoryStream()
Using ds As New DeflateStream(ipstream, CompressionMode.Compress, True)
Using fs As New FileStream(ProfilePath, FileMode.Open, FileAccess.Read)
Dim Buffer(CInt(fs.Length - 1)) As Byte, Size As Integer = 0
Size = fs.Read(Buffer, 0, Buffer.Length)
ds.Write(Buffer, 0, Size)
End Using
End Using
IccDict.Elements("/N") = New PdfInteger(CInt(IccProfile))
IccDict.Elements("/Filter") = FilterArray
IccDict.Stream = IccDict.CreateStream(EncodedIcc.GetBuffer())
End Using
Document.Internals.AddObject(IccDict)
IccArray.Elements.Add(New PdfName("/ICCBased"))
IccArray.Elements.Add(PdfInternals.GetReference(IccDict))
Document.Internals.AddObject(IccArray)
End Sub
Any help here would be greatly appreciated.
- B