Save Picture to PDF?

Works for me. I think maybe when you changed s=s+ to sa.Append you’re joining with Join(sa). That adds spaces. You’ll want to use Join(sa, “”).

I’ve been working on the declares and finally read some of the docs. The declares are only for when you don’t use one of the 14 built in pdf fonts, but I’m getting out of bounds in Toby’s routine anyways. So I don’t know how that’s supposed to work out. Plus his docs go into some more convoluted things that have to be done to use non-builtin fonts. If you limit the fonts to just those 14 then it’s all Xojo and should be xplat. Will check out Bobs code next :slight_smile:

I am joining with a null string. Very strange…

What kind of picture object are you writing out??? I like the way Toby wrote his code to mimic the Xojo methods. So if I can get his to work, I’m all for that. Makes it really flexible.

This is the change to picture making

[code]pdfImageObject
Function imageBitmap() As string
dim sa() as string //**edit s=s+ to sa.Append

sa.Append chr(c.red)+chr(c.green)+chr(c.blue)

sa.Append chr(c.red)+chr(c.green)+chr(c.blue)

return Join(sa, “”)

End Function[/code]

And to test I made a screen grab, renamed testpic and added this code just above p.nextPage

[code]Window2.Pushbutton1

dim pp As Picture = Picture.Open(SpecialFolder.Desktop.Child(“testpic.png”))
p.drawPicture(pp, 20, 20)

p.nextPage 792,612
…[/code]

[quote=148281:@Will Shank]This is the change to picture making

[code]pdfImageObject
Function imageBitmap() As string
dim sa() as string //**edit s=s+ to sa.Append

sa.Append chr(c.red)+chr(c.green)+chr(c.blue)

sa.Append chr(c.red)+chr(c.green)+chr(c.blue)

return Join(sa, “”)

End Function[/code]

And to test I made a screen grab, renamed testpic and added this code just above p.nextPage

[code]Window2.Pushbutton1

dim pp As Picture = Picture.Open(SpecialFolder.Desktop.Child(“testpic.png”))
p.drawPicture(pp, 20, 20)

p.nextPage 792,612
…[/code][/quote]

OK. Something is very odd then. What OS are you running? I’m on Yosemite.

Because when I try to read in a PNG file and use your example, it get a blank PDF. When I read in a JPEF file - I get junk in the PDF image.

Why are we getting different results???

OS X can do it, nd you need a Windows equivalent ?

Print PDF or Write PDD or… Sorry I do not recall what I used to make like in OS X a print to PDF on Windows.

I made a google search, found something, try it and adopted it.

Only draw back: I do not have a mac to get its name.

A Windows solution exists and it is free.

[quote=148337:@Emile Schwarz]OS X can do it, nd you need a Windows equivalent ?

Print PDF or Write PDD or… Sorry I do not recall what I used to make like in OS X a print to PDF on Windows.

I made a google search, found something, try it and adopted it.

Only draw back: I do not have a mac to get its name.

A Windows solution exists and it is free.[/quote]

That’s from the Print Dialog - yes? I’m talking about doing it in code.

The code Bob provided the link to does work. The draw back is that I have to first save an image file, then read that file back in to generate the PDF. There are no “Picture” to PDF functions in that class. i suppose it could be modified somehow.

Toby’s class is really nice in that it has methods that call just like Xojo’s graphics class. However, I get garbage from the output. William Shank says he’s getting it to work fine. So I’m doing something wrong…

The problem seems to be the size of the picture. I used a pretty small image the first time so I tried a bigger one and now see the distortion, like it’s being torn rightwards. With a small 172x53 image it comes out ok.

Haven’t looked into the logic of the code too much, no idea how picture size could make a difference. I’ve already removed all the non-standard font stuff and now maybe drawpicture too as I only need vector lines really.

Something to consider is that pdf has lots of features. A supported third party solution lets you start now and probably has much more of the pdf stuff you don’t really need but once you have it you’ll probably find uses. Also, Toby’s code does work but some of the bits I’ve seen… uh, logically sound I guess but inefficient.

I just tried a small image and still got junk! Anyhow, yeah, Toby’s code is slow. The other project seems to work pretty fast. I’ve managed to generate a PDF from my report image. I now need to get things scaled properly and all.

