Remove defaultStyle from PDFDomTree - java

I like to convert pdf document into html content. I am using PDF2Dom lib version 2.0.3
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.18</version>
</dependency>
Conversion works, so I wont paste my code... but I like to remove that blue border line from the html document.
If I open PDFDomTree source, I see defaultStyle is protected:
https://github.com/radkovo/Pdf2Dom/blob/main/src/main/java/org/fit/pdfdom/PDFDomTree.java
Is there anyway to overwrite it, or any suggestion for another tool.

Related

CSS unsupported key issue in iText pdf conversion

I'm trying to create a pdf file using iText in Java. My HTML consists of CSS bootsrap version v4.3.1. During the conversion, I'm getting an error like this ERROR c.i.s.c.p.s.CssParserStateController - The rule #-webkit-keyframes is unsupported. All selectors in this rule will be ignored.
I'm trying with Java HTML to pdf conversion using iText 7.1.9 maven dependency. How can I avoid these errors or include this CSS tag?. Since it is loading from the bootstrap I can't change that.
My Code:
ConverterProperties props = new ConverterProperties();
props.setMediaDeviceDescription(new MediaDeviceDescription(MediaType.PRINT));
props.setCssApplierFactory(new DefaultCssApplierFactory());
HtmlConverter.convertToPdf("input.html", new FileOutputStream("output.pdf"), props);
I couldn't find any perfect solution to the above, but I updated my HTML by removing unwanted resources, and that works for me.

If I want to use autoit how can I use in maven project

