Free Support Forum - aspose.com

Font changed after replacing text

hi,


im starting to becomming a big aspose fan. but thers always a but.

having 2 issue
1) when I have a tag created in a source pdf (example [Name]) and have it with a font what is not installed on the computer where aspose is running on, it changes the font. and it is not staying in the font what is included in the file.

2) when I have Tags right side aligned and i replace them, they shift to the right. how can I take care that the alignment is as it is in the source pdf?

like to here from you

richard

Hi Richard,


Thanks for using our products.

Can you please share the source PDF file and the code snippet that you are using so that we can test the scenario at our end. We are sorry for this inconvenience.

Document pdfDocument = new Document(fileName);

//create TextAbsorber object to find all instances of the input search phrase TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@"\x5B[a-zA-Z]*\x5D");

	</p><p>TextSearchOptions textSearchOptions = new TextSearchOptions(true);
	textFragmentAbsorber.TextSearchOptions = textSearchOptions;

//accept the absorber for all the pages pdfDocument.Pages.Accept(textFragmentAbsorber);

//get the extracted text fragments TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments; //loop through the fragments foreach (TextFragment textFragment in textFragmentCollection)

{

//update text and other properties if (textFragment.Text == "[k_aanhefnaam]") { textFragment.Text = "Dear Joe" + i.ToString(); } else if (textFragment.Text == "[k_straatnr]") { textFragment.Text = "Street 10" + i.ToString(); } else if (textFragment.Text == "[k_pcplaats]") { textFragment.Text = "12345 New york " + i.ToString(); } else if (textFragment.Text == "[k_naam]") { textFragment.Text = "Joe " + i.ToString(); } else if (textFragment.Text == "[b_naam]") { textFragment.Text = "Sunset optician " + i.ToString(); } }

	pdfDocument.Save(@"c:\CS\pdfs\output_" + i.ToString() + ".pdf");</p>

Hi Richard,


Thanks for sharing the code snippet and resource file. I have tested the scenario using the code snippet which you have shared and as per my observations, no tag is being replaced. However I have simply tried replacing [k_naam] tag and as per my observations, the resultant file contains text in Times New Roman. Even though the Calibri font is installed over my system but output file contains text in Times New Roman. For
the sake of correction, I have logged it in our issue tracking system as
PDFNEWNET-34711. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We
apologize for your inconvenience.

Any new about this isseu?

richard

Hi Richard,


Thanks for your patience.

The development team has been busy resolving
other priority issues and I am afraid this above stated problem is not yet
resolved. Nevertheless, as soon as we have some updates regarding its resolution, we would
be more than happy to update you with the status of correction. Please be
patient and spare us little time.

We are sorry for this delay and inconvenience


Hi Richard,


Thanks for your patience.

We have further investigated the issue PDFNEWNET-34711 and have found that the document contains MyriadPro font but not Calibri.

Your query. 1) when I have a tag created in a source pdf (example [Name]) and have it with a font what is not installed on the computer where aspose is running on, it changes the font. and it is not staying in the font what is included in the file.

You have described the case when the font is not installed. Actually to reuse the font, the system must access the full font version. So, the full font version should be available on the system, or embedded to the document. Furthermore, this particular document uses font subsets. They are not full font versions and cannot be reused. So in order to reuse them they must be installed on the system. Or the document must be built without subsetting them (embed but not subset).

Nevertheless, if we see Adobe behavior, it doesn’t even allow you to change the text when MyriadPro font is not installed and is removed from Adobe’s Resources installation folder. So Adobe uses the font because it ships the font during Adobe’s installation. The font it must be installed to allow us to use it and its a requirement to make possible to reuse the font.

2) when I have Tags right side aligned and i replace them, they shift to the right. How can I take care that the alignment is as it is in the source pdf?

The Pdf format doesn’t have any information that the tags are right-aligned. So you must manually perform the fragments alignment changing their coordinates. Please use following code snippet that performs the right alignment and works fine when font is installed on the system (Please take a look over attached 34711-installedFont.pdf file):

[C#]

Document pdfDocument = new Document(“c:/pdftest/Tag+test+PDF+(High+Quality+Print)
(1).pdf”
);<o:p></o:p>

//create TextAbsorber object to find all instances of the input search phrase

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@"\[[a-zA-Z_]*\]");

TextSearchOptions textSearchOptions = new TextSearchOptions(true);

textFragmentAbsorber.TextSearchOptions = textSearchOptions;

//accept the absorber for all the pages

pdfDocument.Pages.Accept(textFragmentAbsorber);

TextFragment fragment1 = null;

TextFragment fragment2 = null;

TextFragment fragment3 = null;

//get the extracted text fragments

TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

//loop through the fragments

foreach (TextFragment textFragment in textFragmentCollection)

{

//update text and other properties

if (textFragment.Text == "[k_aanhefnaam]")

{

textFragment.Text = "Dear Joe";

fragment1 = textFragment;

}

else if (textFragment.Text == "[k_straatnr]")

{

textFragment.Text = "Street 10";

fragment2 = textFragment;

}

else if (textFragment.Text == "[k_pcplaats]")

{

textFragment.Text = "12345 New york";

fragment3 = textFragment;

}

else if (textFragment.Text == "[k_naam]")

{

textFragment.Text = "Joe";

}

else if (textFragment.Text == "[b_naam]")

{

textFragment.Text = "Sunset optician";

}

}

if (fragment1 != null)

fragment1.Position = new Position(500 - fragment1.Rectangle.Width, fragment1.Position.YIndent);

if (fragment2 != null)

fragment2.Position = new Position(500 - fragment2.Rectangle.Width, fragment2.Position.YIndent);

if (fragment3 != null)

fragment3.Position = new Position(500 - fragment3.Rectangle.Width, fragment3.Position.YIndent);

pdfDocument.Save("c:/pdftest/Tag+test+PDF+(High+Quality+Print) (1)_updated.pdf");

The issues you have found earlier (filed as PDFNEWNET-34711) have been fixed in Aspose.Pdf for .NET 7.7.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.