Batik - put SVG on top of image - java

I have an image file (jpg, etc.) and some svg drawings (svg tag copied from the site, as Java String). The svg drawing is of the same resolution as the image file. I want to put svg drawings on top of the image and save it as one file. My approach, of which I'm not proud of, but works, is to:
use Batik's JPEGTranscoder to transcode svg into image with this svg drawings and white background, save this image
put the image with svg drawings on top of my image file by perfoming low level operations on each pixel
I would like to be able to put the svg drawings on top of my image in one step.

Using an SVG pattern would solve your problem.
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="200" height="200">
<defs>
<pattern id="image" x="0" y="0" patternUnits="userSpaceOnUse" height="200" width="200">
<image x="0" y="0" width="200" height="200"
xlink:href="http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png"/>
</pattern>
</defs>
<rect width="200" height="200" fill="url(#image)"/>
<circle cx="100" cy="100" r="50"/>
</svg>
Fiddle available here.
I pulled the SVG above through the batik rasterizer, and it was correctly rasterized.
Update
As noted in the comments, you could just as well include the image directly in your SVG, without the use of a pattern.
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="200" height="200">
<image x="0" y="0" width="200" height="200"
xlink:href="http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png"/>
<circle cx="100" cy="100" r="50"/>
</svg>
Fiddle available here.

Related

making a 4 stop gradient in android's xml

I tried using inkscape's mesh gradient but it seems not supported in android, I need something like this:
a 4 stop gradient for android's rectangle(or any other shape, like a circle), basically 4 blends of gradient color. How do I do this in android? Or atleast by something that android supports( is illustrator's svg output taken by android)?
You can approximate it using multiple gradients. This is just a quick attempt to get something close. You may be able to do better with a little extra tweaking.
<svg width="250" viewBox="0 0 100 100">
<defs>
<linearGradient id="grad1" x1="0" y1="1">
<stop offset="0" stop-color="rgb(149,254,149)"/>
<stop offset="1" stop-color="rgb(255,254,149)"/>
</linearGradient>
<radialGradient id="grad2" cx="0" cy="0" r="0.75">
<stop offset="0" stop-color="rgba(254,151,149, 1)"/>
<stop offset="1" stop-color="rgba(254,151,149, 0)"/>
</radialGradient>
<radialGradient id="grad3" cx="1" cy="1" r="0.75">
<stop offset="0" stop-color="rgba(149,150,202, 1)"/>
<stop offset="1" stop-color="rgba(149,150,202, 0)"/>
</radialGradient>
</defs>
<rect width="100" height="100" fill="url(#grad1)"/>
<rect width="100" height="100" fill="url(#grad2)"/>
<rect width="100" height="100" fill="url(#grad3)"/>
</svg>

How to display Vietnamese in PDF what exported by Jasper report correctly?

