showing PDF in canvas has very bad quality

I am showing PDF files in a canvas, using a picture to do all drawing before copying the picture to the canvas to show it to the user. If I open the same PDF file in a viewer or in Adobe Reader it is much smoother.

What can I do to get the same smooth view in my Xojo 2019r2 project?

Thanks!

draw it using an htmlviewer. you must have some adobe reader web plugin somewhere in your system (at least on non mac os)
install adobe reader to have it also installed.

I need to see the PDF files in my Xojo app: it’s used to go through scanned files and select where to store them with projects, customers, etc. The viewing and reading itself we do with Adobe Reader.

The question is: How are you doing that? Code?
The usual suspect is that you’re not creating a HiDPI capable Picture… So just in case you’re creating your Picture like this: Var pic As New Picture(width, height), then change it to: self.TrueWindow.BitmapForCaching(width, height). It should then be properly set up with the correct ScaleFactor…

Providing an image (example) will also help.

If you open a PDF as a picture using Xojo, it takes the 72dpi low res thumbnail image.

they render the drawing instructions.

If you use an htmlviewer you might get better results
I use MBS plugins to render the drawing instructions to a hi res image if I need one.
Other PDF rendering solutions exist.

[quote=465350:@Jürg Otter]The question is: How are you doing that? Code?
The usual suspect is that you’re not creating a HiDPI capable Picture… So just in case you’re creating your Picture like this: Var pic As New Picture(width, height), then change it to: self.TrueWindow.BitmapForCaching(width, height). It should then be properly set up with the correct ScaleFactor…[/quote]

I think the problem is there somewhere since this project went HiDPI just a couple of weeks ago :wink:

Did you try MBS Xojo DynaPDF Plugin for this?

No, I don’t have any MB extensions installed.

[quote=465342:@Jean-Yves Pochez]draw it using an htmlviewer. you must have some adobe reader web plugin somewhere in your system (at least on non mac os)
install adobe reader to have it also installed.[/quote]

I used this method and it worked perfectly for the PDF files! Because my program must process pictures and PDF’s, I have created a selection method: for pictures I use the “old” method with a canvas and if the program detects a PDF file, it uses the HTMLviewer (which calls on the current standard PDF reader within the HTMLViewer). Much clearer PDF’s now!

Thanks everybody!

I made a containercontrol, with a pagepanel inside. on one page the canvas that displays jpegs, on the other page an htmlviewer to display pdf. check the file type when you set its value.

[quote=465342:@Jean-Yves Pochez]draw it using an htmlviewer. you must have some adobe reader web plugin somewhere in your system (at least on non mac os)
install adobe reader to have it also installed.[/quote]
Could someone pls share a code snippet? I don’t know HTML but would it look like this?

myHTMLViewer.LoadPage("<embed src=""file_name.pdf"" width=""800px"" height=""2100px"" />", nil)

Problem is my pdf data are contained in a string (created by ChartDirector), not a file, so how would I send a complete pdf string to HTMLViewer.LoadPage rather than a file reference?

I have the complete MBS set but DynaPDF is not included; there must be a simpler and less expensive way to simply render a pdf at hires in xojo?

Peter.

Personally I’d save the PDF data to a temporary file and open that in an HTMLViewer
Thats really simple
At least you get the magic of macOS and its willingness to open a PDF in an HTMLViewer for free

Otherwise you might try drawing the PDF to a really hi rez image
Create a new Picture and set the width & height really large and the DPI quite high then draw the PDF into that
That may give you a high rez image that renders better

Thx Norm,
Actually for anyone who needs this, after a little bit of experimenting, and based on tips above, the following works. Starting with pdf data in a string:

dim d as CGDataProviderMBS = CGDataProviderMBS.CreateWithData(PDFstring) dim p as CGPDFDocumentMBS = CGOpenPDFDocumentMBS(d) dim r as CGRectMBS=CGMakeRectMBS(0,0,myCanvas.Width,myCanvas.Height) self.pdfPicture = self.TrueWindow.BitmapForCaching(r.Width,r.Height) self.pdfPicture.Graphics.DrawCGPDFDocumentMBS p,r,1
then in myCanvas.Paint:

g.DrawPicture(self.pdfPicture, 0, 0)

Produces results even better than a pdf rendered in Preview.app. No scaling or large images required.

P.