And as for a supported 3rd party solution, yeah, I agree. I’m likely going to buy the OmegaBundle which has Christian’s DynaPDF classes in it. That’s obviously the best. But part of why I’m going through this whole headache and mess is to learn anyhow!

Thanks. Enjoy the bundle and DynaPDF Starter.

even the starter version can do a lot. Different image formats, pass through JPEG embedding, compression of PDF content, vector graphics, font embedding, CMYK/RGB/Gray, web- and page links, text formatting and much more.

[quote=148400:@Christian Schmitz]Thanks. Enjoy the bundle and DynaPDF Starter.

even the starter version can do a lot. Different image formats, pass through JPEG embedding, compression of PDF content, vector graphics, font embedding, CMYK/RGB/Gray, web- and page links, text formatting and much more.[/quote]

I’ve downloaded the plugin to try it out and see how it works in the debugger.

My biggest challenge now is taking my canvas and scaling it properly to fit on a page and also to break up the content into multiple pages should the need arise.

I can suggest to look DBReportPDF, is free. Or if you require scale/resize i had code for this, just post a PM.

[quote=148416:@Jon Ogden]I’ve downloaded the plugin to try it out and see how it works in the debugger.

My biggest challenge now is taking my canvas and scaling it properly to fit on a page and also to break up the content into multiple pages should the need arise.[/quote]

Have you seen https://forum.xojo.com/17885-howto-create-a-pdf-document-with-use-of-debenu-free-pdf-library ?

Very interesting. I’ll try yet another solution! I was afraid it was Windows only but it appears it isn’t…

Well, after a weekend of messing around with all the different PDF routines (as well as repairing my water heater and watching my daughters dance with the Moscow Ballet in a performance of the Nutcracker), I have decided that DynaPDF is the way to go here.

DynaPDF gave the best quality output from my picture objects that received the content that I drew in them. It’s not perfect and I can still seem some pixelation when zooming in, but it is better than the results I get with fPDF. fPDF looked very nice, but I was not happy with the image quality. Plus I had to save a JPEF to disk and then read it back in. I know Bernardo’s DBReports methods have direct image import functions, but as his code uses fPDF, I don’t think the results would be any better. Michel, I did not try the Debenu library. Looked like it would have been a lot of declares for OS X. And Toby’s classes never gave me the images I tried to convert.

So it looks like DynaPDF wins. I’ll be ordering the Bundle later today…

DynaPDF has a lot of options. e.g. the Image to pdf.rbp example shows a couple of them.
if you do right, JPEGs are just embedded as they are.

else be sure to use SetResolution, SetUseTransparency, SetSaveNewImageFormat and SetCompressionFilter.

e.g. save bitmap with compression filter none for best results.

Thanks, Christian. I discovered that I needed to set transparency on my picture objects to opaque as I just go a black image in the PDF otherwise. So I learned that - stupid Alpha channel! :slight_smile:

What’s the best way to simply embed a Xojo picture object. I create picture objects containing mostly text drawn with DrawString and a few embedded graphics.

I could probably draw everything natively into the PDF, but as I am already drawing it to the picture objects to display on a canvas, it seems to be a lot of extra work…

you certainly get better quality with drawing directly in PDF. The canvas has a low resolution normally.

normally something like:

call d.SetSaveNewImageFormat(false) // if possible pass through call d.SetUseTransparency(false) // no transparent color call d.SetCompressionFilter(d.kcfFlate) // no compression call d.SetResolution(300) // max resolution

to define parameters and than call Insertpicture passing Picture object.

OK. Thanks. I will try those!

[quote=149337:@Christian Schmitz]you certainly get better quality with drawing directly in PDF. The canvas has a low resolution normally.
[/quote]

Also, I’m drawing to a picture object. Not a canvas. I’m later adding the pictures to the canvas to view my report. But the drawing is done in picture objects that are twice the resolution of the users selected page size.

Hi Jon,

You could check the DBReportPDF repository? I’ve changed the way of storing images. It could try with:

Dim pdf As New DBReportPDF
...
pdf.DrawPicture yourPicture, 300, 300, Picture.QualityMax
...