Discussion:
[iText-questions] Need help for Character Spacing in existing pdf
Shafi hameed
2013-03-13 09:40:01 UTC
Permalink
I have a pdf file in which all the contents are in Arial font. my
requirement is to set a space between every character. eg. i want to change
'HELLO' as 'H E L L O'.
The follwing code adds some text with given amount of charecter spacing
var pdfStamper = new PdfStamper(pdfReader, new FileStream(outPutFname, FileMode.Create));
"winansi", BaseFont.EMBEDDED);
AcroFields pdfFormFields = pdfStamper.AcroFields;
PdfContentByte cb = pdfStamper.GetOverContent(1);
cb.SetCharacterSpacing(2);//Set amount of space you want
cb.SetFontAndSize(customfont, 16);
cb.BeginText();
cb.ShowText("Test");
cb.EndText();
pdfStamper.FormFlattening = false;
pdfStamper.Close();
pdfReader.Close();
But I have to set space on existing text in the pdf, while this code will
add new text ("test") in the pdf.
please help me. thanks in advance.
--
*Thanks & Regards

Shafi**
Sr. Software engineer** | Propalms Network Pvt Ltd. Pune
*
http://www. <http://www.tlcinfotech.co.in/>propalmsnetwork.com<***@propalmsnetwork.com>|
***@propalmsnetwork.com
8600335990
mkl
2013-03-13 10:09:36 UTC
Permalink
Shafi hameed,
I have a pdf file in which all the contents are in Arial font. my
requirement is to set a space between every character. eg. i want to
change 'HELLO' as 'H E L L O'.
Unless you only need to do that for the single PDF you mentioned (or a some
PDFs internally very similar), that is a hell of an assignment. And as your
title in your footer says that you are a "Sr. Software engineer", I'm
inclined to doubt that this is only an excercise with only one target PDF...

Some questions, therefore:

1. Do you really only need to process that one PDF you mentioned? Or only
PDFs internally very similar? In these cases, please provide that PDF.

2. Can the text content of the PDFs in question be considered parsable?

3. How wide should that space be? The width of a regular space character?
Some custom width? A width to calculate from font size and style?

4. Inserting a space makes text lines longer. Does your assignment include
reflowing lines which afterwards would reach beyond some margin? In that
case, are the margins and the general page structure known?

5. When copying and pasting text from your PDF, shall that text also
include the spaces?

6. Does your assignment involve shifting annotations and jump targets which
might be considered anchored relative to certain page content?

Depending on the answers there may follow more questions still.

Regards, Michael



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Re-Need-help-for-Character-Spacing-in-existing-pdf-tp4657800p4657801.html
Sent from the iText - General mailing list archive at Nabble.com.
Shafi hameed
2013-03-13 10:34:12 UTC
Permalink
Actually my basic requirement is to change the font of existing pdf into
'Braille' (Braille.ttf is a true type font basically for blind people)
I want to select any PDF file and want to change all its font into Braille.
as I did not findno easy method to change the existing text font, I did
some trick to change all the text's font into Braille.
every thing worked fine for me but another problem occurred, since The
width of Braille font is greater than the actual font's width which
resulted the overlapping of character. file fully converted
into Braille font but there is very less distance between two character.
so I thought if I could set a spacing between two character, my problem
would be solved.

OR
please tell me any easer way to change the all text fonts into Braille or
any selected font.
Post by mkl
Shafi hameed,
I have a pdf file in which all the contents are in Arial font. my
requirement is to set a space between every character. eg. i want to
change 'HELLO' as 'H E L L O'.
Unless you only need to do that for the single PDF you mentioned (or a some
PDFs internally very similar), that is a hell of an assignment. And as your
title in your footer says that you are a "Sr. Software engineer", I'm
inclined to doubt that this is only an excercise with only one target PDF...
1. Do you really only need to process that one PDF you mentioned? Or only
PDFs internally very similar? In these cases, please provide that PDF.
2. Can the text content of the PDFs in question be considered parsable?
3. How wide should that space be? The width of a regular space character?
Some custom width? A width to calculate from font size and style?
4. Inserting a space makes text lines longer. Does your assignment include
reflowing lines which afterwards would reach beyond some margin? In that
case, are the margins and the general page structure known?
5. When copying and pasting text from your PDF, shall that text also
include the spaces?
6. Does your assignment involve shifting annotations and jump targets which
might be considered anchored relative to certain page content?
Depending on the answers there may follow more questions still.
Regards, Michael
--
http://itext-general.2136553.n4.nabble.com/Re-Need-help-for-Character-Spacing-in-existing-pdf-tp4657800p4657801.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
iText-questions mailing list
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/
http://itextpdf.com/themes/keywords.php
--
*Thanks & Regards

