Having a fight with DynaPDF

Hi all,

I’m having a fight trying to insert a picture in a pdf. I have a PDF that works well, text and some vector graphics, however when I try and add a PNG and JPG through a Picture object (that shows fine on a canvas), all I get is blank where the image should be.

[code] call pdf.SetSaveNewImageFormat(false) // if possible pass through
call pdf.SetUseTransparency(true) // no transparent color
call pdf.SetCompressionFilter(pdf.kcfFlate) // no compression
call pdf.SetResolution(300) // max resolution

  call pdf.InsertPicture(imgLogo,48,48,100,100)[/code]

If I make imgLogo the LogoMBS(100) it shows. If I load the same file in the example from Dynapdf, it works. If I debug and stop on that line of InsertPicture, imgLogo does show the picture properly.

I did try converting the Picture into a MemoryBlock and do a InsertImageFromBuffer,

dim mb1 As MemoryBlock = imgLogo.GetData(Picture.FormatPNG) call pdf.InsertImageFromBuffer(48,48, 100,100, mb1, 1)

Then I receive a “There is more than one item with this name and it’s not clear to which it refers”.

Anything I’m missing?

Thanks

Maybe it isnt in the place or size you expect?

My code for similar

         call pdf.InsertPicture(thepic , marginleft_mm *  72/25.4 ,  margintop_mm *  72/25.4,  thepic.width * factor,  thepic.height * factor)

The left and top margins are held by me in mm
The * 72/25.4 changes it to inches based on a notional 72 dpi
Factor governs the scaling of the image

Have you tried commenting out the other code and just using:

result = pdf.InsertPicture(imgLogo, 48, 48, imgLogo.Width,imgLogo.Height)

Just to see if this works?

make sure to pass double parameters with double value and not integer.

Xojo’s compiler gets confused here with integer.

[quote=284860:@Denise Adams]Have you tried commenting out the other code and just using:

result = pdf.InsertPicture(imgLogo, 48, 48, imgLogo.Width,imgLogo.Height)

Just to see if this works?[/quote]

Yes, I just get a blank page. Thanks though.

If I do

imgLogo = LogoMBS(100) call pdf.InsertPicture(imgLogo,48,48,100,100)

It displays as expected.

IT doesn’t seem to like the graphics file (tried different PNG & JPG files) but if I use the MBS DynaPDF Picture example and make the picture one of the files it works perfectly!

I will fiddle more tonight. I will probably have a vanilla PDF create method and see if it plays nice. Thanks all.

Please email me an non working example file.
Maybe there is something special with images.

Thanks. Let me dig a bit, try a clean pdf method. Possible I’m messing myself up earlier with some initialization. The images work in your examples.

If I bang my head against the wall over the weekend I will let you know. Appreciate the response.

OK, it’s something connected to the “Supports Retina/HiDPI” setting.

Turn it off, and it works as expected. Turn it back on and my imgLogo (Picture) comes up blank in the PDF.

See if I can create a test example. Not sure if Xojo or DynaPDF at this point :frowning:

imgLogo with Retina on is not just a “picture”
with hidpi on it’s more than likely a multi representation image

[quote=284891:@Norman Palardy]imgLogo with Retina on is not just a “picture”
with hidpi on it’s more than likely a multi representation image[/quote]

I tried imgLogo.IndexedImage(0) and (1) and nilObjectException (hidpi on). (imageCount is 0)

Canvas and Imagewell are ok with just pure Picture.

Canvases & imagewells are “image aware” since they come from us

But imageCount being 0 is a problem - basically there’s no image

[quote=284893:@Norman Palardy]Canvases & imagewells are “image aware” since they come from us

But imageCount being 0 is a problem - basically there’s no image[/quote]

Oh, bug?

  dim dlgOpen As New OpenDialog
  dim tempPic As Picture
  dim fileLogo as FolderItem 
  dlgOpen.Filter = filetypesLogo.All
  fileLogo = dlgOpen.ShowModal
  
  if fileLogo <> nil then
    tempPic = Picture.Open(fileLogo)
    MsgBox ("Image Count is " + Str(tempPic.ImageCount))
    OpenPicture(fileLogo)
  end if

Loads JPG or PNG and reports back 0 all the time, however does draw in the canvas fine (as you mention image aware :slight_smile: ). 2016.2.1

(fyi, ImageCount reports 0 on hidpi on & off)

Hadnt read every post to realize you’re using things that should NOT be multi-representation anyways like JPG and PNG
A JPG or PNG should load as a plain old PICTURE so it makes sense it has an image count of 0 - its not a multi representation type
With hidpi on they get loaded as an immutable bitmap type ( see the DesktopHiDPISupport PDF in the documentation folder) With it off they are mutable
If this worked pre2016r2.1 then it should be the same as it was with hidpi off

When you run this little snippet and put a break point on the msgbox line what contents do you see in tempPic ?
You should see your JPG or PNG

What platform are you using ? Not that it should matter but you never know…

Well, I may add some code to detect the case of a HiDPI picture and pick the one with highest resolution automatically.

I read a lot of the documentation last night and came to same conclusion. If i breakpoint, the Picture contents are indeed correct.

If I manually create an ImageSet in the IDE and stuff the PNG in the 1x, 2x and 3x, DynaPDF shows the image. Oddly enough if I delete the image in 2x and 3x, nothing shows in the PDF, if I pop in a different graphic in the 2x, then the 1x shows.

So, as a workaround, can I programmatically change images in an imageset?

I think the problem I have is that the Picture is only that, a simple JPG or PNG so is not an imageset, and not a separate HiDPI one either, but DynaPDF InsertPicture thinks it is? (Possibly).

See the bit where I manually added images to an imageset in the IDE in my answer to Norman earlier. FYI, I have some graphics already in the project (drag and dropped a while ago so not imagesets) and they don’t show either in the PDF if HiDPI is enabled.

FYI, exact same symptoms in 2016 r1.1

I’ll see if I have a DynaPDF v3 plugin still kicking around.

Edit: Yup, same thing with v3 & v4 of the DynaPDF plugin. Guessing what it think a Picture is in HiDPI land isn’t what Xojo is giving it (or vice versa!) :slight_smile:

Christian, if you want I can try and knock up a simple project this weekend and email it to you that shows this?

The problem with HiDPI images is fixed for next prerelease.

Of course if you have a JPEG file already, you should use InsertImage with the file to pass it through and embed the JPEG directly.
That’s one of the good features in DynaPDF.

[quote=285025:@Christian Schmitz]The problem with HiDPI images is fixed for next prerelease.

Of course if you have a JPEG file already, you should use InsertImage with the file to pass it through and embed the JPEG directly.
That’s one of the good features in DynaPDF.[/quote]

Many thanks. I have the file but what I do, I uuEncode the small logo and save in the XML so any user can re-load it.

I tried loading the image into a MemoryBlock from Picture.GetData but when I do this call

call pdf.InsertImageFromBuffer(48,48, 100,100, mbNew)

I get a compiler error “There is more than one item with this name and it’s not clear to which it refers”, seems to think the MemoryBlock isn’t. (Docs show it can be a MemoryBlock or String). I added an index at the end as well and same error.

Appreciate the fast response and look forward to the next pre-release.