Documents for Excel, Java Edition Documentation
Manage File Operations / Export to a PDF File / Support Document Properties
In This Topic
    Support Document Properties
    In This Topic

    GcExcel provides support for document properties while saving Excel spreadsheets to PDF documents. The document properties contain the basic information about a document, such as title, author, creation date, subject, creator, version etc. You can store such useful information in the exported PDF document. 

    The DocumentProperties class contains the methods such as setPdfVersion, setTitle, setAuthor, setSubject, setKeywords, setCreator, setProducer, setCreationDate and setModifyDate.

    Using Code

    Refer to the following example code to add document properties in the exported PDF document.

    Java
    Copy Code
    Workbook workbook = new Workbook();
    // Fetch default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    worksheet.getRange("A1").setValue("GrapeCity Documents for Excel");
    worksheet.getRange("A1").getFont().setSize(25);
    
    // Load an image from a specific file in input stream
    InputStream inputStream = ClassLoader.getSystemResourceAsStream("grapecity.png");
    try {
        byte[] bytes = new byte[inputStream.available()];
        // Read an image from input stream
        inputStream.read(bytes, 0, bytes.length);
    
        // Add background image of the worksheet
        worksheet.setBackgroundPicture(bytes);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    
    PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
    // Print the background picture in the centre of exported pdf file
    pdfSaveOptions.setPrintBackgroundPicture(true);
    
    // Saving workbook to pdf
    workbook.save("12-PrintBackgroundPicture.pdf", pdfSaveOptions);