Adding Document title in the titlebar instead of filename

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Adding Document title in the titlebar instead of filename

avchavan
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();
        }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding Document title in the titlebar instead of filename

avchavan
writer.setViewerPreferences(PdfAWriter.DisplayDocTitle);

added the above line to make it work.
Loading...