Skip to main content
Known Participant
December 19, 2007
Question

rtf import/export of a textframe

  • December 19, 2007
  • 12 replies
  • 1254 views
hi,

is it possible to export and import textframe contents to/from a rtf file? (with the api)

best regards
This topic has been closed for replies.

12 replies

Known Participant
January 17, 2008
thanks, shame on me - i didn't see the 5th param... thanks!
Inspiring
January 17, 2008
Have you tried kSuppressUI in your export provider Export method call?

Ian
Known Participant
January 16, 2008
is there any possibility to not show the export options dialog when exporting as tagged text?
Known Participant
December 21, 2007
problem was, i used: "Rich Text Format" as stated in http://support.adobe.com/devsup/devsup.nsf/docs/51699.htm and not "Sangam Rtf Export"
Known Participant
December 21, 2007
wow! thanks for that, will try it asap.
Inspiring
December 21, 2007
Hi<br /><br />Here is the source code I use. For programming my plugins I use a framework with different methods. As you see there are methods from this framework in the code below. I explain it in the code what they do.<br /><br />--- SNIP BEGIN ---<br /><br />//****************************************************************************<br />/*! \brief Export text (different formats) from a text frame<br /> * \param UIDRefFrame UID reference of the frame<br /> * \param iProvider Provider to use<br /> * \param sText Exported Text<br /> * \return Error code<br /> ****************************************************************************/<br />int CIndesignUtils::exportText(UIDRef uidRefFrame, int iProvider, string& sText)<br />{<br /> bool bExportPossible = kFalse;<br /> int iErr = ERR_NO;<br /> int32 iLen = 0;<br /> int iStart;<br /> int iEnd;<br /> string sProvider = "";<br /> bool16 bOldUndoState = kTrue;<br /> ExportMemoryXferBytes oStream;<br /> UIDRef uidRefTextModel = UIDRef::gNull;<br /> InterfacePtr<ITool> ipActiveTool(nil);<br /><br /> do {<br /> // If uidRefFrame is nil, take the current frame<br /> getUIDRefCurrentFrameIfUIDRefIsNull(uidRefFrame, IFrameType::kTextFrame); // Error returned is not important<br /> if (uidRefFrame != UIDRef::gNull) {<br /> // Select the text tool<br /> ipActiveTool.reset(selectTextTool(uidRefFrame, INT_MAX));<br /> }<br /> switch (iProvider) {<br /> case PROVIDER_RTF: iErr = ERR_IND_EXPORTRTFTEXT;<br /> // EXPORTPROVIDER_RTF is defined as "Sangam RTF Export"<br /> sProvider = EXPORTPROVIDER_RTF;<br /> break;<br /> case PROVIDER_INDESIGN: iErr = ERR_IND_EXPORTINDESIGNTEXT;<br /> sProvider = EXPORTPROVIDER_INDESIGN;<br /> break;<br /> default: iErr = ERR_IND_WRONGEXPORTPROVIDER; break;<br /> }<br /> if (iErr == ERR_IND_WRONGEXPORTPROVIDER) break;<br /> // Get the current document<br /> IDocument* ipDocument = getCurrentDocument();<br /> if (ipDocument == nil) {<br /> break;<br /> }<br /> InterfacePtr<IExportProvider> ipExportProvider(searchExportProvider(sProvider)); <br /> if (ipExportProvider == nil) {<br /> break;<br /> }<br /> // Get the text model of the frame<br /> InterfacePtr<ITextModel> ipTextModel(getTextModel(uidRefFrame));<br /> if (ipTextModel == nil) {<br /> break;<br /> }<br /> uidRefTextModel = ::GetUIDRef(ipTextModel);<br /> // Get the text length in the current frame<br /> if (isInCopyRunning()) {<br /> iStart = 0;<br /> iErr = getTextLength(uidRefFrame, iEnd);<br /> } else {<br /> iErr = getSelectedTextIndex(iStart, iEnd);<br /> }<br /> if (iErr != ERR_NO) break;<br /> InterfacePtr<ITextTarget> ipTargetBoss((ITextTarget*) ::CreateObject(kTextSuiteBoss, IID_ITEXTTARGET));<br /> if (ipTargetBoss) {<br /> ipTargetBoss->SetTextUnmanaged(uidRefTextModel, RangeData(iStart, iEnd, RangeData::kLeanForward));<br /> }<br /> bExportPossible = ipExportProvider->CanExportThisFormat(ipDocument, ipTargetBoss, sProvider.c_str());<br /> if (bExportPossible) {<br /> // We found the appropriate provider, now we can export<br /> InterfacePtr<IPMStream> ipStream(StreamUtil::CreateMemoryStreamWrite(&oStream));<br /> if (ipStream == nil) break;<br /> ipExportProvider->ExportToStream(ipStream, ipDocument, ipTargetBoss, sProvider.c_str(), K2::kSuppressUI);<br /> sText = oStream.getBuffer();<br /> if (sText.length() <= 0) {<br /> iErr = ERR_IND_NOTEXTEXPORTED;<br /> }<br /> } else {<br /> iErr = ERR_IND_CANNOTEXPORTTEXT;<br /> }<br /> } while (kFalse);<br /> // Select the tool who was active before the method was called<br /> selectTool(ipActiveTool);<br /> return iErr;<br />} <br /><br />--- SNIP END -----<br /><br />This method works for RTF and Indesign Tagged Text.<br /><br />I hope it helps to solve the problem.<br /><br />Regards<br />Hans
Known Participant
December 20, 2007
sorry for posting again, i now can export the indesign tagged text, but rtf export fails...<br /><br />InDesign::TextRange range(GetFrameTextRange(selectedItem));<br />InterfacePtr<ITextTarget> mtTarget((ITextTarget*)CreateObject(kTextSuiteBoss, IID_ITEXTTARGET));<br /> mtTarget->SetTextUnmanaged(::GetUIDRef(range.QueryModel()), RangeData(range.Start(), range.End(), RangeData::kLeanForward));<br /><br />IDFile idFile(PMString("C:\\bla.rtf")); <br /><br />InterfacePtr<IK2ServiceRegistry> k2ServiceRegistry(gSession, UseDefaultIID());<br /> int32 exportProviderCount = k2ServiceRegistry->GetServiceProviderCount(kExportProviderService);<br /><br /> bool found = kFalse;<br /> for (int32 exportProviderIndex = 0 ; exportProviderIndex < exportProviderCount ; exportProviderIndex++) {<br /> InterfacePtr<IK2ServiceProvider> k2ServiceProvider(k2ServiceRegistry->QueryNthServiceProvider(kExportProviderService, exportProviderIndex));<br /> InterfacePtr<IExportProvider> exportProvider(k2ServiceProvider, IID_IEXPORTPROVIDER); <br /> bool16 canExportByTarget = exportProvider->CanExportThisFormat(doc, mtTarget, "Rich Text Format");<br /> if (canExportByTarget) {<br /> found = kTrue;<br /> exportProvider->ExportToFile(idFile, doc, mtTarget, "Rich Text Format", kFullUI);<br /> }<br /> if (found) break;<br /> }<br /><br />he can't find an appropriate rtf export provider.
Known Participant
December 20, 2007
(i need both, RTF and tagged text)<br /><br />ok, i only have problems with the export:<br /><br />- i have a selection manager and have the selected textframe's UIDRef, no problem there.<br /><br />- <b>how can i get the textmodel from this UIDRef?</b><br /><br />- when creating the export provider with this code: <br /><br />InterfacePtr<IExportProvider> provider((IExportProvider*)CreateObject(kTaggedTextExportFilterBoss, IID_IEXPORTPROVIDER));<br /><br /><b>how can i tell the exportprovider to export my textframe?</b><br /><br />- <b>how can i create the stream? i need to export it to file or a string, doesn't matter</b><br /><br />best regards!
Known Participant
December 20, 2007
oh, nice, thanks.

do you have a sample how to export the text of a text frame into a stream?!

best regards!
Inspiring
December 19, 2007
Hi

No. You can import and export to/from a text frame via this providers.

import
------
You can import the text and get an UID reference of the text story who contains the text. This story can you insert in a text frame.

export
------
You can export the text of a text frame into a stream and get the buffer of this stream (in RTF format).

Greetz
Hans