Designer for libHaru

728 views
Skip to first unread message

Mike Adkins

unread,
May 21, 2013, 2:27:34 PM5/21/13
to libHaru
Hello.

I am working on my second pdf utilizing libHaru. The product is
great, so thanks to all the devs that have worked on it.

Maybe I am missing something, but it seems as if my pdf design is all
trial and error. Basically I write the code to create the rectangle
and run my app to see if it looks right. This seems cumbersome and
most of the time not correct. I was wondering how other devs do their
development. Is there a designer that would help the user create the
pdf (code to create the pdf). I was thinking of something to Adobe
Acrobat, but have a button to generate the code hpdf syntax after you
are done creating the pdf.

Thanks for your thoughts.
Mike

Koen Deforche

unread,
May 22, 2013, 7:21:43 AM5/22/13
to lib...@googlegroups.com
Hey Mike,
What we are doing is designing as HTML/CSS and rendering to PDF using libHaru.

There are plenty of WYSIWYG editors for HTML, including web-editors, and there are obvious benefits if using HTML.

To render HTML/CSS we have developed a layout engine (Wt Render librarywhich is bundled with Wt but can be used separately) which is quickly improving to become CSS2 compliant. It was initially meant to support everything that is supported by the TinyMCE editor but we are thus expanding its feature set.

Regards,
Koen

Franco Marchesini

unread,
May 22, 2013, 8:14:45 AM5/22/13
to lib...@googlegroups.com
Hello Koen,

This line of code has impressed me, why do not extract a HTMLRender() function to include in libharu?

Now I will study this framework did not know before.

Ciao
Franco

renderer.render("<p style=\"background-color: #c11\">Hello, world !</p>");


2013/5/22 Koen Deforche <koen.d...@gmail.com>

--
--
---
libHaru.org development mailing list
To unsubscribe, send email to libharu-u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "libHaru" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libharu+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Koen Deforche

unread,
May 22, 2013, 9:33:25 AM5/22/13
to lib...@googlegroups.com
Hey Franco,


It's not part of libharu since the main part of it (the layout engine) is actually independent of libharu (it can be used for any WPaintDevice), and more dependent on internal utility functions in Wt (XHTML parsing, stylesheet/CSS parsing, font matching, ...).

Also note that the license different: Wt is using a dual licensing model (GPL or commercial license).

Regards,
koen 

Franco Marchesini

unread,
May 22, 2013, 10:38:55 AM5/22/13
to lib...@googlegroups.com
Ciao Koen,

very intriguing :-)



2013/5/22 Koen Deforche <koen.d...@gmail.com>

--

Mike Adkins

unread,
May 22, 2013, 11:11:02 AM5/22/13
to lib...@googlegroups.com
That really is intriguing.  Not really what I was hoping for, but I can see how that would be beneficial.  Thank you!

Mike

Mike Adkins

unread,
May 22, 2013, 8:19:43 PM5/22/13
to lib...@googlegroups.com
I decided to make a small tool to allow you to make the page layout and the tool spits out the libharu code to create the PDF.

I did it in vb.net and it is based on an open source tool. At this point it is only doing rectangles, which is all I really need. I will post the code download link when I get the bugs out.

I can't believe no one has posted something like this before, I know I can't be the first to want it.

Mike

Bill Horger

unread,
May 22, 2013, 11:20:52 PM5/22/13
to lib...@googlegroups.com
Mike,

Can you give a few more clues as to what you're trying to accomplish?

Bill


Mike Adkins

unread,
May 23, 2013, 12:52:45 AM5/23/13
to lib...@googlegroups.com
Essentially, I want to duplicate a a form that is already made. The problem is the form in an image and not in HTML or PDF format, so there really is no conversion. So the only option I really have is write the code in libharu to generate the form, which I have done, but it is a tedious and time consuming task to make sure all the coordinates for the rectangles are correct. So originally, I wanted to know how other devs would complete this task.

Does that explain the issue any better. Like I said, I wrote a tool that outputs the libharu code needed to generate the code, but this is only for rectangles and lines.

Thanks.
Mike

Bill Horger

