AlivePdf create a map chart - actionscript

I'm building a pure actionscript project and would like to create a pdf with an map chart of the world to display my data.
It's possible to create a map and save as image and then embed in pdf with alivepdf?
package
{
import MyButton;
import flash.display.*;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.external.*;
import flash.net.*;
import flash.net.FileReference;
import flash.system.Security;
import flash.utils.ByteArray;
import org.alivepdf.display.*;
import org.alivepdf.fonts.*;
import org.alivepdf.layout.*;
import org.alivepdf.pdf.*;
import org.alivepdf.saving.*;
public class WorldTest extends Sprite
{
private var saveButton:MyButton = new MyButton();
// declared of logo or imagen on top of the PDF's document.
[Embed(source="FCMap_World.swf", mimeType="application/octet-stream" )]
protected var jpgBytes:Class;
protected var pdf:PDF;
public function WorldTest() {
saveButton.y = 0;
addChild(saveButton);
this.addEventListener(MouseEvent.CLICK, onMouseClickEvent);
}
protected function onMouseClickEvent(event:Event):void{
pdf = new PDF(Orientation.LANDSCAPE, Unit.MM, Size.LETTER);
pdf.setDisplayMode(Display.FULL_WIDTH);
pdf.addPage();
pdf.addImage(new jpgBytes() as DisplayObject, null, 0, 0, 0);
var bytes:ByteArray = pdf.save(Method.LOCAL);
var file:FileReference = new FileReference();
file.save(bytes, "myPDF.pdf");
}
}
}

It seems like you are trying to add swf file as image.
You need to make an image from it first.
var map : MovieClip = new jpgBytes();
var bitmapData : BitmapData = new BitmapData(map.width, map.height);
bitmapData.draw(map);
var bitmap : Bitmap = new Bitmap(bitmapData);
You can try to use another library called PDFcase for creating pdf in ActionScript.
This example shows how to add images to pdf.

Related

Integrate KoliBri web-components in Vaadin

I am trying to integrate KoliBri web-components (https://github.com/public-ui/kolibri) in a Vaadin project. I followed the documentation for web components integration (https://vaadin.com/docs/latest/create-ui/web-components) but I was not successful.
I want to integrate a KoliBri-button (kol-button) and therefor created getter and setter methods for the required properties of the button. When loading the website, the kol-button-component is loaded successfully from the .js file.
enter image description here
But the kol-button element in the DOM is empty and won´t show up:
enter image description here
Here is my KolButton.java:
package com.example.application.views.helloworld;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Synchronize;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
#Tag("kol-button")
#NpmPackage(value = "#public-ui/components", version = "1.1.10")
#JsModule("#public-ui/components/dist/components/kol-button")
public class KolButton extends Component {
public boolean getLabel() {
return getElement().getProperty("_label", false);
}
public void setLabel(String label) {
getElement().setProperty("_label", label);
}
public void setVariant(String variant) {
getElement().setProperty("_variant", variant);
}
public boolean getVariant() {
return getElement().getProperty("_variant", false);
}
}
And the view.java:
package com.example.application.views.helloworld;
import com.example.application.views.MainLayout;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteAlias;
#PageTitle("Hello World")
#Route(value = "hello", layout = MainLayout.class)
#RouteAlias(value = "", layout = MainLayout.class)
public class HelloWorldView extends HorizontalLayout {
public HelloWorldView() {
var kolButton = new KolButton();
kolButton.setLabel("TestText");
kolButton.setVariant("danger");
setVerticalComponentAlignment(Alignment.END, kolButton);
add(kolButton);
}
}
Do you have any idea to solve this? Thanks in advance

Itext html2pdf use converter for create personal Paragraph

But where do you change the font size of the method
HtmlConverter.convertToElements?
Why do I get this result with this code result code after execute ?
because the text between the tags does not change size ?
I also tried these solutions using the various methods (but the size does not change) :
https://stackoverflow.com/a/59044415/18323778
itext7 set font and size of HtmlConverter elements (In this question it is explained how to use the css too I am interested in changing only 2 properties of the element)
Run this code:
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDictionary;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.Style;
import com.itextpdf.layout.element.IElement;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.layout.properties.Property;
import com.itextpdf.layout.properties.UnitValue;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
/**
*
* #author UC9001309
*/
public class TestConvertHtml2pdf {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
PdfWriter pdfWriter = new PdfWriter("C:\\Temp\\" + new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()) + ".pdf");
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument);
FontProvider provider = new DefaultFontProvider(true, false, false);
ConverterProperties cvProp = new ConverterProperties();
cvProp.setFontProvider(provider);
cvProp.setImmediateFlush(true);
List<IElement> lst = HtmlConverter.convertToElements("Testo <b><u><i>prova</i></u></b> con tag",cvProp);
lst.get(0).setProperty(Property.FONT_SIZE,UnitValue.createPointValue(Float.parseFloat("20")));
Paragraph p = (Paragraph) lst.get(0);
p.setProperty(Property.FONT_SIZE,UnitValue.createPointValue(Float.parseFloat("20")));
document.add(p);
document.close();
}
}
i tried various methods but still don't get results, does anyone know how to fix ?
Thanks for your help .
The goal is to create a method in Itext 7 to pass as parameters a string with html tag and font and font size, get it translated by the html parser to apply bold, italics, uderline without setting them with Itex commands as paragraph. selBold ec ..
Because my colleagues get tired of programming.
After several attempts I solved this (I create a main to try):
package testconverthtml2pdf;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.IElement;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.font.FontProvider;
import com.itextpdf.layout.properties.UnitValue;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
/**
*
* #author UC9001309
*/
public class TestConvertHtml2pdf {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
// Future parameters of the method change it to test !!!
float vardim = 10.5f;
String tipofont =StandardFonts.COURIER.toString().toLowerCase();
String strInput = "Testo <b><u><i>prova</i></u></b> con tag";
// -------------------------------------------------------------
PdfWriter pdfWriter = new PdfWriter("C:\\Temp\\" + new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()) + ".pdf");
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument);
FontProvider provider = new DefaultFontProvider(true, false, false);
ConverterProperties cvProp = new ConverterProperties();
cvProp.setFontProvider(provider);
cvProp.setImmediateFlush(true);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<p style='font-family:"+tipofont +";font-size:"+UnitValue.createPointValue(vardim)+"'>") ;
stringBuilder.append(strInput) ;
stringBuilder.append("</p>") ;
System.out.println(stringBuilder);
List<IElement> lst = HtmlConverter.convertToElements(stringBuilder.toString(),cvProp);
Paragraph p = (Paragraph) lst.get(0);
document.add(p);
document.close();
}
}
To set Font and Font-Size to the input string I add a with a Style attribute inside for Font and Font-Size taken from parameter.
stringBuilder.append("<p style='font-family:"+tipofont +";font-size:"+UnitValue.createPointValue(vardim)+"'>") ;
tipofont -----> Font parameter
vardim -----> Font size parameter
I have to thank André Lemos who in his comment (lost because instead of modifying the question I deleted and recreated) gave me a solution because the bold was not created because the font type that had bold as its attribute was missing. I loaded Currier but not Currier-Bold.
If this solution can help anyone, it is available to the community.

