We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replacing text from curve path text isn’t working

Hello,

I’m trying to replace the text from a pdf that has curved text, but it doesn’t seem to find the text fragment to replace it. Seems to work with normal text, but not with curved text.

The code can be found below and the pdf use attached:
Playername.pdf (594.5 KB)

//m_Document = MakeObject(System::String::FromUtf8(path));
//from: “Playername”
//to: “Something”

void CAspose::ReplaceTextInDocument(const char* from, const char *to, bool &textChanged)
{
textChanged = false;
for (int i = 0; i < m_Document->get_Pages()->get_Count(); i++)
{
auto absorber = MakeObject(StringtoU16(from).c_str());
m_Document->get_Pages()->idx_get(i + 1)->Accept(absorber);

       //no text fragments found!
       for (int j = 0; j < absorber->get_TextFragments()->get_Count(); j++)
       {
            auto text = absorber->get_TextFragments()->idx_get(j + 1);
            text->set_Text(StringtoU16(to).c_str());
            textChanged = true;
            //...
       }
 }

}

Many thanks in advance for your feedback,

Cristian Miron
www.geminicad.com

@Cristian.MIRON

Would you please make sure to use latest version of the API i.e. Aspose.PDF for C++ 20.5. Also, please initialize TextFragmentAbsorber as give in this example. In case issue is still persisting, please share modified working code snippet so that we can test the scenario in our environment and address it accordingly.

Tested with Aspose 20.5 with no improvement. The original text in PDF file is Playername. Aspose recognizes these fragments from it: Play and ame.
Trying to initialize the absorber as in your example, i.e.
auto absorber = MakeObject(L"Aspose.Pdf");
doesn’t compile.

I attach the whole code, including the function StringtoU16:

bool CAspose::ReplaceTextInDocument(const char* from, const char *to, bool &textChanged)
{
try
{
textChanged = false;
for (int i = 0; i < m_Document->get_Pages()->get_Count(); i++)
{
auto absorber = MakeObject(StringtoU16(from).c_str());
m_Document->get_Pages()->idx_get(i + 1)->Accept(absorber);

		for (int j = 0; j < absorber->get_TextFragments()->get_Count(); j++)
		{
    auto text = absorber->get_TextFragments()->idx_get(j + 1);

    System::SharedPtr<Aspose::Pdf::Text::Position> position = text->get_Position();
    double pageWidth = text->get_Page()->get_Rect()->get_Width();
    double pageHeight = text->get_Page()->get_Rect()->get_Height();

    double oldTotalHorizontalMargin = pageWidth - text->get_Rectangle()->get_Width();
    double oldTotalVerticalMargin = pageHeight - text->get_Rectangle()->get_Height();

    double leftMarginProportion = position->get_XIndent() / oldTotalHorizontalMargin;
    double topMarginProportion = position->get_YIndent() / oldTotalVerticalMargin;

			text->set_Text(StringtoU16(to).c_str());
			textChanged = true;

    double newTotalHorizontalMargin = pageWidth - text->get_Rectangle()->get_Width();
    double newTotalVerticalMargin = pageHeight - text->get_Rectangle()->get_Height();

    position->set_XIndent(leftMarginProportion * newTotalHorizontalMargin);
    position->set_YIndent(topMarginProportion * newTotalVerticalMargin);
    text->set_Position(position);

		}
	}

	return true;
}
catch (...)
{
}

return false;

}
//--------------------------------------------------------------------------------------------------
std::u16string CAspose::StringtoU16(const std::string &str) const
{
std::u16string wstr = u"";
char16_t c16str[3] = u"\0";
mbstate_t mbs;

for (const auto& it: str)
{
memset (&mbs, 0, sizeof (mbs));//set shift state to the initial state
memmove(c16str, u"\0\0\0", 3);
mbrtoc16 (c16str, &it, 3, &mbs);
wstr.append(std::u16string(c16str));
}

return wstr;
}

@catalin.aramescu

Thanks for providing further details.

We have logged an investigation ticket as PDFCPP-1327 in our issue tracking system for this scenario. We will further investigate the issue in details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

Can we have an update on this issue, please? We’ll have a release in a couple of weeks and this feature is important for us.
Thank you

@catalin.aramescu

Regretfully the earlier logged ticket is not resolved yet. However, we have recorded your concerns and will surely take care of them during ticket investigation. We will inform you as soon as we have additional updates regarding ticket resolution. Please spare us some time.

We are sorry for the inconvenience.

Hello! There is no hot fix available since almost a month and this is unacceptable. Please note that we will not renew the software subscription if there’s no fix or workaround available in the next days.

@Cristian.MIRON

Please accept our humble apology for the inconvenience caused. Please note that we resolve every issue which is reported. However, they are resolved on first come first serve basis. Furthermore, issue resolution time depends upon complexity of the issue, and components of the API need to investigated to resolve it.

Aspose.PDF for C++ is ported from its parent .NET API i.e. Aspose.PDF for .NET. We have initially investigated the issue and it revealed that the issue needs to be fixed in parent API and we are working over it. As soon as the issue is resolved and its fix is ported into C++ API, we will inform you. Please spare us some time.

Thank you for the fast feedback. Do you have an estimation for when the fix will be ported to C++ API and a patch/new version will be available?

@Cristian.MIRON

We are afraid that we cannot offer any reliable ETA at the moment as the issue in .NET API is needed to be investigated first. However, we will surely inform you as soon as we make some definite progress towards ticket resolution. We greatly appreciate your patience in this matter. Please spare us some time.