unread,
May 23, 2013, 8:52:12 AM5/23/13
to lib...@googlegroups.com
Yes, Mike, that makes sense. It certainly is tedious to hand construct elements, especially graphic ones.

While there may be a more generic solution, if you have several forms to create, and the basic format of an element is definable (i.e. a rectangular box that follows text, a box that fits underneath text, etc.), one can construct generic code that will allow some flexibility in building elements that can be "stacked" (called sequentially) in the code to create the forms.

The biggest headache is keeping track of where things are so that the next element uses the previous position to select the starting location of the text/graphic element.

I don't know if this is helpful or not; I do know that, sometimes, discussion will spark a thought that can help.

Hoping this is a spark,
Bill



Mike

Richard Brett

unread,
May 23, 2013, 8:45:50 PM5/23/13
to lib...@googlegroups.com
Hi

  I have some code we put together that takes a .DOCX file or .HTML file and renders them to PDF using Libharu.  (The docx converter is better than html by far) to solve a need to convert document templates (eg purchase order layout) to a real/final document in PDF (it includes variable# row subsitution).  It is not highly general purpose, especially as the DocX format spec is > 5,000 pages.  It gets used by end-users creating "documents"/templates using Word, and the intermediate software converting that to PDF (via Libharu).  We did a lot of work decoding Docx, but libharu is used "as-is".

I mention this in the spirit of this thread, so people know what it out there, but it doesnt help Mike and his "image" format.

Cheers
.Richard

Ameen Mancheri

unread,
Sep 12, 2013, 5:15:33 AM9/12/13
to lib...@googlegroups.com
Shall I know how to use Wt Render Library separate from Wt? We just need an HTML to PDF converstion feature, not the entire one.

Koen Deforche

unread,
Sep 16, 2013, 3:24:01 AM9/16/13
to libHaru
Hey,

2013/9/12 Ameen Mancheri <ameen.m...@gmail.com>:
> Shall I know how to use Wt Render Library separate from Wt? We just need an
> HTML to PDF converstion feature, not the entire one.

If you've got Wt installed, then you can use the PDF renderer
independently from the rest of the web toolkit.

See below for an example that converts a HTML file to PDF.

Regards,
koen

#include <fstream>

#include <Wt/Render/WPdfRenderer>
#include <hpdf.h>

using namespace Wt;

void error_handler(HPDF_STATUS error_no,
HPDF_STATUS detail_no,
void *user_data) {
fprintf(stderr, "libharu error: error_no=%04X, detail_no=%d\n",
(unsigned int) error_no, (int) detail_no);
}

void htmlToPdf(const std::string& file)
{
HPDF_Doc pdf = HPDF_New(error_handler, 0);
HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL);
HPDF_UseUTFEncodings(pdf);
HPDF_Page page = HPDF_AddPage(pdf);
HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);

Wt::Render::WPdfRenderer renderer(pdf, page);

/*
* Only needed if Wt is not linked against libpango
*/
renderer.addFontCollection("/usr/share/fonts/truetype");
renderer.setMargin(2.54);
renderer.setDpi(96);
renderer.setFontScale(1);

std::ifstream f(file.c_str(), std::ios::in | std::ios::binary);

if (!f)
throw std::runtime_error(std::string("Could not read input file ") + file);

f.seekg(0, std::ios::end);
int length = f.tellg();
f.seekg(0, std::ios::beg);

boost::scoped_array<char> xhtml(new char[length + 1]);
f.read(xhtml.get(), length);
xhtml[length] = 0;

renderer.render(WString::fromUTF8(xhtml.get()), 0);

std::string pdfName = file.substr(0, file.length() - 4) + "pdf";
HPDF_SaveToFile(pdf, pdfName.c_str());
HPDF_Free(pdf);
}

int main(int argc, char **argv)
{
htmlToPdf(argv[1]);
}

Franco Marchesini

unread,
Sep 23, 2013, 6:26:32 AM9/23/13
to lib...@googlegroups.com
Ciao Richard,

it's sound good!!.

Can you share your code?

I'm trying to write something like reportlab (pdf rendering from xml).

Best regards
Franco



2013/5/24 Richard Brett <rbr...@fieldpine.co.nz>
Reply all
Reply to author
Forward
0 new messages