How to convert PlanarImage or BufferedImage (JAI) to Image (JavaFX)

I am trying to change the image represented in an ImageView instance, after manipulating it with JAI. JAI can output a PlanarImage, RenderedImage(non-awt), or BufferedImage(non-awt), but these are not valid types for ImageView construction.
import java.awt.image.renderable.ParameterBlock;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.Interpolation;
public class A11 extends Application{
int zoom = 100;
ImageView img = new ImageView();
Image src = new Image("file.bmp");
public static void main(String args[]){
launch(args); // start application
}
#Override
public void start(Stage window){
ParameterBlock pb = new ParameterBlock();
pb.addSource(src); // source Image
pb.add(zoom/100); // xScale
pb.add(zoom/100); // yScale
pb.add(0.0F); // xTranslate
pb.add(0.0F); // yTranslate
pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
PlanarImage dest = JAI.create("scale", pb, null);
// NEED TO CONVERT 'dest' TO 'destImage' HERE
ImageView frame = new ImageView(destImage);
ScrollPane pane = new ScrollPane(frame);
window.setScene(new Scene(pane,800,600));
window.show();
}
}

iOS deve with Starling framework: take a screenshot and save it to the camera roll

I use flash for ios development and I use starling framework.
I'm trying to take a screenshot and then save it to the camera roll, but cameraRoll only accepts bitmapdata. How am I going to convert sprite to bitmapdata? Thanks a million!!
You can convert Sprite to BitmapData using BitmapData.draw() method.
Here's an example.
Try to get an byte array for this use can use Encoder like JPGEncoder or PNGEncoder from byte array you can easily convert to bitmapData.
And the code which i used for converting byte array to bitmapData is here. I hope it would be helpfull for you.If you send any byteArray by calling this class it would convert you bitmapData and return back using callBack Function.
package browsingImages
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.events.Event;
import flash.utils.ByteArray;
import scenes.Subscenes.KeepDiary;
public class BitmapDataConverter
{
// private var _KeepDiary:KeepDiary;
private var bmpData:BitmapData;
private var _loader:Loader;
private var _callB:Function;
public function BitmapDataConverter(byteArr:ByteArray,callB:Function)
{
_callB=callB;
getBitmapFunc(byteArr);
}
private function getBitmapFunc(bytArr:ByteArray):void{
if(bytArr != null){
bmpData = new BitmapData(100, 100, true,0xFFFFFF);
_loader = new Loader();
_loader.loadBytes(bytArr);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderAdded);
}
}
private function onLoaderAdded(eve:Event):void{
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaderAdded);
bmpData.draw(_loader);
bmpData = Bitmap(_loader.content).bitmapData;
if(_callB != null)
_callB(bmpData);
}
}
}
Actually, you cant use draw for starling's Sprite.
this code works for me:
public static function copyAsBitmapData(displayObject:DisplayObject, transparentBackground:Boolean = true, backgroundColor:uint = 0xcccccc):BitmapData
{
if (displayObject == null || isNaN(displayObject.width)|| isNaN(displayObject.height))
return null;
var resultRect:Rectangle = new Rectangle();
displayObject.getBounds(displayObject, resultRect);
var result:BitmapData = new BitmapData(displayObject.width, displayObject.height, transparentBackground, backgroundColor);
var context:Context3D = Starling.context;
var support:RenderSupport = new RenderSupport();
RenderSupport.clear();
support.setOrthographicProjection(0, 0, Starling.current.stage.stageWidth, Starling.current.stage.stageHeight);
support.applyBlendMode(true);
support.translateMatrix( -resultRect.x, -resultRect.y);
support.pushMatrix();
support.blendMode = displayObject.blendMode;
displayObject.render(support, 1.0);
support.popMatrix();
support.finishQuadBatch();
context.drawToBitmapData(result);
return result;
}

