I would like to know whether its possible to use the document title in the
titlebar when the PDF is opened instead of the filename appearing in it?
If yes, then how to achieve it?
Here's the code i tried & it shows list.pdf in the titlebar of the PDF
reader (Adobe) instead of the document's title.

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ICC_Profile;
import com.itextpdf.text.pdf.PdfAConformanceLevel;
import com.itextpdf.text.pdf.PdfAWriter;
import com.itextpdf.text.pdf.PdfAction;
import com.itextpdf.text.pdf.PdfAnnotation;
import com.itextpdf.text.pdf.PdfBorderDictionary;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.xml.xmp.DublinCoreProperties;
import com.itextpdf.text.xml.xmp.PdfProperties;
import com.itextpdf.text.xml.xmp.XmpWriter;
import com.itextpdf.xmp.XMPException;


public class TitleTest {

        public static void main(String[] args) throws IOException,
DocumentException, XMPException {
                Document document = new Document();
                PdfAWriter writer = PdfAWriter.getInstance(document, new
FileOutputStream("list.pdf"), PdfAConformanceLevel.PDF_A_1A);
                writer.setViewerPreferences(PdfAWriter.PageModeUseOutlines);
                writer.setRunDirection(PdfAWriter.RUN_DIRECTION_LTR);
                writer.setTagged(PdfAWriter.markAll);
                writer.createXmpMetadata();
                XmpWriter xmp = writer.getXmpWriter();

                DublinCoreProperties.addSubject(xmp.getXmpMeta(),
"Subject");
                DublinCoreProperties.setTitle(xmp.getXmpMeta(), "Title",
"en_US", "en_US");
                DublinCoreProperties.setDescription(xmp.getXmpMeta(),
"Description", "en_US", "en_US");
                PdfProperties.setKeywords(xmp.getXmpMeta(), "Keywords");
                PdfProperties.setVersion(xmp.getXmpMeta(), "1.4");
                document.addTitle("Title");
                document.addLanguage("en_US");
                document.open();
                Font font1 = FontFactory.getFont("ROsanswebtextregular.ttf",
BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
                ICC_Profile icc = ICC_Profile.getInstance(new
FileInputStream("sRGB Color Space Profile.icm"));
                writer.setOutputIntents("Custom", "",
"http://www.color.org";, "sRGB IEC61966-2.1", icc);
               
                Chunk c = new Chunk("Google", font1);
                PdfAction action = new PdfAction("https://google.com";);

                PdfAnnotation annotation = PdfAnnotation.createLink(
                writer, new Rectangle(0 ,0), PdfName.HIGHLIGHT,
                action);
                annotation.put(PdfName.CONTENTS, PdfName.TEXT);
                annotation.setBorderStyle(new PdfBorderDictionary(0,
PdfBorderDictionary.STYLE_BEVELED));
                c.setAnnotation(annotation);
                document.add(c);
                document.close();
        }
} 



--
View this message in context: 
http://itext.2136553.n4.nabble.com/Adding-Document-title-in-the-titlebar-instead-of-filename-tp4660898.html
Sent from the iText mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to