Package com.jagpdf

Examples of com.jagpdf.Document


// ---------------------------------------------------------------------------
//             strings

    static void strings(String[] args)
    {
        Document doc = jagpdf.create_file(args[0] + "/jagpdf_doc_java_strings.pdf");
        doc.page_start(597.6, 848.68);
        Canvas canvas = doc.page().canvas();

        //[java_example_string
        /*` An example should make it clear. Let's load a standard ISO-8859-2
            encoded font. */
        Font helv = doc.font_load("standard; enc=iso-8859-2; name=Helvetica; size=24");
        canvas.text_font(helv);
        /*` One of the languages representable by this encoding is Czech. We can
          pass a Unicode string ['úplnÄ›k] (full moon). [lib] converts the string
          to ISO-8859-2 and it is shown correctly. */
        String full_moon_cze = "\u00fapln\u011bk";
        canvas.text(50, 800, full_moon_cze); // ok
        /*` If we pass Swedish ['fullmåne], letter ['å] will not be shown
         because ISO-8859-2 does not represent such character. We should have
         used ISO-8859-1 encoded font instead. */
        String full_moon_swe = "fullm\u00e5ne";
        canvas.text(50, 760, full_moon_swe); // wrong
        /*` Let's load a Unicode encoded TrueType font. */
        //<-
        /* //->
        Font dejavu = doc.font_load("enc=utf-8; file=DejaVuSans.ttf; size=24");
        //<- */
        String res_dir = testlib.getResourcesDir();
        String dejavu_file = res_dir + "/fonts/DejaVuSans.ttf";
        Font dejavu = doc.font_load("enc=utf-8; file=" + dejavu_file + "; size=24");
        //->
        canvas.text_font(dejavu);
        /*` Now we can mix Czech and Swedish and it will be shown correctly as
            [lib] converts the strings to UTF-8.*/
        canvas.text(50, 720, full_moon_swe);
        canvas.text(50, 680, full_moon_cze);
        //]

        doc.page_end();
        doc.finalize_doc();
    }
View Full Code Here


{
    public static void some_code() {
//->

MyStream myStream = new MyStream();
Document doc = jagpdf.create_stream(myStream);
//<-
    }
View Full Code Here

        //collect(5000, "done");
    }

    public static void do_it(String argv[]) {
        CustomStream my_stream = new CustomStream(argv[0] + "/basic_extstream.pdf");
        Document doc = jagpdf.create_stream(my_stream);
        my_stream = null;
        doc.page_start(5.9*72, 3.5*72);
        doc.page_end();
        doc.finalize_doc();
        doc = null;
    }
View Full Code Here

        static String horse = "\u017elu\u0165ou\u010dk\u00fd k\u016f\u0148 \u00fap\u011bl";
        static String horse3 = horse + ' ' + horse + ' ' + horse;


    public static void main(String argv[]) {
        Document doc = jagpdf.create_file(argv[0] + "/basic_text.pdf");
        doc.page_start(597.6, 848.68);
        Canvas canvas = doc.page().canvas();
        doc.outline().item(horse);
        // adobe core font
        Font font_14 = doc.font_load("standard;name=Times-Roman;size=12;enc=windows-1250");
        canvas.text_font(font_14);
        canvas.text(50, 800, horse);
        // true type
        String res_dir = testlib.getResourcesDir();
        String fspec = "enc=utf-8; size=12; file=" + res_dir + "/fonts/DejaVuSans.ttf";
        Font font_ttf = doc.font_load(fspec);
        canvas.text_font(font_ttf);
        canvas.text(50, 750, horse);
        // control rect
        canvas.rectangle(50, 200, 400, 450);
        canvas.path_paint("s");
        // justification
        justified_text(font_ttf, canvas, 600);
        justified_text(font_14, canvas, 550);

        // expected errors
        try {
            int[] arr_i = new int[10];
            canvas.text(0, 0, arr_i);
            assert false;
        } catch(IllegalArgumentException expected) {}

        try {
            byte[] arr_b = new byte[10];
            canvas.text(0, 0, arr_b);
            assert false;
        } catch(IllegalArgumentException excpected) {}

        // finalize
        doc.page_end();
        doc.finalize_doc();
    }
View Full Code Here

import com.jagpdf.JagPDFException;
import testlib.testlib;