Actionscript 3 Load> Combine> and Save External Images

I'm new to actionscript 3, So Thank you in advance for any help you can give. Bascially what I'm trying to do is load 2 or more external images, all the same size and resolution, then combine or composite them one on top of the other, then save that result as a new image using a jpeg or png encoder.
I don't want to take a snapshot of the stage, I'd like to save the images with thier original resolution. So far the only thing I've been able to do is load two images, and composite them on the stage. thats about it.
Can someone please give some insight into how to accomplish this. I'm using flash pro CS5.5, and writing code in a class file, not on the timeline. Here is a copy of the code.
package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.ByteArray;
public class imageComposite extends MovieClip
{
var images:Array = ["koala.png","koala2.png"];//two images
public function imageComposite()
{
// constructor code
var thumbLoader:Loader;
for (var i:uint = 0; i < images.length; i++)
{
thumbLoader = new Loader;
thumbLoader.load(new URLRequest(("assets/" + images[i])));
addChild(thumbLoader);
}
thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,bmpData);
}
public function bmpData(evt:Event):void
{
trace("Event was completed successfully!");
}
}
}
First you put both the Loader objects into a separate "holder" object.
// constructor code
var holder:Sprite = new Sprite();
addChild(holder);
var thumbLoader:Loader;
for (var i:uint = 0; i < images.length; i++)
{
thumbLoader = new Loader;
thumbLoader.load(new URLRequest(("assets/" + images[i])));
holder.addChild(thumbLoader);
}
...
Later in your "complete" event handler:
var bitmapData:BitmapData = new BitmapData(holder.width, holder.height, false);
bitmapData.draw(holder);
var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
Then you can write this byteArray object to the server or to disk (desktop AIR application).
Thank you so very much for taking the time to offer your knowledge, it was more then helpful. The code you gave me worked perfectly with one exception. the "holder" variable has to be declared outside of the function. I got alittle bit of an access error, but when I placed it outside the function it worked just fine.
Anyway, i've expanded on the code adding the ability to save. I just put a movieClip on the the stage with instance name of "saveButt_mc". Then added the ability to save using fileReference. My goal is to have it autosave to a server using php, but for now this will have to do.
Heres my final code, thanks again for the help.
-D
package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.ByteArray;
import flash.display.Sprite;
import flash.net.FileReference;
import flash.net.FileFilter;
import com.adobe.images.PNGEncoder;
public class imageComposite extends MovieClip
{
var images:Array = ["koala.png","koala2.png"];//two images
var holder:Sprite = new Sprite();
public function imageComposite()
{
// constructor code
addChild(holder);
var thumbLoader:Loader;
for (var i:uint = 0; i < images.length; i++)
{
thumbLoader = new Loader ;
thumbLoader.load(new URLRequest(("assets/" + images[i])));
holder.addChild(thumbLoader);
}
//thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, bmpData);
saveButt_mc.addEventListener(MouseEvent.CLICK, bmpData);
addChild(saveButt_mc);
saveButt_mc.buttonMode = true;
}
//need contentLoaderInfo to access loader data;
public function bmpData(evt:Event):void
{
var bitmapData:BitmapData = new BitmapData(holder.width,holder.height,false);
bitmapData.draw(holder);
var byteArray:ByteArray = PNGEncoder.encode(bitmapData);
var file:FileReference = new FileReference();
file.save(byteArray, "newImage.jpg");
trace("Event was completed successfully!");
}
}
}

Resources