Removing text using pdfSweep - wildcard? - itext7

using pdfSweep to redact text - works fine when I know exactly what "string" I want to remove e.g. ID: 12AAFF113 but I won't always know the number appearing after ID: so how can I remove ID and x number of characters afterwards -
does it allow wildcard support or similar?
Dim input As String = "G:/tmp/redact/input.pdf"
Dim output As String = "G:/tmp/redact/output.pdf"
Dim strategy As New CompositeCleanupStrategy()
strategy.Add(New RegexBasedCleanupStrategy("ID: 12AAFF113"))
Dim pdf As New PdfDocument(New PdfReader(input), New PdfWriter(output))
Dim autoSweep As New PdfAutoSweep(strategy)
autoSweep.CleanUp(pdf)
pdf.Close()

Yoy can use PdfAutoSweep and RegexBasedCleanupStrategy.
For example, in the following snippet it's shown how to remove all appearances of (D|d)olor regex string.
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
strategy.add(new RegexBasedCleanupStrategy("(D|d)olor").setRedactionColor(ColorConstants.GREEN));
PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));
// sweep
PdfAutoSweep autoSweep = new PdfAutoSweep(strategy);
autoSweep.cleanUp(pdf);
pdf.close();
The regex in your case should be "id:\s(\w){7}" or summat.

Related

How to avoid non-printing items from printing after flattening PDF

I recently upgraded from iText5 to iText7.
I'm using iText7 to flatten documents to remove interactivity. I expected that the printed document would look the same before and after flattening. Unfortunately that's not the case.
The source pdf has non-printing Button objects that are set to "Visible but doesn't print". After flattening, the undesired fields do print.
Is there a setting I'm missing, or do I need to remove non-printing buttons, fields etc before flattening?
Public Shared Function FlattenPdf(SourcePath As String, DestPath As String) As String
Using reader As New Pdf.PdfReader(SourcePath)
Using writer As New Pdf.PdfWriter(DestPath)
'Opens PDF document in the stamping mode
Dim pdfDoc As New Pdf.PdfDocument(reader, writer)
Dim form As Forms.PdfAcroForm = Forms.PdfAcroForm.GetAcroForm(pdfDoc, createIfNotExist:=True)
'flatten the form to remove editing options
form.FlattenFields()
pdfDoc.Close()
End Using
End Using
Return DestPath
End Function

How to create image file from vfp filetostr() string in c#

