java - Convert HTML to PDF - Instantiated Object not visible -


i'm trying develop converter in java converts html file pdf file , found this site. on bottom of first page , second page there code examples on how realize such program libraries named on page 1 (jtidy, xalan, fop).

i created new maven project in spring tool suite , added library dependencies pom.xml. i've copied code parts newly created test program see if works. fine last code part.

public static byte[] fo2pdf(document fodocument) {     documentinputsource fopinputsource = new documentinputsource(                                                      fodocument);     try {         bytearrayoutputstream out = new bytearrayoutputstream();         logger log = new consolelogger(consolelogger.level_warn);         driver driver = new driver(fopinputsource, out);         driver.setlogger(log);         driver.setrenderer(driver.render_pdf);         driver.run();         return out.tobytearray();     } catch (exception ex) {         return null;     } } 

at first spring shown message when going cursor on documentinputsource

documentinputsource cannot resolved type

and there no option add specific library maven offers normally.

i tried different things, example putting code in different scope inside of class, creating own class , i've tried using ide, though doubt fault solved of these things , well, didn't obviously.

i've read fop library licensed under apache license version 2.0 , added license @ bottom of project, make sure it's not causing trouble, though didn't expect success again.

furthermore i've tried add library read necessary converted wasn't mentionend in article linked in beginning. library dom4j.

now, when go on documentinputsource spring shows me that:

the type documentinputsource not visible

this makes no sense me it's "normal method" inside of class , can see i've changed modifier private public in order make sure visible.

i feel i'm overlooking easy/basic , i'd grateful help. thank taking time read this.

ps: first post here on stack overflow , i'm new programming. if there's missing information; please tell me.

in link mentioned, documentinputsource class package org.apache.fop.tools.

there class name in package org.dom4j.io, package-private. if imported one, compiler warn class not visible (unless of course class in same package).

ensure have following line near beginning of source file :

import org.apache.fop.tools.documentinputsource;

and not 1 :

import org.dom4j.io.documentinputsource;

then, if says doesn't find class org.apache.fop.tools.documentinputsource (or package), missing fop dependency in pom :

<dependency>    <groupid>fop</groupid>    <artifactid>fop</artifactid>    <version>0.20.5</version> </dependency> 

the page found, , version of fop refers (0.20.5) rather old (may 2006, see here), , class looking not present more in recent versions of library. did use recent version in maven dependency ? explain first problem ("cannot resolved type").

i suggest upgrade latest stable version (2.1 dated jan. 2016, see here) , study examples official documentation here (in menu on left have "examples" section).

good luck ! :)


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -