Hello,
Two questions here:
1) We want to translate an English PDF file to a foreign language. What we want specifically is to replace the English text (word) in each text object to the foreign text (word).
We have purchased licenses for "acPDFCreator.Net.dll" and "acPDFCreatorLib.Net.dll" (version 2.0). Will these two .dlls be sufficient for this purpose?
2) I've got sample code segment about the syntax of replacing text as below:
----------------------------------------------------------------------------
Object[] myObjArray = (Object []) axPDF.get_ObjectAttribute ("Pages[1]", "Objects");
foreach (ACPDFCREACTIVEX.acObject obj in myObjArray)
{
//Get the type of Attribute
ACPDFCREACTIVEX.IacAttribute attribute = (ACPDFCREACTIVEX.IacAttribute ) obj.get_Evaluate ("ObjectType");
//Check if it is a text object
if (Int32.Parse(attribute.Value.ToString()) == 6)
{
MessageBox.Show ("acObjectTypeText found","Amyuni PDF Creator");
//Retrieves value of object found
attribute = (ACPDFCREACTIVEX.IacAttribute) obj.get_Evaluate ("Text");
//text property is not empty and exist
if(attribute.Value != null)
{
//Retrieve text value
MessageBox.Show (attribute.Value.ToString());
//change the text value to the new text
attribute.value = "New text";
axPDF.DoCommandTool(ACPDFCREACTIVEX.CommandToolConstants.acCommandToolRunDocument);
}
}
}
----------------------------------------------------------------------------
Anyone can tell me the object type of "axPDF" on the first line? How to derive this object from IacDocument object?
Thanks!
Replace text in text objects
Re: Replace text in text objects
Here's the sample code for replacing text in text objects in .NET (that Jose sent to me):
private void btnLoopObjLib_Click(object sender, EventArgs e)
{
//initailize library
//This should be done once
acPDFCreatorLib.Initialize();
//set license key
acPDFCreatorLib.SetLicenseKey ( "Amyuni .Net Eval Version","07EFC....AC86803E0" );
// Open the PDF document file.
string strFilePathAndName = Application.StartupPath + "\\Source_Files\\fivepage.pdf";
//need to open a file stream
System.IO.FileStream fs = new System.IO.FileStream(strFilePathAndName, FileMode.Open, FileAccess.Read, FileShare.Read);
//Create Document Object
Amyuni.PDFCreator.IacDocument PdfDoc = new Amyuni.PDFCreator.IacDocument(null);
PdfDoc.Open(fs, "");
//Get page count
int intPageCount = PdfDoc.PageCount;
//Loop through all the Pages
for (int counter = 1; counter <= intPageCount; counter++)
{
try
{
//Declare ArrayList and fill it with all of the objects in the
//current PDF document
ArrayList arList = (ArrayList)PdfDoc.GetPage(counter).Attribute("Objects").Value;
foreach (Amyuni.PDFCreator.IacObject obj in arList)
{
//Check if it an text object
if (obj.Attribute("ObjectType").Value.ToString() == "5")
{
obj.Attribute("Text").Value = "New Value";
//or
//MessageBox.Show(obj.Attribute("Text").Value);
}
}
}
catch (Exception ev)
{
MessageBox.Show(ev.Message);
}
}
/*********************************************************************/
// Open the PDF document file.
string strFilePathAndNameSave = Application.StartupPath + "\\Resulting_Files\\Save_fivepage_add_text.pdf";
//save doc to new file
System.IO.FileStream fs2 = new System.IO.FileStream(strFilePathAndNameSave,
FileMode.Create,
FileAccess.Write,
FileShare.Read);
PdfDoc.Save(fs2, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveAll);
//end and cleanup
//this should only be done once
acPDFCreatorLib.Terminate();
}
}
private void btnLoopObjLib_Click(object sender, EventArgs e)
{
//initailize library
//This should be done once
acPDFCreatorLib.Initialize();
//set license key
acPDFCreatorLib.SetLicenseKey ( "Amyuni .Net Eval Version","07EFC....AC86803E0" );
// Open the PDF document file.
string strFilePathAndName = Application.StartupPath + "\\Source_Files\\fivepage.pdf";
//need to open a file stream
System.IO.FileStream fs = new System.IO.FileStream(strFilePathAndName, FileMode.Open, FileAccess.Read, FileShare.Read);
//Create Document Object
Amyuni.PDFCreator.IacDocument PdfDoc = new Amyuni.PDFCreator.IacDocument(null);
PdfDoc.Open(fs, "");
//Get page count
int intPageCount = PdfDoc.PageCount;
//Loop through all the Pages
for (int counter = 1; counter <= intPageCount; counter++)
{
try
{
//Declare ArrayList and fill it with all of the objects in the
//current PDF document
ArrayList arList = (ArrayList)PdfDoc.GetPage(counter).Attribute("Objects").Value;
foreach (Amyuni.PDFCreator.IacObject obj in arList)
{
//Check if it an text object
if (obj.Attribute("ObjectType").Value.ToString() == "5")
{
obj.Attribute("Text").Value = "New Value";
//or
//MessageBox.Show(obj.Attribute("Text").Value);
}
}
}
catch (Exception ev)
{
MessageBox.Show(ev.Message);
}
}
/*********************************************************************/
// Open the PDF document file.
string strFilePathAndNameSave = Application.StartupPath + "\\Resulting_Files\\Save_fivepage_add_text.pdf";
//save doc to new file
System.IO.FileStream fs2 = new System.IO.FileStream(strFilePathAndNameSave,
FileMode.Create,
FileAccess.Write,
FileShare.Read);
PdfDoc.Save(fs2, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveAll);
//end and cleanup
//this should only be done once
acPDFCreatorLib.Terminate();
}
}