public class basic_image {
    public static void main(String argv[]) {
        Document doc = jagpdf.create_file(argv[0] + "/basic_image.pdf");
        doc.page_start(597.6, 848.68);
        Canvas canvas = doc.page().canvas();
        String res_dir = testlib.getResourcesDir();
        String image_path = res_dir + "/images/lena.jpg";
        //
        // image format autodetection
        //
        Image img = doc.image_load_file(image_path);
        canvas.image(img, 50, 50);
        //
        // image format specification (tests enums as well)
        //
        Image img_enum = doc.image_load_file(image_path,
                                             ImageFormat.IMAGE_FORMAT_JPEG);
        canvas.image(img_enum, 310, 50);
        //
        // custom image
        //
        int img_dim = 7;
        byte[] checker_bytes = new byte[img_dim * img_dim];
        for(int i = 0; i < img_dim * img_dim; ++i)
        {
            if (i % 2 == 0)
                checker_bytes[i] = 0;
            else
                checker_bytes[i] = (byte)255;
        }
        ImageDef imgdef = doc.image_definition();
        imgdef.data(checker_bytes, img_dim * img_dim);
        imgdef.dimensions(img_dim, img_dim);
        imgdef.color_space(ColorSpaceType.CS_DEVICE_GRAY);
        imgdef.bits_per_component(8);
        imgdef.dpi(9, 9);
        imgdef.format(ImageFormat.IMAGE_FORMAT_NATIVE);
        Image img_custom = doc.image_load(imgdef);
        canvas.image(img_custom, 50, 310);
        //
        // bad format specification (tests exceptions as well)
        //
        try
        {
            Image img_err = doc.image_load_file(image_path,
                                                ImageFormat.IMAGE_FORMAT_PNG);
            throw new RuntimeException("JagPDFException expected.");
        }
        catch(JagPDFException exc)
        {
            // ok, as expected
        }

        // finalize
        doc.page_end();
        doc.finalize_doc();
    }
View Full Code Here

            my_stream = out_stream;
        }

        jagpdf.create_profile_from_string(s_profile);

        Document doc = jagpdf.create_stream(my_stream);
        doc.page_start(5.9*72, 3.5*72);
        Canvas canvas = doc.page().canvas();
        // meat
        String res_dir = testlib.getResourcesDir();
        String image_path = res_dir + "/images-jpeg/PalmTree-CMYK-icc-FOGRA27.jpg";
        Image img = doc.image_load_file(image_path);
        canvas.image(img, 50, 50);
        canvas.text(10, 10,
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        // -
        doc.page_end();
        doc.finalize_doc();
        doc = null;

//         if (out_stream == null)
//         {
//             // compare the the doc is ok
View Full Code Here

    //
    //
    //
    public static void main(String argv[]) {
            tests();
            Document doc = jagpdf.create_file(argv[0] + "/basic.pdf");
            doc.page_start(5.9*72, 3.5*72);
            doc.page_end();
            doc.finalize_doc();
    }
View Full Code Here

        profile.set("doc.static_file_id", "1");
        profile.set("info.static_producer", "1");
        profile.set("info.creation_date", "0");
        profile.set("stdsh.pwd_user", "user");
        profile.set("stdsh.pwd_owner", "owner");
        Document doc = jagpdf.create_file(argv[0] + "/encrypted.pdf", profile);
        doc.page_start(597.6, 848.68);
        Canvas canvas = doc.page().canvas();
        String res_dir = testlib.getResourcesDir();
        String image_path = res_dir + "/images/lena.jpg";
        // bookmark
        doc.outline().item(horse);
        // image
        Image img = doc.image_load_file(image_path);
        canvas.image(img, 50, 50);
        // adobe core font
        Font font_14 = doc.font_load("standard;name=Times-Roman;size=12;enc=windows-1250");
        canvas.text_font(font_14);
        canvas.text(50, 800, horse);
        // true type
        String fspec = "enc=utf-8; size=12; file=" + res_dir + "/fonts/DejaVuSans.ttf";
        Font font_ttf = doc.font_load(fspec);
        canvas.text_font(font_ttf);
        canvas.text(50, 750, horse);
        // finalize
        doc.page_end();
        doc.finalize_doc();
    }
View Full Code Here

    public static void main(String argv[]) {
        //<-
        /* //->
        Document doc = jagpdf.create_file("hello.pdf");
        //<- */
        Document doc = jagpdf.create_file(argv[0] + "/jagpdf_doc_hello.pdf");
        //->
        doc.page_start(597.6, 848.68);
        doc.page().canvas().text(50, 800, "Hello, world!");
        doc.page_end();
        doc.finalize_doc();
    }
View Full Code Here

TOP

Related Classes of com.jagpdf.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.