Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtk4 example - showing a PDF a page #213

Open
mantielero opened this issue Dec 27, 2022 · 2 comments
Open

gtk4 example - showing a PDF a page #213

mantielero opened this issue Dec 27, 2022 · 2 comments

Comments

@mantielero
Copy link

I struggled a bit in order to display a PDF page using GTK4 and poppler. So this is for the record, just in case it might serve others:

import gintro/[gtk4, gobject, gio, poppler, cairo] 

proc drawEvent(widget: DrawingArea; context: Context; w, h: int) =#:bool {.discardable.} = #, userData: gpointer) =
  var doc  = newDocumentFromFile("file:////home/user/use/your/path/helloworld.pdf", nil)  # Any URL should work
  var page = doc.getPage(0)
  page.render(context)

proc appActivate(app: Application) =
  let window = newApplicationWindow(app)
  window.title = "GTK4 & Nim"
  window.defaultSize = (800, 600)

  let da = newDrawingArea()
  window.setChild(da)  
  da.setHExpand
  da.setVExpand  

  da.setDrawFunc(drawEvent)

  window.present

proc main =
  let app = newApplication("org.gtk.example")
  connect(app, "activate", appActivate)
  discard run(app)

main()

@StefanSalewski, don't hesitate to include it in the example folder if you find it useful.

I open and close the issue.

@mantielero
Copy link
Author

As I said, just for the record.

Cheers

@StefanSalewski
Copy link
Owner

Thanks for reporting. I think we should leave this issue open, as it may be useful for others. Indeed that is why I leave most issues open. I hope you will have some success with poppler. Note that you can always fine tune or expand the generated poppler.nim manually, I often do that for first tests, before I modify the generator script gen.nim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants