How to get the list of embedded fonts in a PDF?

View: New views
5 Messages — Rating Filter:   Alert me  

How to get the list of embedded fonts in a PDF?

by Hashim Saleem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

Can I use itextSharp to retrieve all the embedded fonts in a PDF? If so, which class to look at?

Regards,
Hashim Saleem

Re: How to get the list of embedded fonts in a PDF?

by Paulo Soares :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

BaseFont.GetDocumentFonts().

Paulo

> -----Original Message-----
> From: itextsharp-questions-bounces@...
> [mailto:itextsharp-questions-bounces@...]
> On Behalf Of Hashim Saleem
> Sent: Monday, April 07, 2008 2:42 PM
> To: itextsharp-questions@...
> Subject: [itextsharp-questions] How to get the list of
> embedded fonts in a PDF?
>
>
>
> Hi,
>
> Can I use itextSharp to retrieve all the embedded fonts in a
> PDF? If so,
> which class to look at?
>
> Regards,
> Hashim Saleem

Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions

Re: How to get the list of embedded fonts in a PDF?

by bjorgvino :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Do you know why BaseFont.GetDocumentFonts() always returns an empty ArrayList in my code?
I have a PDF template with embedded fonts (Document Properties->Fonts in Acrobat Reader tells me I have the embedded font in the file, Type: TrueType, Encoding: Ansi) and I'm trying to get the embedded fonts with the following code:
..
string template = context.Server.MapPath(templateUrl);
PdfReader pdfReader = new PdfReader(template);
ArrayList fonts = BaseFont.GetDocumentFonts(pdfReader);
..

The pdfReader is working and I can create a new PDF from the template but fonts.Count == 0 every time!

Please help!
Bjorgvin.

Paulo Soares wrote:
BaseFont.GetDocumentFonts().

Paulo

> -----Original Message-----
> From: itextsharp-questions-bounces@lists.sourceforge.net
> [mailto:itextsharp-questions-bounces@lists.sourceforge.net]
> On Behalf Of Hashim Saleem
> Sent: Monday, April 07, 2008 2:42 PM
> To: itextsharp-questions@lists.sourceforge.net
> Subject: [itextsharp-questions] How to get the list of
> embedded fonts in a PDF?
>
>
>
> Hi,
>
> Can I use itextSharp to retrieve all the embedded fonts in a
> PDF? If so,
> which class to look at?
>
> Regards,
> Hashim Saleem


Aviso Legal:

Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.



Disclaimer:

This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.




-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Register now and save $200. Hurry, offer ends at 11:59 p.m.,
Monday, April 7! Use priority code J8TLD2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions

Re: How to get the list of embedded fonts in a PDF?

by Paulo Soares :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Without seeing the pdf your guess is as good as mine.

Paulo

> -----Original Message-----
> From: itextsharp-questions-bounces@...
> [mailto:itextsharp-questions-bounces@...]
> On Behalf Of bjorgvino
> Sent: Thursday, May 15, 2008 4:18 PM
> To: itextsharp-questions@...
> Subject: Re: [itextsharp-questions] How to get the list of
> embedded fonts in a PDF?
>
>
> Do you know why BaseFont.GetDocumentFonts() always returns an
> empty ArrayList
> in my code?
> I have a PDF template with embedded fonts (Document
> Properties->Fonts in
> Acrobat Reader tells me I have the embedded font in the file, Type:
> TrueType, Encoding: Ansi) and I'm trying to get the embedded
> fonts with the
> following code:
> ..
> string template = context.Server.MapPath(templateUrl);
> PdfReader pdfReader = new PdfReader(template);
> ArrayList fonts = BaseFont.GetDocumentFonts(pdfReader);
> ..
>
> The pdfReader is working and I can create a new PDF from the
> template but
> fonts.Count == 0 every time!
>
> Please help!
> Bjorgvin.
>
>
> Paulo Soares wrote:
> >
> > BaseFont.GetDocumentFonts().
> >
> > Paulo
> >
> >> -----Original Message-----
> >> From: itextsharp-questions-bounces@...
> >> [mailto:itextsharp-questions-bounces@...]
> >> On Behalf Of Hashim Saleem
> >> Sent: Monday, April 07, 2008 2:42 PM
> >> To: itextsharp-questions@...
> >> Subject: [itextsharp-questions] How to get the list of
> >> embedded fonts in a PDF?
> >>
> >>
> >>
> >> Hi,
> >>
> >> Can I use itextSharp to retrieve all the embedded fonts in a
> >> PDF? If so,
> >> which class to look at?
> >>
> >> Regards,
> >> Hashim Saleem

Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions

Re: How to get the list of embedded fonts in a PDF?

by bjorgvino :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, I have managed to get the fonts working...but now when I use the font and call doc.NewPage() I get an error. The code is below and I'll try to upload the pdf template I'm using. What am I doing wrong here?

protected void Page_Load(object sender, EventArgs e)
{
//Should embedded font be used?
const bool useEmbeddedFont = true;

//Create new document and write to memory
Document doc = new Document(PageSize.A4, 36, 36, 120, 36);
MemoryStream pdf = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, pdf);
doc.Open();

//Set up reader to read template
string template = Server.MapPath(TemplateSourceDirectory + "/nabble_test.pdf");
PdfReader reader = new PdfReader(template);

//Add template to document
PdfImportedPage page = writer.GetImportedPage(reader, 1);
PdfContentByte content = writer.DirectContent;
content.AddTemplate(page, 0, 0);

//Get font
ArrayList fonts = BaseFont.GetDocumentFonts(reader);
BaseFont font;
string text;
if (fonts.Count > 0 && useEmbeddedFont)
{
        //Use first font
        Object[] obj = (Object[])fonts[0];
        font = BaseFont.CreateFont((PRIndirectReference)(obj[1]));
        text = "Document font.";
}
else
{
        font = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        text = "Helvetica";
}

//Write some text to first page using document font
Paragraph p1 = new Paragraph(text, new Font(font));
doc.Add(p1);

//Create a new page and add the template again
doc.NewPage(); //if useEmbeddedFont this fails!
content.AddTemplate(page, 0, 0);

//Write some text to second page using document font
Paragraph p2 = new Paragraph(text, new Font(font));
doc.Add(p2);

doc.Close();
reader.Close();
writer.Close();
}
nabble_test.pdf

Without seeing the pdf your guess is as good as mine.

Paulo
LightInTheBox - Buy quality products at wholesale price