GDViewer DisplayFromString

Discussions about document viewing.
Post Reply
rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

GDViewer DisplayFromString

Post by rbsoft » Thu Feb 04, 2010 11:19 pm

Hello,

I am using evaluating GDViewer with RealBasic and everything seems to be working very well. However, I have a problem that I hope you can help with:

When I load a PDF directly from a file there is no problem. However, when I load the PDF file contents into a string and try to use DisplayFromString I get a result of 13 and cannot open from string. Here is a code sample in RealBasic 2008:

Code: Select all

  Sub OpenPDF(f as folderitem)
  dim nState as integer
  dim tis as TextInputStream
  
  If f <> Nil then
    if f.Exists then
      call gdviewer1.SetLicenseNumber("Removed")
      tis = f.OpenAsTextFile
      'nState = GdViewer1.DisplayFromPdfFile(f.AbsolutePath) 'I commented out this line, which works and loads the pdf properly
      nState = GdViewer1.DisplayFromString(tis.ReadAll) 'here is where I have trouble, it returns 13 instead of 0
      tis.close
    Else
      msgbox "File Not Found."
    End if
  else
    quit
  end if
End Sub

Any help would be appreciated.

Thanks!

-Mike

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: GDViewer DisplayFromString

Post by Loïc » Sat Feb 06, 2010 1:29 pm

Hi Mike,

Please send a basic RB application embedding your code at esupport (at) gdpicture (dot) com.

We will download a trial version of RB to see what we can do.

With best regards,

Loïc

rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

Re: GDViewer DisplayFromString

Post by rbsoft » Mon Feb 08, 2010 5:23 pm

Hi Loïc,

No problem, I already sent it on Feb 5th.

-Mike

rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

Re: GDViewer DisplayFromString

Post by rbsoft » Mon Feb 08, 2010 7:34 pm

Excuse me, I misspoke. I only sent the PDF. I will send the code sample right now.

-Mike

rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

Re: GDViewer DisplayFromString

Post by rbsoft » Wed Feb 10, 2010 9:05 pm

I'm still waiting for a response on this, or some indication that you've received my file via email... :|

In the mean-time I have tested DisplayFromString by modifying your VB example (vb_sample.vbp ) so that the Load PDF button functions as follows:

Code: Select all

Private Sub Command20_Click()
Dim sExt As String
Dim strTemp As String 'holds one line
Dim strAll As String 'holds the whole file
Dim ffile 'file handle
Dim i As Long 'return value from DisplayFromString

   
   Me.CommonDialog1.Filter = "All Files (*.*)|*.*|PDF (*.pdf)|*.pdf"
   Me.CommonDialog1.ShowOpen
   If Len(Me.CommonDialog1.FileName) > 0 Then
      ffile = FreeFile
      Open Me.CommonDialog1.FileName For Input As #ffile
      While Not EOF(ffile)
      Line Input #ffile, strTemp
        strAll = strAll & strTemp 'read the whole file into strAll
      Wend
      Close #ffile
      'Me.GdViewer1.DisplayFromPdfFile (Me.CommonDialog1.FileName) 'removed for this test
      i = Me.GdViewer1.DisplayFromString(strAll) 'try to display from string
      MsgBox i 'returns error code 13
   End If
End Sub
This is the same result that I get with REALBasic: error code 13 - unknown image format. The PDF files open just fine when I use DisplayFromPDFFile so there is nothing wrong with the format.

I also tried outputting the string to a temporary PDF file and opening the PDF file in Acrobat Reader, which worked. So that tells me that the string in fact the correct format.

I can only conclude that there is a bug in DisplayFromString in REALBasic and Visual Basic, or there is something wrong with how the string is being passed.

-Mike

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: GDViewer DisplayFromString

Post by Loïc » Thu Feb 11, 2010 5:37 pm

Hi Mike,

Your vb6 code is incorrect. I suspect your RB code incorrect too.
I was not able to compile your RB project using latest RealBasic compiler...

Here the good way to load PDF from string in vb6:

Code: Select all

