showing PDF in canvas has very bad quality

  1. 2 weeks ago

    Mario v

    Nov 29 Netherlands

    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!

  2. Jean-Yves P

    Nov 29 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    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.

  3. Mario v

    Nov 29 Netherlands

    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.

  4. Jürg O

    Nov 29 Pre-Release Testers, Xojo Pro

    @Mario vGinneken using a picture to do all drawing

    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...

  5. Emile S

    Nov 29 Europe (France, Strasbourg)

    Providing an image (example) will also help.

  6. Jeff T

    Nov 29 Pre-Release Testers Midlands of England, Europe

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

    in a viewer or in Adobe Reader

    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.

  7. Mario v

    Nov 29 Netherlands

    @Jürg O 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...

    I think the problem is there somewhere since this project went HiDPI just a couple of weeks ago ;-)

  8. Christian S

    Nov 29 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    Did you try MBS Xojo DynaPDF Plugin for this?

  9. Mario v

    Nov 29 Netherlands

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

    @Jean-YvesPochez 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 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!

  10. Jean-Yves P

    Nov 29 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    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.

  11. @Jean-YvesPochez 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.

    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.

  12. Norman P

    Dec 3 Pre-Release Testers, Xojo Pro under THE bus

    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

  13. 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.

or Sign Up to reply!