Shafi**
Sr. Software engineer** | Propalms Network Pvt Ltd. Pune
*
http://www. <http://www.tlcinfotech.co.in/>propalmsnetwork.com<***@propalmsnetwork.com>|
***@propalmsnetwork.com
8600335990
mkl
2013-03-13 11:11:08 UTC
Permalink
Shafi hameed,
Post by Shafi hameed
Actually my basic requirement is to change the font of existing pdf into
'Braille' (Braille.ttf is a true type font basically for blind people)
Why didn't you say so from the start?
Post by Shafi hameed
I want to select any PDF file and want to change all its font into Braille.
as I did not findno easy method to change the existing text font, I did
some trick to change all the text's font into Braille.
That reminds me of an answer on stack overflow, Changing font of PDF using
iTextSharp <http://stackoverflow.com/a/15241639/1729265> ... As that
solution worked "as per [the asker's] expectation," I didn't look into it.
That person actually merely replaced the base font name leaving everything
else untouched. Thinking about that solution makes clear that it involves
many preconditions to work acceptably.
Post by Shafi hameed
every thing worked fine for me but another problem occurred, since The
width of Braille font is greater than the actual font's width which
resulted the overlapping of character.
If you did the same trick and now run into this kind of problems, you most
likely have not adjusted the character widths array. Therefore, the PDF
viewer thinks it should display the Braille characters using the widths of
the corresponding Arial characters.

PDF objects representing Arial in a PDF look like this:

9 0 obj
<<
/Type /Font/Subtype /TrueType/Name /F0/BaseFont /Arial /Encoding
/WinAnsiEncoding/FirstChar 32/LastChar 255/Widths [278 278 355 556 556 889
667 190 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556
556 278 278 584 584 584 556 1015 667 667 722 722 667 610 778 722 278 500 667
556 832 722 778 667 778 722 667 610 722 667 944 667 667 610 278 278 278 469
556 333 556 556 500 556 556 278 556 556 222 222 500 222 832 556 556 556 556
333 500 278 556 500 722 500 500 500 334 260 334 584 750 556 750 222 556 333
1000 556 556 333 1000 667 333 1000 750 610 750 750 222 222 333 333 350 556
1000 333 1000 500 333 944 750 500 667 278 333 556 556 556 556 260 556 333
736 370 556 584 333 736 552 400 549 333 333 333 576 537 278 333 333 365 556
834 834 834 610 667 667 667 667 667 667 1000 722 667 667 667 667 278 278 278
278 722 722 778 778 778 778 778 584 778 722 722 722 722 667 667 610 556 556
556 556 556 556 889 500 556 556 556 556 278 278 278 278 556 556 556 556 556
556 556 549 610 556 556 556 556 500 556 500]/FontDescriptor 13 0 R
endobj
13 0 obj
<<
/Type /FontDescriptor/FontName /Arial /Flags 32/FontBBox[-250 -144 2664
864]/Ascent 864/Descent -144/CapHeight 864/AvgWidth 432/MaxWidth
2664/MissingWidth 2664/StemH 78/StemV 78/ItalicAngle 0
endobj

When changing this to Braille, it generally does not suffice to replace the
name. Instead the other pieces of information you see here also should be
adjusted. In your case the effects of the /Widths array are most appearant
but the other entries visible here should be inspected, too.
Post by Shafi hameed
file fully converted into Braille font but there is very less distance
between two character.so I thought if I could set a spacing between two
character, my problem would be solved.
OR
please tell me any easer way to change the all text fonts into Braille or
any selected font.
I would propose you first try to replace the other relevant font information
(first your widths array), too, not only the base font name. Then start
dealing with text that went beyond the margins and other visual artifacts.

Regards, Michael



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Re-Need-help-for-Character-Spacing-in-existing-pdf-tp4657800p4657806.html
Sent from the iText - General mailing list archive at Nabble.com.
Leonard Rosenthol
2013-03-13 11:19:03 UTC
Permalink
Changing the font of any arbitrary text in any arbitrary PDF is EXTREMELY DIFFICULT (or may even be impossible in some cases). You really need to read ISO 32000-1:2008 (the PDF standard) to get a deep understanding of font technology and text encoding issues and why it is such a hard problem.