Private Sub Command19_Click()
   Call GdViewer1.DisplayFromString(Text2String("c:\test.pdf"))
End Sub

Public Function Text2String(strPath As String) As String
   Dim intFile As Integer
   Dim strTemp As String
   Dim lByteLen As Long
   Dim bytArray() As Byte

  intFile = FreeFile
  Open strPath For Binary As intFile
  lByteLen = LOF(intFile)
  ReDim bytArray(1 To lByteLen)
  Get intFile, 1, bytArray

  
  Text2String = StrConv(bytArray, vbUnicode)
  Close intFile
  Erase bytArray
End Function
Hope this helps.

Kind regards,

Loïc

rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

Re: GDViewer DisplayFromString

Post by rbsoft » Thu Feb 11, 2010 8:24 pm

Thanks, that works in VB. I'll see if I can convert it to RB.

rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

Re: GDViewer DisplayFromString

Post by rbsoft » Thu Feb 11, 2010 8:42 pm

Still having trouble with RB. Would it be possible to get a sample function for RB?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: GDViewer DisplayFromString

Post by Loïc » Thu Feb 11, 2010 8:49 pm

Hi,

I don't understand how RB works with strings. You have more competence than me.

I suggest you to post the issue to the RB support. The goad is to store the content of a file in a string variable, then you will be able to call the desired function of GdViewer.

Kind regards,

Loïc

rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

Re: GDViewer DisplayFromString

Post by rbsoft » Thu Feb 11, 2010 9:20 pm

I appreciate your help so far.

Since you are the one who will be getting my $250 I don't think that a sample function in REALBasic is too much to ask for, especially since REALBasic is a development environment that your plugin specifically supports.

I will be purchasing immediately as soon I can get it to work, but it's taking a lot of my time trying to figure it out with no real samples for this function.

Thanks,

-Mike

rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

Re: GDViewer DisplayFromString

Post by rbsoft » Fri Feb 12, 2010 9:14 pm

I took the string values that were being sent to DisplayFromString from VB and RB and wrote them both out to a file. I found only one difference between the two files: the "Size" of the VB file is 2 bytes larger than the RB file.

Strangely, it does not affect the "Size on disk". Here is a screenshot:

Image

Is VB or StrConv tacking on some kind of EOF marker that RB is not, or could it be there is a particular character that DisplayFromString is looking for in order to validate the format of the PDF file?

Interestingly, Acrobat Reader can open both files without any problems.

rbsoft
Posts: 9
Joined: Thu Feb 04, 2010 11:08 pm

Re: GDViewer DisplayFromString

Post by rbsoft » Sat Feb 13, 2010 8:17 pm

I found the problem that was causing discrepancies between the file sizes. Now I can load a simple PDF (4kb) in RB but not a larger, more complex one (1mb).

Do you know what exactly StrConv(bytArray, vbUnicode) is doing to the string? I need to replicate that in RB to get it to work.

jpbro
Posts: 8
Joined: Sun Jul 26, 2009 10:37 pm
Location: Canada
Contact:

Re: GDViewer DisplayFromString

Post by jpbro » Tue Mar 16, 2010 8:46 pm

StrConv(BYTEARRAY, vbUnicode), converts the byte array to a Unicode (2 bytes per character) string. I don't think that this is the best approach if you already have your data in a byte array - maybe you should try using DisplayFromByteArray instead?

Unfortunately, I don't use RealBasic, so I can't help much more than that - if DisplayFromByteArray doesn't work, you will have to see if there is a way to convert your RB array/string into a Unicode string before using DisplayFromString.

sanket
Posts: 1
Joined: Wed Apr 09, 2014 11:26 am

Re: GDViewer DisplayFromString

Post by sanket » Wed Apr 09, 2014 11:44 am

Version:- GDViewer 5.xx.
Browsere:- IE11

I have binary data of the TIFF image, when I am using DisplayFromString() from javascript/Vbscript it's not at all working for me. Where as when I have used DisplayFromByteArray() from vbscript it's working. I dont want to use VBscript as it is not supported in IE11. Is there any way to put image on viewer from binary data???

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests