· Sep 9, 2020

pdf embedded too large? Can't recreate it

Hello fellow comrades.


I have a little issue concerning the creation of an embedded PDF sent by hl7. When I Extract it, the pdf is not completed (Seen by opening it with notepad++) compared to the one I created with a Base 64 converter.

The one I got from the Base 64 converter contains 7XXX contains lines and mine after my program contains 5900. The 5900 lines are the same that 5900 firsts of the others so my converting code is ok. The problem must be in the recuperation of the data. I think it's too long and the GetFieldStreamRaw can't contain everything. Could you help, what are the upgradres I need to do to overcome my issue?


Info: Req is the hl7 message, Segment is the path and is correct, linkAndFileName where to copy it. The loop is correct, the problem is concerning the first line.

Method getPdfBase64FromED(req As EnsLib.HL7.Message, segment As %String, linkAndFileName As %String) As %Status
  do req.GetFieldStreamRaw(.base64, segment)
    set stream1=##class(%Stream.FileCharacter).%New()
    set stream2=##class(%Stream.FileCharacter).%New()
    set sc = stream2.LinkToFile(linkAndFileName)
    while 'base64.AtEnd {
        set temp=base64.Read()
        set temp=$translate(temp, $c(13,10))
        do stream1.Write(temp)
    $$$TRACE(" ")
    do stream1.Rewind()
    while 'stream1.AtEnd {
        set temp=stream1.Read(4000)
         set temp=$system.Encryption.Base64Decode(temp)
        do stream2.Write(temp)
sc = stream2.%Save()
return $$$OK


Thanks in advance,


Discussion (3)0
Log in or sign up to continue

I have seen the same problem with using character streams and the "raw" get so needed to use the un-escaped get and decode into a binary stream.   It seems that something in the encoded PDF is interpreted as an escaped end marker.

I never like to have direct write to files inside of the rules or transformation so I return the decoded stream.  Usually I call this in a transformation that places it into a stream container.  That stream container is then sent to a Filepassthrough or FTPpassthrough operation to handle the actual dropping of the file.

Here is my similar function that has worked for very large embedded PDF files:

ClassMethod GetStreamDecodeFromHL7Field(pHl7Msg As EnsLib.HL7.Message, pPropPath As %String) As %Stream.Object
                #dim tSC as %Status = $$$OK
                #dim tRemainder as %String
                #dim tBinary as %String
                #dim tBase64 as %String
                // Extract Base64 encoded data to a temp stream, then
                // decode it as a second step.
                set tRemainder = ""
                set tBase64Stream = ##class(%Stream.TmpCharacter).%New()
                set tSC = pHl7Msg.GetFieldStreamUnescaped(.tBase64Stream, pPropPath, .tRemainder)
                set tStream = ##class(%Stream.GlobalBinary).%New()
                do tBase64Stream.Rewind()
                while ('tBase64Stream.AtEnd) {
                                set tBase64 = tBase64Stream.ReadLine()
                                set tBinary = $system.Encryption.Base64Decode(tBase64)
                                do tStream.Write(tBinary)
                return tStream