I am using these dependencies
implementation ('net.sf.jasperreports:jasperreports:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-fonts:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-functions:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-metadata:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-fonts:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-annotation-processors:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-chart-themes:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-chart-customizers:6.9.0')
implementation ('net.sf.jasperreports:jasperreports-custom-visualization:6.9.0')
compile 'com.lowagie:itext:2.1.7.js5'
with Jasper report for Eclipse 2019.6 . Vietnamese character display in error
Java code
#RequestMapping(value = "/ca_audit/minute_pdf", method = RequestMethod.GET)
public void generatePDFCashAuditMinute() throws JRException {
JasperReport jasperReport = JasperCompileManager.compileReport("D:/vy/template.jrxml");
Map<String, Object> parameters = new HashMap<>();
parameters.put("p1", "Example joint stock company"); // Tên tổ chức
parameters.put("p2", "EXKK002"); // Số biên bản
parameters.put("p3", 26); // Ngày
JRDataSource jrDataSource = new JREmptyDataSource();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, jrDataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, "D:/foo/out.pdf");
}
The content of file *.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="bien_ban_kiem_ke_quy_a4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="7098c966-5c92-43e3-a729-b3d486fc858b">
<parameter name="p1" class="java.lang.String"/>
<parameter name="p2" class="java.lang.String"/>
<parameter name="p3" class="java.lang.Integer"/>
<queryString>
<![CDATA[select 1 as id]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<title>
<band height="84" splitType="Stretch">
<textField>
<reportElement x="14" y="6" width="100" height="30" uuid="2106c35d-3d5e-4203-950a-54a87b6952ea"/>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$P{p1}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="376" y="23" width="64" height="16" uuid="77d41a67-82d2-46d0-9a3e-5327ae3b450b"/>
<text><![CDATA[Số biên bản:]]></text>
</staticText>
<textField>
<reportElement x="440" y="23" width="50" height="16" uuid="a505da46-48af-4dcb-84bc-f9d27697919d"/>
<textFieldExpression><![CDATA[$P{p2}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="260" y="47" width="34" height="13" uuid="541c25ed-4b29-4cc4-a19d-05f295ae0340"/>
<text><![CDATA[ngày]]></text>
</staticText>
<textField>
<reportElement x="290" y="47" width="40" height="13" uuid="72e64426-d702-4694-bc25-81a2f3e43f82"/>
<textFieldExpression><![CDATA[$P{p3}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
I create file jasperreports.properties in classpath
In Eclipse IDE (with Jaspersoft module)
How to fix it?
It's a font issue. Not a PDF encoding problem. Maybe try to use Arial Unicode MS
Inside your tag add the following
<font fontName="Arial Unicode MS" size="11" pdfFontName="Arial Unicode MS" pdfEncoding="Identity-H"/>
Also make sure that Arial font extension jar in class path. Search internet for arial font extension jar.
Try this:
Do not set a PDF Font Name for the font family that you created with the Arial ttf. You don't want to use Helvetica because it doesn't include glyphs for Vietnamese characters. Leave it empty so that the Arial ttf is used in PDF.
Set the PDF Encoding for the font family to Identity-H (Vietnamese uses horizontal writing).
The screenshot shows that the font family is called "times", so you'll have to use <font fontName="times"/> for the text element.
This will result in the Arial ttf being embedded in the PDF file (a subset of it actually) and used for the text. Therefore the PDF would show the Vietnamese characters, as long as the Arial ttf includes glyphs for them (and my Arial ttf copy does).
If for some reason you don't want to embed Arial in the PDF file, you can also use the DejaVu fonts included in net.sf.jasperreports:jasperreports-fonts:6.9.0, for instance <font fontName="DejaVu Sans"/>
You might also want to set the net.sf.jasperreports.default.pdf.encoding property to Identity-H, if you generally want to embed fonts in PDFs, or just leave it unset and specify the PDF encoding for each font family.
File jasperreports.properties
net.sf.jasperreports.default.pdf.encoding=UTF-8
net.sf.jasperreports.export.character.encoding=UTF-8
https://community.jaspersoft.com/wiki/custom-font-font-extension
https://freefontsdownload.net/download/36926/arial-unicode-ms.zip
https://learn.microsoft.com/vi-vn/typography/font-list/arial-unicode-ms
What is the purpose of the 'Pdf embedded' option of the Static Text element in iReport 5.6.0?

Unable to access jpg in jsp

There are two image files in my webcontent/images folder the_logo.jpg and logo.png
I am able to access the .png file
<img alt="Powerpay1" src="./images/logo.png" width="250" height="50" />
but unable to access the .jpg file
<img alt="Powerpay" src="./images/the_logo.jpg" width="250" height="50" />
How should I solve this?
Feel free to ask if any other information is needed.
NOTE : I am using Apache tomcat.
use
<img alt="Powerpay1" src="../images/logo.png" width="250" height="50" />
<img alt="Powerpay1" src="../images/the_logo.jpg" width="250" height="50" />
This code will take the cursor to the previous folder.
If you have two nested folder, use ../../ or three nested folders, use ../../../and so on to go to the root of the directory and browse respectly.
instead of
<img alt="Powerpay1" src="./images/logo.png" width="250" height="50" />
<img alt="Powerpay1" src="./images/the_logo.jpg" width="250" height="50" />
One more best way to doing it by using scriptlets
Ex:
<%
String base = request.getContextPath() + "/";
if (base == null || base.isEmpty()) {
base = "/";
}
%>
<img alt="Powerpay1" src="<%=base%>images/logo.png" width="250" height="50" />
Apache configuration can allow specific suffixes. see mod_suffix
File in linux should be in a path as /etc/httpd/conf/httpd.conf
Try changing your files match patterns to add jpg:
<FilesMatch "\.(png|**jpg**|gif|css|php|html|js)$">
allow from all
</FilesMatch>

nested exception is java.lang.NoClassDefFoundError: org/apache/batik/anim/dom/SVGDOMImplementation error

I included below code in xsl-fo document:
<fo:instream-foreign-object>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20">
<g style="fill:red; stroke:#000000">
<rect x="0" y="0" width="15" height="15"/>
<rect x="5" y="5" width="15" height="15"/>
</g>
</svg>
</fo:instream-foreign-object>
i need to create a pdf ,I am using fop 1.0,batik-all-1.8pre-r1084380.
While running the xsl fo code ,i got the following error.
nested exception is java.lang.NoClassDefFoundError: org/apache/batik/anim/dom/SVGDOMImplementation
Kindly help.

Which swing tool is used?

I have a java program installed on my computer that creates Forms and can later print it. I want to do something similar with my program! In the source folders of this program, I found folders for the specific forms. Each folder containes a image for e.g named Payment.png and a xml file is structured like this:
<?xml version="1.0" encoding="windows-1250" standalone="no"?>
<form xmlns:xinclude="http://www.w3.org/2001/XInclude" blankodruck="true" filename="Payment.png" saveAndPrintButtonEnabled="true" scale="1.0" title="Payment" window_height="725" window_width="860" paper="A5" orientation="landscape">
<printscale sx="0.432" sy="0.434"/>
<printoffset x="0" y="13"/>
<model class="de.hans.client.app.form.payment.PaymentModel" />
<printform filename="Payment.png" pngscaleX="1" pngscaleY="1"/>
<offset x="-20" y="15" scaleX="0.72" scaleY="0.7" printOffsetX="4" printOffsetY="3" printScaleX="2.34" printScaleY="2.33">
<xinclude:include href="../Header.xml"/>
</offset>
<checkbox height="33" name="Paydaten_ChB" width="35" x="862" y="74" printOffsetX="0" printOffsetY="0"/>
<checkbox columns="90" height="35" ...
<textfield columns="1" height="36" name="quartal" width="35" x="1235" y="72" printOffsetX="0" printOffsetY="0"/>
<radiobutton group="Gender" height="36" name="User_gender" tooltip="men" width="33" x="1253" y="130" printOffsetX="0" printOffsetY="0"/>
It has even a barcode-field:
<barcode length="886" type="3" px="430" py="180" pages="1">
<invisible name="date"/>
<invisible name="titel"/>
Can somebody guess how this printable swings are created in the program? Thanks

Categories

Resources