html to pdf

Post

Posted
Rating:
#1 (In Topic #1317)
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
I want to import part of a web page, specifically a <div class=xxx> node and store it in a database as a pdf blob. Can anyone give me a clue as to how to build the pdf "object"?

I can get the page and extract the node OK into a string, what I have never tried is converting that string to a pdf object inside the program code. In short I have no idea.
The node concerned is generally text but includes html tables etc, no diagrams. Essentially I'm trying to get the "information" from the page without all the page designer's beautiful surrounding garbage, aka useless crap.
The storing it in the database is also easy-peasy. So its just the pdf stuff, without losing the formats.

BTW, this arose because some internet idiot said it cant be done. Which seemed kind of stupid as most browsers have a "print selection to pdf file" available.


tia
the other bruce

Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
Generally and strictly wanting to use the resources of Gambas, you can create a PDF file with at least :? two modes:

- "<COLOR color="#800000">Output</COLOR>" property of the "Printer" class
   Stampare in Gambas - Gambas-it.org - Wikipedia

- by using "<COLOR color="#800000">gb.cairo</COLOR>" resources:
   Creare un file PDF con le risorse del Componente gb.cairo - Gambas-it.org - Wikipedia

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
Here is a quick example you can try. When it's finished, have a look at the PDF file in your Home folder.

Code (gambas)

  1. Public Sub Form_Open() ''Requires gb.cairo
  2.  
  3.   Dim pdf As CairoPdfSurface
  4.   Dim sMyText As String = "Hi there!"
  5.  
  6.   pdf = New CairoPdfSurface(User.Home &/ "MYprint.pdf", 50.8, 25.4)
  7.  
  8.   With Cairo
  9.     .Begin(pdf)
  10.     .Source = Cairo.ColorPattern(Color.White)
  11.     .Paint()
  12.     .Font.Name = "FreeSerif"
  13.     .Font.Size = 35
  14.     .Source = Cairo.ColorPattern(Color.Black)
  15.     .Font.Weight = .FontWeightBold
  16.     .MoveTo(5, 50)
  17.     .Text(sMyText)
  18.     .Fill()
  19.     .End
  20.  
  21.   pdf.Finish
  22.  

<IMG src="https://www.cogier.com/gambas/PDF_Example.png"> </IMG>
Online now: No Back to the top
1 guest and 0 members have just viewed this.