Changing the character spacing of a run of text is easy – there is a text state operator (Tc) for that.

Leonard

From: Shafi hameed <***@gmail.com<mailto:***@gmail.com>>
Reply-To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Date: Wednesday, March 13, 2013 11:34 AM
To: Post here <itext-***@lists.sourceforge.net<mailto:itext-***@lists.sourceforge.net>>
Subject: Re: [iText-questions] [SPAM] Re: Need help for Character Spacing in existing pdf

Actually my basic requirement is to change the font of existing pdf into 'Braille' (Braille.ttf is a true type font basically for blind people)
I want to select any PDF file and want to change all its font into Braille. as I did not findno easy method to change the existing text font, I did some trick to change all the text's font into Braille.
every thing worked fine for me but another problem occurred, since The width of Braille font is greater than the actual font's width which resulted the overlapping of character. file fully converted into Braille font but there is very less distance between two character. so I thought if I could set a spacing between two character, my problem would be solved.

OR
please tell me any easer way to change the all text fonts into Braille or any selected font.




On Wed, Mar 13, 2013 at 3:39 PM, mkl <***@wir-sind-cool.org<mailto:***@wir-sind-cool.org>> wrote:
Shafi hameed,
I have a pdf file in which all the contents are in Arial font. my
requirement is to set a space between every character. eg. i want to
change 'HELLO' as 'H E L L O'.
Unless you only need to do that for the single PDF you mentioned (or a some
PDFs internally very similar), that is a hell of an assignment. And as your
title in your footer says that you are a "Sr. Software engineer", I'm
inclined to doubt that this is only an excercise with only one target PDF...

Some questions, therefore:

1. Do you really only need to process that one PDF you mentioned? Or only
PDFs internally very similar? In these cases, please provide that PDF.

2. Can the text content of the PDFs in question be considered parsable?

3. How wide should that space be? The width of a regular space character?
Some custom width? A width to calculate from font size and style?

4. Inserting a space makes text lines longer. Does your assignment include
reflowing lines which afterwards would reach beyond some margin? In that
case, are the margins and the general page structure known?

5. When copying and pasting text from your PDF, shall that text also
include the spaces?

6. Does your assignment involve shifting annotations and jump targets which
might be considered anchored relative to certain page content?

Depending on the answers there may follow more questions still.

Regards, Michael



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Re-Need-help-for-Character-Spacing-in-existing-pdf-tp4657800p4657801.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
iText-questions mailing list
iText-***@lists.sourceforge.net<mailto:iText-***@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



--
Thanks & Regards

Shafi
Sr. Software engineer | Propalms Network Pvt Ltd. Pune
[Loading Image...]
http://www.<http://www.tlcinfotech.co.in/>propalmsnetwork.com<mailto:***@propalmsnetwork.com> | ***@propalmsnetwork.com<mailto:***@propalmsnetwork.com>
8600335990
mkl
2013-03-13 12:37:59 UTC
Permalink
Shafi hameed, Leonard
Changing the character spacing of a run of text is easy – there is a text
state operator (Tc) for that.
Yes, but it's important to see that this is true for the "spacing of a run
of text" --- depending on the software, though, that created the original
PDF, there may be multiple such runs in a text line, each of them starting
with a Tm operator setting the text matrix. In this case, the operands of
these Tm operators would have to be changed, too. Then there are those ugly
constructs for poor man's bold effects by printing text twice with a small
offset which will break when merely character spacing is changed. And who
knows what else is out there...

