Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

PDF Sprite problem

edited July 2013 in General Posts: 66

The following code tries to display a full-page PDF of text. IT either shows nothing or one or two words.

Am I overusing the sprite pdf capability? is there a max size for the pdf?

Thanks

displayMode(FULLSCREEN)
    
function setup()     
    
    spriteMode(CORNER)
    page1l = image(400,600)    
    setContext(page1l)  
    sprite("Dropbox:Tikkun-01 3",0,0)  
end


function draw()     
    
 sprite(page1l,0,0)
    
end

Comments

  • edited July 2013 Posts: 391

    Try resetting your context by adding the line:



    setContext()



    Add this after you draw your sprite in page1l in setup()

  • Posts: 66

    Thanks @Slashin8r -- tried it, but no difference. One text pdf only shows 3 words, a second text pdf shows nothing.

  • Posts: 66

    @Simeon -- how robust is the PDF code in Codea? The PDFs in question come from InDesign, with about 20 different fonts in the file.

  • edited July 2013 Posts: 391

    If it is due to the size of the PDF, you can try making a test PDF that is much smaller and uses only a few fonts. Let me know the results, I'm definitely curious to see how you get it to work. In the meantime I will continue to test this as well.

  • I advise convert pdf to png

  • edited July 2013 Posts: 391

    Yeah it really seems like converting to an image such as png or jpg is the way to go.

    function setup()
        pdfImage = nil
        http.request("http://www.sciweavers.org/download/registration_form_1372951272.png", success)
    end
    
    function success(data, status, headers)
        pdfImage = data
    end
    
    function draw()
        background(20,20,40)
        if pdfImage ~= nil then
            sprite(pdfImage, WIDTH/2,HEIGHT/2)
        end
    end
    

    Original pdf file: http://northernicefastpitch.com/tournaments/9u/05252013_USSSA/registration_form.pdf


    Converted to png using an online pdf to image converter

  • Posts: 66

    I'd reached the same conclusion -- I wanted to use the PDF because 1) we update the PDF from time to time, and I'd rather not have the extra step of making a jpg 2) I'd like to find some lua code to read the content of the pdf -- something not possible with jpgs.

  • Posts: 66

    Some PDFs work, some don't. The one's that don't have one dimension greater than 1000

    I seem to recall some discussion of sprite size limit -- @Simeon, does that apply to PDF size as well? Even when scaled down? (I.E. the sprite is 400x600, the PDF is 792x1224)

  • Posts: 391

    What would happen if you tossed the PDF into a mesh and drew it that way instead?

  • Posts: 391

    @akiva, anyway you could share one or two of the PDFs you are using? I would love to see if I can recreate the issue you are experiencing.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Slashin8r - sprites are drawn using meshes anyway, no probably no difference

  • edited July 2013 Posts: 391

    Ah, so it really does seem like saving as an image is the only way to go as of now. Trying to find a good website that can convert PDF to image on the fly by use of a single URL. Then you could call an http.request for each PDF and have an image returned to be drawn.

  • Posts: 66

    I'm using an iPad 1 - i dont know if that's an issue....

    Since pdfs are size independent I'm wondering why/how codea's dropbox chooser determines the "size" of the image. From the internal thumbnail jpg? @Simeon?

  • Posts: 2,161

    When loading a PDF you can pass a second parameter to readImage to specify the width.

    I've had no problem with loading PDFs.

  • Posts: 66

    @Andrew_Stacey im using sprite to load the pdf - i tried adding width and height - still nothing

  • Posts: 2,161

    It's an issue with the new sprite batching code, I think.

    displayMode(FULLSCREEN)
    
    function setup()     
        img = readImage("Dropbox:Tikkun-01 4")
        spriteMode(CORNER)
        spriteBatching(false)
        page1l = image(400,600)    
    
        setContext(page1l)  
        background(29, 62, 59, 255)
        sprite(img,0,0,400)
        setContext()
    end
    
    
    function draw()     
        background(77, 77, 77, 255)
         sprite(img,0,0)
    
        sprite(page1l,0,0)
    
    end
    

    Try commenting out the spriteBatching = false line.

    Alerting @Simeon ...

  • Posts: 2,161

    Same if loading via sprite:

    displayMode(FULLSCREEN)
    
    function setup()     
        img = readImage("Dropbox:Tikkun-01 4")
        spriteMode(CORNER)
        spriteBatching(false)
        page1l = image(400,600)    
    
        setContext(page1l)  
        background(29, 62, 59, 255)
        sprite("Dropbox:Tikkun-01 4",0,0,400)
        setContext()
    end
    
    
    function draw()     
        background(77, 77, 77, 255)
         sprite(img,0,0)
    
        sprite(page1l,0,0)
    
    end
    
  • Posts: 66

    @Andrew_Stacey that works - but the pdf is much darker than the original.
    If i comment out the background in draw it doesnt work -

  • Posts: 2,161

    I think that the background of your PDF is rendering as partially transparent. I don't know if that is your PDF or the renderer.

  • Posts: 66

    Any idea why commenting out background causes it to not show up?

  • Posts: 66

    changing the background color solves the darkness -- I suspect the problem is the renderer (which makes sense if the main use is for games)

  • SimeonSimeon Admin Mod
    Posts: 4,957

    @Andrew_Stacey the rendered output is the same to me regardless of batching — I have fixed one other batching issue so that might have been it.

    I will submit a bug-fix update to address this and the Xcode export issue shortly, hopefully that will resolve any inconsistencies in rendering.

  • Posts: 66

    @Simeon if the transparency is a renderer issue would it be possible to make it optional? There are times when you don't want transparency

  • Posts: 391

    I'm glad to see this is showing some positive results now.



    Would it render the background transparent if your PDF had an image for its background? I currently don't have the software available to test this, but am curious to know how it works out.

  • Posts: 2,161

    When I look at the PDF in the sprite picker then it has a transparent background. With a PDF where I've explicitly set the background colour then I get that actual colour.

    I've just looked at two PDFs, one with an explicit white page colour and one with nothing. There is a definite difference between the two. So Codea is translating an empty background to transparent.

    Personally, I view this as a feature not a bug. To work around it, simply render your PDF to a white image first. Or run it through a shader that converts transparent pixels to white.

    One change that could be made would be to set the colour of the transparent pixels to white instead of black. Then you could use a blend mode to render a white background. As it is, they are black which means that (as far as I can tell), blend modes don't help (since we don't have the ability to specify constant colours in blends).

  • SimeonSimeon Admin Mod
    Posts: 4,957

    @akiva we simply use the internal iOS renderer to render the PDF into a texture that can be used on your geometry. If you would like to customise the background colour, then you can render a white (or other colour) background behind your PDF. This should be more flexible for you.

Sign In or Register to comment.