is there any other way using aspose.pdf to achieve this functionality
eg. create one blank pdf document and then copy each page from original file to newly created file
with some margin (eg. header height is 100px then we can copy page from old document and start it from 120px in new document)
We have create one web application, in .net and we need to do some manipulation in PDF while user upload pdf file before saving it on server.
Suppose i need to redact any information from Pdf then how can i do this.
our requirement is we remove email address from Pdf file and then we need to save it
tatvasoft2014: We have create one web application, in .net and we need to do some manipulation in PDF while user upload pdf file before saving it on server.
Suppose i need to redact any information from Pdf then how can i do this.
our requirement is we remove email address from Pdf file and then we need to save it
Hi Jignesh,
Thanks for contacting support.
You may consider parsing the PDF document and try removing the email address information. May be you can use RegularExpression to search for email addresses or search for @ character and remove the text after it. For more information, please visit Replace Text Based on a Regular Expression
Hello,
Thanks for you reply. Can you please check my another query in same forum regarding PDF settings and reply me ASAP.
Thanks,
Jignesh Chauhan
Hello,
I gone through example provided in link given by you, but getting some issue while replacing text.
1. Content after 1999-2005 are blank after replacing it with xxxx-xxxx. (e.g. paragarphs contains 1995-2005 in middle of the paragraph then all next statement after 1995-2005 are blank after executing code given in sample)
2. If Content is wrap in next line then it is not replace with xxxx-xxxx eg. 1999- in first line and then due to no much space in same line 2005 are wrap in next line then this code is not working.
3. First case working fine if we put this line in table.
Please reply as soon as possible
Thanks,
Jignesh Chauhan
Hi Jignesh,
Can you please share the source PDF file along with code snippet which you are using so that we can test the scenario at our end.
Hello,
Please find attached files in which I perform replace some value. In this demo I replace year(xxxx-xxxx) fromat.
In Demo35 some information is removed. For reference I also attached generated file in zip.
In Demo32 value is not replace due to value is split in two rows.
Code :
//open document
Document pdfDocument = new Document(txtFilePath.Text);
//create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("\d{4}-\d{4}"); //like 1999-2000
//set text search option to specify regular expression usage
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
textFragment.Text = “xxxx-xxxx”;
//set to an instance of an object.
textFragment.TextState.Font = FontRepository.FindFont(“Calibri”);
//textFragment.TextState.FontSize = 22;
//textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue);
//textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green);
}
pdfDocument.Save(txtNewFile.Text);
And also I need to apply same font and size as original text in PDF while replacing year with xxxx because of if font size of the text is less than which I used in above code then next statement is overwrite with replaced value(xxxx-xxxx)
And also let me know how I can remove mailto link from PDF Document.
Please reply ASAP.
Thanks,
Jignesh Chauhan
tatvasoft2014: In Demo35 some information is removed. For reference I also attached generated file in zip.
Hi Jignesh,
Thanks for sharing the resource files.
I have tested the scenario and have noticed that above stated issue occurs when using the API in trial mode. The problem does not appear when using a valid license. For your reference, I have also attached the resultant PDF generated over my end.
tatvasoft2014: In Demo32 value is not replace due to value is split in two rows.
I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWNET-36746 in our issue tracking system.
tatvasoft2014: And also I need to apply same font and size as original text in PDF while replacing year with xxxx because of if font size of the text is less than which I used in above code then next statement is overwrite with replaced value(xxxx-xxxx)
When using the valid license, you can get the font size and name information and use the same information while replacing the text.
tatvasoft2014: And also let me know how I can remove mailto link from PDF Document.
You may consider setting the link target to null. Please follow the instructions specified over Update Links in a PDF File. In case the problem still persists, please share the sample PDF file. We are sorry for your inconvenience.
Hi Jignesh,
Please follow the instructions specified over following link for further details on how to Get a temporary license
Hello,
When I am going to replace 10 digit with xxxxxxxxxx using below code. It
is working properly if there is single occurrence of 10 digit but same
code is not working if I keep 10 digit two times in line. For eg. If I keep
9898989898 it will replace with xxxxxxxxxx but when I keep this as 9898989898 /
1234567890 then code is replace only first occurrence (9898989898 is replaced)
but 1234567890 is remains as it is.
I got same issue while replacing email address instead of 10 digit.
Code which I used is as Under
TextFragmentAbsorber textFragmentAbsorberForPhoneNumber = new TextFragmentAbsorber("\\d{10}"); //like 1999-2000
//set text search option to specify regular expression usage
textFragmentAbsorberForPhoneNumber.TextSearchOptions = textSearchOptions;
//accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorberForPhoneNumber);
//get the extracted text fragments
textFragmentCollection = textFragmentAbsorberForPhoneNumber.TextFragments;
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
//update text and other properties
textFragment.Text = "XXXXXXXXXX";
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
}
Please reply ASAP.
Thanks,
Jignesh Chauhan
Hi Jignesh,
Thanks for your inquiry. I am afraid while testing the scenario with Aspose.Pdf for .NET 9.1.0, we are unable to replicate the issue. Please download and try latest version of
Aspose.Pdf for .NET, it will fix the issue. If issue persist then we will appreciate if you please share a console application to help reproduce the issue for further investigation.
We are sorry for the inconvenience caused.
Best Regards,
Hello,
Thanks for sharing new Dll. I check and it works fine. Still I have one more question regarding PDF. How can I disable all links from PDF document.
Please find attached pdf file for sample. In this PDF I have added one link, and I dont want to allow user to click on that link and open URL. I Check this with below code but it is not working.
Code :
----------------------------
string urlPattern = @“http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=]*)?”;
foreach (Aspose.Pdf.Page page in pdfDocument.Pages)
{
//LinkAnnotation linkAnnot = (LinkAnnotation)pdfDocument.Pages[1].Annotations[1];
foreach (LinkAnnotation linkAnnot in page.Annotations)
{
Regex rgxURL = new Regex(urlPattern);
if (rgxURL.IsMatch(((Aspose.Pdf.InteractiveFeatures.GoToURIAction)(linkAnnot.Action)).URI))
{
page.Annotations.Delete(linkAnnot);
}
}
}
Please reply ASAP.
Thanks,
Jignesh Chuahan.
Hi Jignesh,
Thanks for your inquiry. Please check following code snippet to set empty URI for the link. Hopefully it will help you to accomplish the task.
// load the PDF
file<o:p></o:p>
Document doc = new Document(myDir
+ "Web+URL.pdf");
// get the first
link annotation from first page of document
LinkAnnotation linkAnnot =
(LinkAnnotation)doc.Pages[1].Annotations[1];
// Modification
link: change link URI
GoToURIAction goToAction =
(GoToURIAction)linkAnnot.Action;
// specify the URI
for link object
goToAction.URI = String.Empty;
// save the
document with updated link
doc.Save(myDir+"PDFLINK_Modified_output.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
Dear
Tilal Ahmad
I have also tried above sample code, but if We set goToAction.URI = string.empty then it is not open current URL but user is able to click on that link and new window of browser is opened. So need to disable that link not want to set action to blank, because while I set action to blank then it is open blank page in browser.
In my previous post I gave you sample code which I used but that code is working in case of I am updating the text (e.g. In document Url is www.aspose.com when I replace this URL with xxxxxxxxx and execute that code then it works fine.)
- OR -
Is there any way to remove all the hyperlinks from the document.
Thanks,
Jignesh Chauhan
tatvasoft2014:
Is there any way to remove all the hyperlinks from the document.
Hi Jignesh,
Thanks for sharing the details.
I am afraid the current release of Aspose.Pdf for .NET does not support the feature to remove hyperlinks from PDF file. However for
the sake of correction, I have logged this requirement in our issue tracking system as PDFNEWNET-36764. We will
investigate this issue in details and will keep you updated on the status of a
correction.
We
apologize for your inconvenience.