Use vfp's filetostr() function to store the string returned by the image file into the text type field of sql server
So how to create a picture file after reading a string from sql server with C#?
What encoding is the string returned by filetostr and what type is it in C#
FileToStr() reads any file either binary or not. You never store a binary file to SQL server's text field. Text data type is depreceated anyway. You use Varbinary(MAX) instead.
There is no special encoding returned with FileToStr(), it simply reads any file as is with no character encoding conversion. IOW, you can think it as ASCIIEncoding. In C# it is byte[] (not a char[]) - same as doing a File.ReadAllBytes()-. If you look a file using a hex editor, you would see hex bytes, FileToStr() gets all those bytes as a single string (unlike C#, in VFP a string can contain any ASCII character including character 0x00).
You can simply get it as a byte[] and create Image using Image.FromStream(). ie:
void Main()
{
byte[] mySavedPic;
using(SqlConnection connection = new SqlConnection(#"server=.\SQLExpress;Trusted_connection=yes;Database=ImageDb"))
{
SqlCommand cmd = new SqlCommand("select Picture from myPictures where pictureId = 1",connection);
connection.Open();
mySavedPic = (byte[])cmd.ExecuteScalar();
connection.Close();
}
Form f = new Form();
PictureBox p = new PictureBox();
p.SizeMode = PictureBoxSizeMode.StretchImage;
p.Dock = DockStyle.Fill;
using (MemoryStream ms = new MemoryStream(mySavedPic))
{
p.Image = Image.FromStream(ms);
}
f.Controls.Add( p );
f.ShowDialog();
}

Trouble with using multiple actions within a if statement

everytime i code using multiple actions, it doesnt produce and output and the code doesnt work at all until i give it one action alone instead of three, i dont know whats wrong with it, i tried to put this code in if statements and/or just left it alone as an action when pressing the save button
heres the code \ btw im using visual studio 2012
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim Path1 As String = "Backups\"
Dim Path2 As String = rtbTitle.Text + "\"
Dim FullPath As String = Path1 + Path2
Dim textfileTitle As String = "title.txt"
Dim textfileDescription As String = "description.txt"
Dim textfileTag As String = "tag.txt"
Dim textfileChannel As String = "channel.txt"
If Directory.Exists(FullPath) Then
rtbTitle.SaveFile(FullPath + textfileDescription, RichTextBoxStreamType.PlainText)
rtbDescription.SaveFile(FullPath + textfileDescription, RichTextBoxStreamType.PlainText)
rtbTag.SaveFile(FullPath + textfileDescription, RichTextBoxStreamType.PlainText)
End If
End Sub
Add Option Explicit and Option Strict to the top of your code file (or set them as defaults) and you'll soon see where you're getting into trouble.
One problem that will show up is that you're using '+' to concatenate strings, you really should use '&'. You may unwittingly have typos in your control names or be inputting bad data for the paths. All these sorts of errors are covered up until run time unless you set those options.
After that add a Try...Catch block around your code, run it and view the error.

Parsing double superCSV with comma as decimal separator?

I Want to parse a double with comma as decimal separator (',' instead of '.') using SuperCSV CellProcessor
I want to parse the first element (0,35) to Double
0,35;40000,45
I have tried something like that :
/** FRENCH_SYMBOLS */
private static final DecimalFormatSymbols FRENCH_SYMBOLS = new DecimalFormatSymbols(Locale.FRANCE);
DecimalFormat df = new DecimalFormat();
df.setDecimalFormatSymbols(FRENCH_SYMBOLS);
final CellProcessor[] processors = new CellProcessor[] {
new NotNull(new ParseDouble(new FmtNumber(df))),
new NotNull(new ParseBigDecimal(FRENCH_SYMBOLS)) };
ParseBigDecimal works just fine but the parseDouble doesn't seems to work, it gives me an exception : org.supercsv.exception.SuperCsvCellProcessorException: '0,35' could not be parsed as a Double
You're totally correct - ParseDouble doesn't support a French-style decimal separator (comma), but ParseBigDecimal does. If you think this is a useful feature, why not submit a feature request.
The simplest workaround is to simply chain a StrReplace before the ParseDouble to convert the comma to full stop.
new StrReplace(",", ".", new ParseDouble())
Alternatively, you could write a custom cell processor that either:
parses a Double (with a configurable decimal separator)
converts a BigDecimal to a Double (calling doubleValue()) - this can then be chained after your new ParseBigDecimal(FRENCH_SYMBOLS)
Oh, and in future you might want to mention that your file is semi-colon separated and you've set up Super CSV with CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE :)

How can I remove a line of text from a text file in VB6? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to read a file and write into a text file?
I have a search facility where items are displayed in a ListView. These items are read in from a file. When I select an item in the ListView I want to be able to remove it from the text file as well.
At the moment, it is is only removed from the ListView but when I search again it still displays so it isn't being deleted from the text file.
Basically my program is a list of products with their barcodes and quantities. The user can search for an item, which is displayed in the listview, then edit it to add or reduce the quantity. When they click save it is written to the file. That is all working fine, but it is now showing the item twice, same barcode and product name and different quantities.
I tried to use the replace function but that is just adding empty lines of text to my file.
I have also gotten advice to copy the file and remove the selected item. I'm unsure how to do this. Does anyone have any alternative ways to do this?
Here is my code:
Private Sub cmdEdit_Click()
Dim barcode As String
Dim prodNum As String
Dim unknown As String
Dim desc As String
Dim size As String
Dim costPrice As String
Dim retailPrice As String
Dim deptCode As String
Dim dept As String
Dim subDeptCode As String
Dim subDept As String
Dim quantity As String
Dim barcodeYes As String
Dim Number As String
Dim i As Single
ListView1.ListItems.Remove ListView1.SelectedItem.Index
Open "D:\VB\EXPORT PRODUCT FILE.CSV" For Input As #3
Input #3, barcode, prodNum, unknown, desc, size, costPrice, retailPrice, deptCode, dept, subDeptCode, subDept, quantity, barcodeYes, Number
AddQuantity.Show
AddQuantity.txtName.Text = ListView1.SelectedItem
AddQuantity.txtBarcode.Text = ListView1.SelectedItem.SubItems(1)
AddQuantity.txtQuantity.Text = ListView1.SelectedItem.SubItems(2)
Close #3
End Sub
Thanks
The only way to remove something from the middle of a file is to rewrite eveything from that point onwards.
You haven't showed your code to write to the file but I assume you're appending.
You'll need to change this to load all data, change the entry you want then save it all again.
Alternatively, use a database which is designed for this kind of use.

Resources