But, after all, the primary task seems to be a change of fonts with clearly
different metrics, and indeed,
Changing the font of any arbitrary text in any arbitrary PDF is EXTREMELY
DIFFICULT
Regards, Michael



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Re-Need-help-for-Character-Spacing-in-existing-pdf-tp4657800p4657809.html
Sent from the iText - General mailing list archive at Nabble.com.
Shafi hameed
2013-03-13 13:56:58 UTC
Permalink
Hi Leonard,
Can you please give me some sample code to use (Tc) operator to set the
character space in existing PDF's text?
Thank you in advance.
Post by Leonard Rosenthol
Changing the font of any arbitrary text in any arbitrary PDF is EXTREMELY
DIFFICULT (or may even be impossible in some cases). You really need to
read ISO 32000-1:2008 (the PDF standard) to get a deep understanding of
font technology and text encoding issues and why it is such a hard problem.
Changing the character spacing of a run of text is easy – there is a text
state operator (Tc) for that.
Leonard
Date: Wednesday, March 13, 2013 11:34 AM
Subject: Re: [iText-questions] [SPAM] Re: Need help for Character Spacing in existing pdf
Actually my basic requirement is to change the font of existing pdf into
'Braille' (Braille.ttf is a true type font basically for blind people)
I want to select any PDF file and want to change all its font into
Braille. as I did not findno easy method to change the existing text
font, I did some trick to change all the text's font into Braille.
every thing worked fine for me but another problem occurred, since The
width of Braille font is greater than the actual font's width which
resulted the overlapping of character. file fully converted
into Braille font but there is very less distance between two character.
so I thought if I could set a spacing between two character, my problem
would be solved.
OR
please tell me any easer way to change the all text fonts into Braille or
any selected font.
Post by mkl
Shafi hameed,
I have a pdf file in which all the contents are in Arial font. my
requirement is to set a space between every character. eg. i want to
change 'HELLO' as 'H E L L O'.
Unless you only need to do that for the single PDF you mentioned (or a some
PDFs internally very similar), that is a hell of an assignment. And as your
title in your footer says that you are a "Sr. Software engineer", I'm
inclined to doubt that this is only an excercise with only one target PDF...
1. Do you really only need to process that one PDF you mentioned? Or only
PDFs internally very similar? In these cases, please provide that PDF.
2. Can the text content of the PDFs in question be considered parsable?
3. How wide should that space be? The width of a regular space character?
Some custom width? A width to calculate from font size and style?
4. Inserting a space makes text lines longer. Does your assignment include
reflowing lines which afterwards would reach beyond some margin? In that
case, are the margins and the general page structure known?
5. When copying and pasting text from your PDF, shall that text also
include the spaces?
6. Does your assignment involve shifting annotations and jump targets which
might be considered anchored relative to certain page content?
Depending on the answers there may follow more questions still.
Regards, Michael
--
http://itext-general.2136553.n4.nabble.com/Re-Need-help-for-Character-Spacing-in-existing-pdf-tp4657800p4657801.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
iText-questions mailing list
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/
http://itextpdf.com/themes/keywords.php
--
*Thanks & Regards
Shafi**
Sr. Software engineer** | Propalms Network Pvt Ltd. Pune
*
8600335990
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
iText-questions mailing list
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/
http://itextpdf.com/themes/keywords.php
--
*Thanks & Regards

Shafi**
Sr. Software engineer** | Propalms Network Pvt Ltd. Pune
*
http://www. <http://www.tlcinfotech.co.in/>propalmsnetwork.com<***@propalmsnetwork.com>|
***@propalmsnetwork.com
8600335990
Shafi hameed
2013-03-13 09:21:33 UTC
Permalink
Dear sir,

I have a pdf file in which all the contents are in Arial font. my
requirement is to set a space between every character. eg. i want to change
'HELLO' as 'H E L L O'.

The follwing code adds some text with given amount of charecter spacing

var pdfStamper = new PdfStamper(pdfReader, new FileStream(outPutFname,
FileMode.Create));

BaseFont customfont = BaseFont.CreateFont(@"E:\MyFont.ttf",
"winansi",
BaseFont.EMBEDDED);
AcroFields pdfFormFields = pdfStamper.AcroFields;


PdfContentByte cb = pdfStamper.GetOverContent(1);

cb.SetCharacterSpacing(2);//Set amount of space you want
cb.SetFontAndSize(customfont, 16);
cb.BeginText();
cb.ShowText("Test");
cb.EndText();

pdfStamper.FormFlattening = false;
pdfStamper.Close();
pdfReader.Close();

But I have to set space on existing text in the pdf, while this code will
add new text ("test") in the pdf.

please help me. thanks in advance.
--
*Thanks & Regards

Shafi**
Sr. Software engineer** | Propalms Network Pvt Ltd. Pune
*
http://www. <http://www.tlcinfotech.co.in/>propalmsnetwork.com<***@propalmsnetwork.com>|
***@propalmsnetwork.com
8600335990
Continue reading on narkive:
Loading...