Search in sources :

Example 1 with RandomAccessSourceFactory

use of com.itextpdf.io.source.RandomAccessSourceFactory in project i7js-highlevel by itext.

the class C03E19_PagedImages method createPdf.

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    Document document = new Document(pdf);
    Image img;
    // Animated GIF
    URL url1 = UrlUtil.toURL(TEST1);
    List<ImageData> list = ImageDataFactory.createGifFrames(url1);
    for (ImageData data : list) {
        img = new Image(data);
        document.add(img);
    }
    // JBIG2
    URL url2 = UrlUtil.toURL(TEST2);
    IRandomAccessSource ras2 = new RandomAccessSourceFactory().createSource(url2);
    RandomAccessFileOrArray raf2 = new RandomAccessFileOrArray(ras2);
    int pages2 = Jbig2ImageData.getNumberOfPages(raf2);
    for (int i = 1; i <= pages2; i++) {
        img = new Image(ImageDataFactory.createJbig2(url2, i));
        document.add(img);
    }
    // TIFF
    URL url3 = UrlUtil.toURL(TEST3);
    IRandomAccessSource ras3 = new RandomAccessSourceFactory().createSource(url3);
    RandomAccessFileOrArray raf3 = new RandomAccessFileOrArray(ras3);
    int pages3 = TiffImageData.getNumberOfPages(raf3);
    for (int i = 1; i <= pages3; i++) {
        img = new Image(ImageDataFactory.createTiff(url3, true, i, true));
        document.add(img);
    }
    document.close();
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) RandomAccessFileOrArray(com.itextpdf.io.source.RandomAccessFileOrArray) ImageData(com.itextpdf.io.image.ImageData) TiffImageData(com.itextpdf.io.image.TiffImageData) Jbig2ImageData(com.itextpdf.io.image.Jbig2ImageData) RandomAccessSourceFactory(com.itextpdf.io.source.RandomAccessSourceFactory) IRandomAccessSource(com.itextpdf.io.source.IRandomAccessSource) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) Image(com.itextpdf.layout.element.Image) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) URL(java.net.URL)

Example 2 with RandomAccessSourceFactory

use of com.itextpdf.io.source.RandomAccessSourceFactory in project i7j-pdfsweep by itext.

the class PdfCleanUpTool method parseDAParam.

private Map<String, List> parseDAParam(PdfString DA) throws IOException {
    Map<String, List> commandArguments = new HashMap<String, List>();
    PdfTokenizer tokeniser = new PdfTokenizer(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(DA.toUnicodeString().getBytes(StandardCharsets.UTF_8))));
    List currentArguments = new ArrayList();
    while (tokeniser.nextToken()) {
        if (tokeniser.getTokenType() == PdfTokenizer.TokenType.Other) {
            String key = tokeniser.getStringValue();
            if ("RG".equals(key) || "G".equals(key) || "K".equals(key)) {
                key = "StrokeColor";
            } else if ("rg".equals(key) || "g".equals(key) || "k".equals(key)) {
                key = "FillColor";
            }
            commandArguments.put(key, currentArguments);
            currentArguments = new ArrayList();
        } else {
            switch(tokeniser.getTokenType()) {
                case Number:
                    currentArguments.add(new PdfNumber(new Float(tokeniser.getStringValue())));
                    break;
                case Name:
                    currentArguments.add(new PdfName(tokeniser.getStringValue()));
                    break;
                default:
                    currentArguments.add(tokeniser.getStringValue());
            }
        }
    }
    return commandArguments;
}
Also used : PdfTokenizer(com.itextpdf.io.source.PdfTokenizer) RandomAccessFileOrArray(com.itextpdf.io.source.RandomAccessFileOrArray) PdfName(com.itextpdf.kernel.pdf.PdfName) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) RandomAccessSourceFactory(com.itextpdf.io.source.RandomAccessSourceFactory) ArrayList(java.util.ArrayList) List(java.util.List) PdfNumber(com.itextpdf.kernel.pdf.PdfNumber) PdfString(com.itextpdf.kernel.pdf.PdfString)

Aggregations

RandomAccessFileOrArray (com.itextpdf.io.source.RandomAccessFileOrArray)2 RandomAccessSourceFactory (com.itextpdf.io.source.RandomAccessSourceFactory)2 ImageData (com.itextpdf.io.image.ImageData)1 Jbig2ImageData (com.itextpdf.io.image.Jbig2ImageData)1 TiffImageData (com.itextpdf.io.image.TiffImageData)1 IRandomAccessSource (com.itextpdf.io.source.IRandomAccessSource)1 PdfTokenizer (com.itextpdf.io.source.PdfTokenizer)1 PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)1 PdfName (com.itextpdf.kernel.pdf.PdfName)1 PdfNumber (com.itextpdf.kernel.pdf.PdfNumber)1 PdfString (com.itextpdf.kernel.pdf.PdfString)1 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)1 Document (com.itextpdf.layout.Document)1 Image (com.itextpdf.layout.element.Image)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1