Prior to printing code, i open and mark the doc with pdfdocument, then save it with:
PdfLoadedDocument document = new PdfLoadedDocument(file.Path);
// do the redacting work
document.Save(filePath);
then i have this code to open that file and print:
//Load PDF file.
pdfViewer.Load(filePath);
//Set the document name to be displayed when printing the document.
pdfViewer.PrinterSettings.ShowPrintStatusDialog = false;
//Print the file.
pdfViewer.Print();
pdfViewer.Unload();
I am printing a 1-page file, i get a blank page, regardless of printing to printer or one note. also, the saved file opens in several pdf viewers, shows the redactions, but when printed from them, no redactions show.
Hi Dave,
Thanks for contacting Syncfusion support.
We are unable to reproduce the reported issue on our side. We have tried to reproduce in the sample, which was created based on the code, you have shared in the forum. We have attached the sample which we have tired and video for your reference.
We request you to modify the above sample or provide the PDF document which you have tried to open and load in PdfViewer. Also please share the below details to analyze more on this and assist you with a better solution.
1. Syncfusion product version.
2. .Net Framework
Regards,
Krithika
Thanks, it seems i required this line to make my code work:
document.Close(true);
I did not want to start a new thread. THis code looks right. But i get a weird behavior.
First i redact a list of terms, then i annotate a second list.
If an annotation is in the same line as a redaction, the annotation is several characters to the right of where it should be.
Green arrows are good, red not good
// CODE
public partial class MainWindow : Window
{
private List<string> ldList = new List<string>();
List<string> terms = new List<string>();
System.Drawing.Color redaxColor = System.Drawing.Color.Black;
string filePath = @"c:\pdfs\med-report.pdf";
string outFile = @"c:\redacts\outfile.pdf";
string outFile2 = @"c:\redacts\with-highlights.pdf";
// load document
PdfLoadedDocument document;
public MainWindow()
{
InitializeComponent();
Width = 0;
Height = 0;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
terms.Add("shapiro");
terms.Add("friedman");
ldList.Add("amoxicillin");
ldList.Add("allergies");
doRedact();
// DoHighlight();
LoadToPrint();
Close();
}
private void doRedact()
{
document = new PdfLoadedDocument(@"c:\pdfs\med-report.pdf");
// loop all pages
for (int i = 0; i < document.Pages.Count; ++i)
{
PdfLoadedPage page = document.Pages[i] as PdfLoadedPage;
// TESTING Check for exact matches, make list
// WE ARE DOING REDACTION HERE
//
List<MatchedItem> matches = new List<MatchedItem>();
bool found = document.FindText(terms, i, TextSearchOptions.WholeWords, out matches);
if (found)
{
foreach (var match in matches)
{
PdfRedaction redaction = new PdfRedaction(match.Bounds, redaxColor);
page.AddRedaction(redaction);
}
}
List<PdfRedactionResult> redactionResults = document.Redact();
foreach (PdfRedactionResult result in redactionResults)
{
if (result.IsRedactionSuccess)
Console.WriteLine("Content redacted successfully..." + result.ToString());
else
Console.WriteLine("Content not redacted properly..." + result.ToString());
}
List<MatchedItem> cLoseMatches = new List<MatchedItem>();
bool foundCloseM = document.FindText(ldList, i, TextSearchOptions.WholeWords, out cLoseMatches);
if (foundCloseM)
{
foreach (var cmatch in cLoseMatches)
{
RectangleF rectangleF = cmatch.Bounds;
PdfRectangleAnnotation annotation = new PdfRectangleAnnotation(rectangleF, "rectangle");
//Assign the colors
annotation.InnerColor = System.Drawing.Color.IndianRed;
annotation.Color = System.Drawing.Color.IndianRed;
annotation.Opacity = 0.4f;
annotation.SetAppearance(true);
//Add the annotation to the page.
page.Annotations.Add(annotation);
}
}
}
document.Save(@"c:\redacts\with-highlights.pdf");
document.Close(true);
}
private void LoadToPrint()
{
//Load PDF file.
pdfViewer.Load(@"c:\redacts\with-highlights.pdf");
pdfViewer.PrinterSettings.ShowPrintStatusDialog = false;
pdfViewer.Print();
pdfViewer.Unload();
}
}
;
Hi Dave,
Currently we are working on your requirement to reproduce the issue in our end. we will check and provide further details on August 29th , 2022.
Meanwhile, we request you to share the input document to replicate the issue. so that it will be helpful for us to assist with you further in this.
Regards,
Irfana J.
i thought it was when we had a redact and annotation in the same line, however, that is incorrect as seen in the second line in the above image (first line with any markings).
i have one more question, how do i eliminate the yellow popup on mouseover?
as you can see in debug, the path is there and correct
Hi Dave,
i thought it was when we had a redact and annotation in the same line, however, that is incorrect as seen in the second line in the above image (first line with any markings). | We were able to reproduce the reported behaviour with the provided details on our end. Currently we are validating on this and will provide the further details on September 1 , 2022
|
i have one more question, how do i eliminate the yellow popup on mouseover? as you can see in debug, the path is there and correct
| We tried to reproduce the reported issue on our end with the provided details, but we could not be able to reproduce the issue. Please share the below details to analyze more on this and assist you with a better solution.
1. Stack trace details for the issue.
2. Any restriction was set for document or folder( Kindly share the details).
|
Regards,
i have resolved the path issue.
The annotation issue seems to be that the first match is not annotating. Not sure if it is bounds
Hi Dave,
Thank you for confirmation. We will update the details in this forum #177128.
Regards,
Irfana J.
It is not the first match it is the first term in the first search that is not firing.
bool found = document.FindText(terms, i, TextSearchOptions.WholeWords, out matches);
in the line above, terms is a list of terms to find. it is not finding the first term in the list of terms.
Hi Dave,
Sorry for the inconvenience caused.
Due to complexity, still we are validating the reported issue on our end and we will update the further details on September 05th, 2022.
Regards,
Gowthamraj K
Hi Dave
We have confirmed the issue “Annotation not added properly based on the find text result in a redacted same line” as a defect in our product. We will include the fix for the reported issue in our upcoming weekly NuGet release on September 20th, 2022.
Please use the below feedback link to track the status of the reported bug,
Note: If you require a patch for the reported issue in any of our Essential Studio Main or SP release versions, then kindly let us know the version, so that we can provide a patch in that version based on our SLA policy.
Regards,
Gowthamraj K
I cannot view the link, access is denied, and I will need a patch as soon as one is available.
It also seems relevant to ask if using the pdfviewer control to accomplish the same things might be a workaround?
I tried it, exact same results.
Next, i will try to break the lists into sequences of load file, search a term, save.
Hi Dave,
|
I cannot view the link, access is denied, and I will need a patch as soon as one is available.
|
We have added your mail in this feedback link, now you can able to access.
Please let us know any of our Essential Studio Main or SP release versions, so that we can provide a patch in that version based on our SLA policy.
|
|
|
It also seems relevant to ask if using the pdfviewer control to accomplish the same things might be a workaround? I tried it, exact same results.
|
In PdfViewer, we are using the loadedDocument FindText API internally. Hence it returns the same value based on the loadedDocument FindText API . Once the issue is resolved on the loadedDocument side, it will properly work with PdfViewer.
|
Please let us know if you need any further assistance.
Regards,
Gowthamraj K