0

I am surfing the web-users pdf files from Domino Server. I have a template.pdf and a font file on my Java package to generate these pdf files without SAVING them on the server. However the PdfStamper requires me to use OutputStream which needs a path.

Does Domino Server have a temp space? Is there a different way to implement this? Is there a fake path to set?

As a test for now I'm saving it on my local machine.


package de.vogella.itext.write;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;

public class FillUpPDF {

    // Get the files from jar/package
    InputStream streamTemplate = getClass().getResourceAsStream("Template1.pdf");
    InputStream streamFont = getClass().getResourceAsStream("Ruritania.ttf");

    // Files
    public static final String sTemplate = "Template1.pdf";
    public static final String sResultPDF = "C:/Test/Bob Info.pdf";
    public static final String sResultFont = "Ruritania.ttf";

    // Manipulates a PDF file source with the file destination as result
    public void manipulatePdf(String src, String dest) throws IOException, DocumentException {

        // Read the Template
        PdfReader reader = new PdfReader(src);

        // Copy the template and output it to the destination
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));    //Where to fileoutputstream on Domino Server temporarily

        // Gets the fields on the form
        AcroFields form = stamper.getAcroFields();

        // Create and set the font
        BaseFont newFont = BaseFont.createFont(sResultFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        form.addSubstitutionFont(newFont);

        /* Filling up the fields on the form */
        form.setFieldProperty("text_1", "textfont", newFont, null);
        form.setFieldProperty("text_1", "textsize", new Float(9), null);
        form.setField("text_1", "Bob");

        form.setFieldProperty("text_2", "textfont", newFont, null);
        form.setFieldProperty("text_2", "textsize", new Float(9), null);
        form.setField("text_2", "Gates");

        form.setFieldProperty("text_3", "textfont", newFont, null);
        form.setFieldProperty("text_3", "textsize", new Float(9), null);
        form.setField("text_3", "Oct 17, 2013 at 11:00am");

        form.setFieldProperty("text_4", "textfont", newFont, null);
        form.setFieldProperty("text_4", "textsize", new Float(9), null);
        form.setField("text_4", "Cloud and Smarter Infrastructure");

        // Fixed the field
        stamper.setFormFlattening(true);
        stamper.setFreeTextFlattening(true);

        // Close
        stamper.close();
        reader.close();


       // Next Step: Send out the created pdf file to the user.


    }

    // Main method
    public void main(String[] args) throws Exception {
        FillUpPDF certification = new FillUpPDF();
        //certification.manipulatePdf(sTemplate, sResultPDF);
        certification.manipulatePdf(sTemplate, sResultPDF);
    }
}
4

1 に答える 1