1
    var PDF = new ActionAsPdf("TestReport", null)
    {
            FileName = "TestFile.pdf",
            PageOrientation = Rotativa.Options.Orientation.Landscape,
            PageMargins = { Left = 1, Right = 1 }
    };
    byte[] PDFData = PDF.BuildPdf(ControllerContext);

Is it possible to check for a string (eg. "Daily Task") in the 'PDFData' ? Please guide me. Thanks!

DevSa
  • 178
  • 3
  • 16
  • 1
    Maybe take a look at https://stackoverflow.com/questions/283456/byte-array-pattern-search – Sean Mar 03 '20 at 15:41

1 Answers1

2

Try to convert byte array into string:

var str = System.Text.Encoding.Default.GetString(PDFData);
var isContains = str.Contains("Daily Task");

An example:

string dailyTask = " Daily Task ";
byte[] PDFData = Encoding.ASCII.GetBytes(dailyTask);
var str = System.Text.Encoding.Default.GetString(PDFData);
var isContains = str.Contains("Daily Task");
Console.WriteLine(isContains);
StepUp
  • 36,391
  • 15
  • 88
  • 148
  • example works as expected. Is it possible to scan the text which is printed on the pdf? This is what I am trying to achieve. – DevSa Mar 05 '20 at 06:35
  • @DevSa Does your `PdfData` contain text printed in pdf? If yes, does the above code find your desired string? – StepUp Mar 05 '20 at 07:20
  • Nop. I cant find any text from the generated pdf in pdfData. – DevSa Mar 05 '20 at 08:46
  • According to my question in the title your answer is correct. – DevSa Mar 05 '20 at 08:56
  • @DEvsa it looks like text of pdf file is stored differently and we cannot find the desired string or encryption is different. You can unmark my reply. It is ok. Maybe you need to create another question "How to find string in generated array by rotativa"? – StepUp Mar 05 '20 at 09:17