Rank: Newbie
Groups: Registered
Joined: 11/9/2016(UTC) Posts: 3  Location: Hyderabad
|
Hi.
Using Patagames.Pdf, can we edit Plain Text and Replace PDFTextobject in PDF File. Example : AAAA word needs to replace with BBBB
Regards Kiran.
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 post(s)
|
Unfortunately there is no a simple way to do that. You can replace the text, it will be even shown in PdfViewer, but these changes can't be saved. So they would be lost after page disposing.
|
|
|
|
Rank: Guest
Groups: Guests
Joined: 1/5/2016(UTC) Posts: 158
Was thanked: 4 time(s) in 4 post(s)
|
Hi
Let us know how to Replace the Text (AAAA TO BBBB) for viewing in Viewer using Patagames.PDF, after viewing the Replaced Text in Viewer, once print is done the changes will reflect or not ?
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 post(s)
|
The following code illustrates how to search and replace text in whole document and then print. Please note, you need to upgrade the Pdfium.Net SDK to the latest version. http://forum.patagames.c...released-on-Nov-13--2016Code:
private void ReplaceTextAndPrint(PdfDocument pdfDocument)
{
PrintDialog dlg = new PrintDialog();
PdfPrintDocument print = new PdfPrintDocument(pdfDocument);
print.BeforeRenderPage += (s, e) =>
{
foreach(var obj in e.Page.PageObjects)
{
var textObj = obj as PdfTextObject;
if (textObj == null)
continue;
textObj.TextUnicode = textObj.TextUnicode.Replace("AAAA", "BBBB");
}
};
dlg.Document = print;
dlg.AllowCurrentPage = true;
dlg.AllowSomePages = true;
dlg.UseEXDialog = true;
if (dlg.ShowDialog() == DialogResult.OK)
print.Print();
}
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 11/9/2016(UTC) Posts: 3  Location: Hyderabad
|
The changes are not getting reflected after replacing the Text and Printing to PDF. is it possible to save to PDF ?
Regards Kiran.
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 post(s)
|
As I told before there is no a simple way to save these chages. It can be printed or viewed in PdfViewer control only. Edited by user Sunday, November 13, 2016 10:43:23 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Guest
Groups: Guests
Joined: 1/5/2016(UTC) Posts: 158
Was thanked: 4 time(s) in 4 post(s)
|
After replacing the text The changes are not getting reflected while printing to current printer from PDF Viewer.
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 post(s)
|
Originally Posted by: Guest  After replacing the text The changes are not getting reflected while printing to current printer from PDF Viewer. The code above illustrates the printing only, without viewing in Pdfviewer. If you want to view these changes in PdfViewer you should write the following code. This happens because the printing engine and PdfViewer uses distinct instances of the PdfPage. Code:
public Form1()
{
PdfCommon.Initialize();
InitializeComponent();
pdfViewer1.BeforeDocumentChanged += (s, e) =>
{
if(pdfViewer1.Document!= null)
pdfViewer1.Document.Pages.PageLoaded -= Pages_PageLoaded;
};
pdfViewer1.AfterDocumentChanged += (s, e) =>
{
if (pdfViewer1.Document != null)
pdfViewer1.Document.Pages.PageLoaded += Pages_PageLoaded;
};
}
private void Pages_PageLoaded(object sender, Patagames.Pdf.Net.EventArguments.PdfPageEventArgs e)
{
foreach (var obj in e.Page.PageObjects)
{
var textObj = obj as PdfTextObject;
if (textObj == null)
continue;
textObj.TextUnicode = textObj.TextUnicode.Replace("AAAA", "BBBB");
}
}
So if you want to view the changes and then print them, then you need to combine these two samples to achieve your goal. Also, if you want to print document using PdfToolStripMain (PdfToolbarMain for WPF), then you need to create a derived class from it and override the OnPrintClick method (https://pdfium.patagames.com/help/html/3e322275-202a-3ac4-bb09-b6d40b06d739.htm) within which you should write the code from the first sample (The call of the ReplaceTextAndPrint method) Edited by user Monday, November 14, 2016 12:07:06 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Guest
Groups: Guests
Joined: 1/5/2016(UTC) Posts: 158
Was thanked: 4 time(s) in 4 post(s)
|
Hi,
I'm trying to use this method of changing the text in a PDF but as soon as the replace is done the size of the BoundingBox is changed. How can I prevent this?
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 2/18/2019(UTC) Posts: 3  Location: Minnesota
|
Sorry to raise this from the dead, but I'm trying to modify text while printing. If I reference e.Page.PageObjects at all, I get empty pages. This is enough to cause it to happen (modification of post #4 above): Quote: print.BeforeRenderPage += (s, e) => { foreach(var obj in e.Page.PageObjects) { } };
Any help?
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 post(s)
|
This is a bug. Will be fixed in a few days. Edited by user Monday, November 18, 2019 4:22:47 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 post(s)
|
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 12/7/2021(UTC) Posts: 5  Location: Braga
|
Hi, im trying to replace some text from an open pdf. I followed this thread, my program finds the text i want to replace but after replacing, it replaces it with bugged characters. For example in the pdf i want to replace "Exemplo" with "Teste" and it sends this. [img=https://postimg.cc/7fLs89HM]print of the in and out pdf[/img] Could this be pdf file problem?
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 post(s)
|
Hello,
It seems that the font does not contain the required glyphs. Try to create a new font.
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 12/7/2021(UTC) Posts: 5  Location: Braga
|
do u mean create a base pdf with a diferent font or change font in code?
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,027
Thanks: 5 times Was thanked: 122 time(s) in 119 post(s)
|
In code. textObj.Font = PdfFont.Create(…)
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 12/7/2021(UTC) Posts: 5  Location: Braga
|
It says that "PdfFont.Create" doesnt exist. [img=https://postimg.cc/Z0FGtRFm]
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 12/7/2021(UTC) Posts: 5  Location: Braga
|
i searched and found that u were reffering to "PdfFont.CreateFont" but still i have a similiar problem. Here is my code: Code:printDoc1.BeforeRenderPage += (s, e) =>
{
foreach (var obj in e.Page.PageObjects)
{
var textObj = obj as PdfTextObject;
if (textObj == null)
continue;
textObj.TextUnicode = textObj.TextUnicode.Replace("Exemplo", "Teste");
textObj.Font = PdfFont.CreateFont(mainDoc, "Calibri");
}
};
This is the result. [img=https://postimg.cc/Zvmt8Khr]Result[/img] Edited by user Monday, December 13, 2021 6:24:06 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 12/7/2021(UTC) Posts: 5  Location: Braga
|
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close