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
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”.
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.
[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 ). 2016.2.1
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…
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.
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!)
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
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.