Which is the best way to upload file in selenium webdriver with java?
--using send keys
--using autoit
--using robot class
If I want to use autoit how can I use in maven project
Can I upload file in selenium webdriver without giving hardcode path?
Yes you can use autoit in maven project.
String getLocation=Constant.currentDirectory+"\\testExplorer.exe "+ uploadFileName;
Runtime.getRuntime().exec(getLocation);
Here uploadfilename is the name of the file that you want to upload
You can create .exe file by using AutoIt Editor.By using the following code you can parameterise the filename that you want to upload
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1",$CmdLine[1])
ControlClick("Open","","Button1")
Use below two dependencies in to your pom-
Note: by using Jcob API, you can actually directly write/copy paste autoit script(s) in your selenium code without having it as complied executable exe script..
<dependency>
<groupId>autoitx4java</groupId>
<artifactId>autoitx4java</artifactId>
<version>1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.hynnet/jacob -->
<dependency>
<groupId>com.hynnet</groupId>
<artifactId>jacob</artifactId>
<version>1.18</version>
</dependency>
How to use it example-
1.Keep Jacob dll in to your project path and set its path as below-
System.setProperty(LibraryLoader.JACOB_DLL_PATH,
System.getProperty("user.dir") +
"/automation/src/test/java/externalLib/jacob-
1.20-x64.dll");
click on the upload/choose file in ur app with regular selenium click-
clickOnElement(findElementByXpath(chooseFileBtn));
wait(2);
Now write your code (you need autoIt installed for this and capture script) like below-
AutoItX autoIt = new AutoItX();
String title = "Open";
Assert.assertTrue(autoIt.winWaitActive(title, "Open", 20));
autoIt.controlSend(title, "", "Edit1", filePath);
autoIt.controlClick(title, "", "Button1");
Note: AutoIt Controls [controlSend, and controlClick ] will work directly from our code now, and do the job.

Ghost4j not using default ghostscript installation

I'm using Ghost4j to render PDFs, but it throws the following sorts of errors sometimes when trying to render documents that were created by MS Word
[main] ERROR org.ghost4j.Ghostscript - GPL Ghostscript 9.18: Some glyphs of the font TimesNewRoman requires a patented True Type interpreter.
According to this thread this may be due to the Ubuntu Ghostscript package leaving out certain fonts. So I compiled the latest Ghostscript (9.22) from source and installed it, and it's now the version that comes up when I use the gs command, but Ghost4j still seems to be using the old 9.18 version.
How can I tell it to use the new version of Ghostscript?
Ghost4j doesn't use the ghostscript installation per se, instead both ghost4j and ghostscript use a library called libgs.so. This library is a dependecy of ghostscript but also comes with an installation called libgs-dev (on Linux).
I am suspecting that somehow Ghost4j uses some leftower version of the library.
So if you are using the latest version of Ubuntu installing libgs-dev should solve the problem, however all current stable versions of Linux default to the 9.18
We solved this problem by manually building that library and symlinking the version we need to the libgs.so file. You can download the compiled dynamically linked version 9.22 of libgs.so here(personal dropbox link) save it under /usr/lib/x86_64-linux-gnu/libgs.so.9.22 and run
ln -fs /usr/lib/x86_64-linux-gnu/libgs.so.9.22
/usr/lib/x86_64-linux-gnu/libgs.so
and, if one does not trust strangers on the internet like one shouldn't here are the instructions for building it yourself:
(tutorial for building gs),
(gs source code).
To make sure everything else is the same we use Ghost4j 1.0.1 and JNA 4.1.0
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.ghost4j</groupId>
<artifactId>ghost4j</artifactId>
<version>1.0.1</version>
</dependency>
While solving this problem I found this endpoint method to be really usefull:
#RequestMapping(value = "/gs/version", method = GET)
public GhostscriptRevision gsVersion() throws IOException {
return Ghostscript.getRevision();
}
Good luck.

Compilation error in Node.getTextContent for jdk 6

java Source code not compiling with jdk 6.
import org.w3c.dom.Node;
Node node = list.item(0);
String txtContent = node.getTextContent();
getTextContent() not found in the jdk 6
how can solve this compilation issue.
I came here with the same problem. Even worse: I had two projects side by side, both targetting the same JRE (1.6), and one was able to resolve Node.getTextContent() while the other wasn't. I resolved it sort of by accident; I went to project properties | Java Build Path | Order and Export tab, selected the JRE (which was at the bottom of the list) and clicked the "Top" button to move it to the top. My problem went away. It appears that the Node I wanted was hidden by another one. :-\ Maybe this will help with your problem.
Although a late post... maybe someone will find this useful.
I didn't like the manual project setting with JRE on top because all my colleagues would have to go trough this every time the project was imported, so I found another solution.
In my case I had the following dependency tree: org.reflections (0.9.8) -> dom4j (1.6.1) -> xml-apis (1.0.b2).
In order to fix it, I added an exclusion in the org.reflections dependency, like this:
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.8</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
In your case maybe there is another dependency that imports a faulty jar. E.g.: Dealing with "Xerces hell" in Java/Maven?
Please check http://www.jarfinder.com/index.php/java/info/org.w3c.dom.Node to see all the jars that contain that class.
I have also faced the similar problem. It is nothing to do with the Source Code. Steps to solve the problem is,
Go to project Properties (Right click on project and choose properties)
Select Java Build Path
Go to Order and Export tab
Make sure your JRE library is on TOP. If it is not in top, make it to top.
Click on OK and see after completing the build progress in right down.
For anyone working with hibernate the solution is similar to virussu_ro above.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
Possibly a long shot, but are you sure you're using JDK 6? Sometimes IDEs like Eclipse have a dropdown in the Project window that lets you choose a version, and it may be set to 1.4. Or you may have your CLASSPATH set incorrectly. Worth checking if you have ever had Java 1.4 installed.
I ask because Node.getTextContent was added in JDK 1.5, so the only way I can explain its absence is that you are using the Java 1.4 version of org.w3c.dom.Node.
Try running this code to determine location of jar:
System.out.println(System.getProperty("java.version"));
ProtectionDomain domain = org.w3c.dom.Node.class.getProtectionDomain();
System.out.println("domain: " + domain);
CodeSource codeSource = domain.getCodeSource();
if(codeSource != null) {
System.out.println("location: " + codeSource.getLocation());
} else {
System.out.println("null location, probably JRE class");
}
Maybe there is a jar on classpath that contains org.w3c.dom.Node class and hides the correct one.

How to use YUI calendar in Java Wicket?

My question is not so hard, i think. But it does not change the fact that i dont know how to do it :) Anyway, how can i use yui calendar object in my wicket page? i have tried some codes in java codes, but i got some errors, so i need your precious help. Thanks.
Its is as simple as this:
...
import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
...
DateTextField df = new DateTextField('wicketID', dateModel, "yy.DD.mm");
df.add(new DatePicker());
form.add(df);
Basicaly, you construct a normal DateTextField and add the YUI Picker to it. thats about all.
enjoy
Edit: to answer the questions in the comments:
user500129: are you using maven as build tool? i strongly suggest it to you. if you do, you find the yoi components in the wicket-datetime artefact. The relevant maven dependency is:
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>${wicket.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
If you are not using maven, you can download the jar from the maven repository, for wicket.14.14 this would be the correct link: http://mvnrepository.com/artifact/org.apache.wicket/wicket-datetime/1.4.14
hope that helps

Categories