Find end line in .pdf - c++

I'm developing a plugin for Adobe Acrobat X with C++ that copies all text from opened .pdf in a .txt file. I've tried text runs and text characters from PDEText, it copies all text but it concatenates all lines.
Q: how can I find where end line is in my text?

I made it!
I parse the text letter by letter and I check if they're on the same row verifying top or bottom attribute from ASFixedRect ( I use PDETextGetBBox() to get ASFixedRect ).
Farewell!

Related

Delete every other line in Visual Studio Code regardless of content

A colleague has inserted duplicates for ~1200 entries into our database. They have sent me a text file containing both the originals and copies in alternating lines of CSV text. I've opened that up in VS Code with the goal of converting the lines representing duplicates into DELETE statements targeting our database. No line is truly identical to another—every two is a pair in which the data is the same other than the row ID.
I have found Stack Overflow entries for removing every other line when the line is empty, or when every other line is an exact copy of the previous line. I have not found an entry this scenario in which the lines have a difference. E.g. I tried using (.*)\n\1 w/ $1\n from another SO entry, which seems to target truly duplicate lines.
So how do I use VS Code to delete every other line regardless of content?
You can achieve this using Replace-All UI in regex mode.
Press command-F or control-F
Expand the arrow on the left of the Find display
Press the ".*" so that it's highlighted
Enter this for Find (top text field in the Find UI): (.*\n)(.*)\n (basically select two lines but save the contents of the first line in the regex system)
Enter this for Replace (following text field in the find UI): $1 (take the line saved from the Find regex and re-insert it)
Hit the Replace All button
Here's a similar SO question

How to modify only timecodes but not other numbers or letters in a text file?

I'm making a program to speed up and slow down parts of videos, and I want to support modifying times on subtitles to match. How can I search for only the timecodes in a text file and modify them?
This is for srt subtitle files. Timecodes are in the format of HH.MM.SS,mmm. The files contain other numbers (eg in hex colors) so I only want to search for numbers in the specific timecode format.
I already have a function to take an input time in seconds and return an output time in seconds. It should also be fairly easy to convert between 'timecode' format and time in seconds.
This is an example of the text file:
1
00:00:00,000 --> 00:00:09,138
<font color="#CCCCCC">alexxa</font><font color="#E5E5E5"> who's your favorite president</font>
2
00:00:04,759 --> 00:00:12,889
<font color="#E5E5E5">George Washington</font><font color="#CCCCCC"> has my vote Alexa</font>
The only thing left is how to take in only timecodes and then replace them with new timecodes?
Not sure where to go from here. It would also be good to avoid looping through the text file more than necessary because there will be a lot of timecodes to change.
Given it's a text format, the most efficient way to match (and replace) the format of the time-stamps in your file would be to use regular expressions: https://en.cppreference.com/w/cpp/regex
the algo would you like this: you read line by line from your source file, for
every read line where RE matches, you replace it with the new time-stamps (i.e. craft a new line) and output to a new file (or to a buffer, which later could be committed into the source file - after processing is done). Other lines (where RE does not match) you output intact, as they were read.

Change text in aepx file programmatically

I am trying to develop an API using PHP, Which will receive Text from user as Input.
I need to change text inside the aepx file. On my research I found <string> tag and <ldata> contains text value and corresponding its hexadecimal value respectively.
I am able to parse and replace text of <string> tags in aepx.
I am also able to change the hexadecimal values of bdata attribute of <ldata>.
But after all the changes I have made, it is not rendering(tried to run using aerender command). Also After Effect Application(latest -cc 2018) is crashing while opening changed aepx file.
Example:
Original
<ldta bdata="0000000c00020000000000010000000000005da80000000000005da8000afc8000005da80000008700 0000000000000000000000000000000000000100010000506c616365686f6c6465722074657874000000000000 000000000000000000000000000200000000000000000000000100000000000000000000000000000000000000 0300000000000000000000000000000000000000000000000000000000"/>
<string>Placeholder text</string>
After Change
<ldta bdata="0000000c00020000000000010000000000005da80000000000005da8000afc8000005da80000008700 000000000000000000000000000000000000010001000048656C6C6F20576F726C642100000000000000000000 000000000000000000020000000000000000000000010000000000000000000000000000000000000003000000 00000000000000000000000000000000000000000000000000"/>
<string>Hello World!</string>
You can do this using After Effects Expressions. Following are the steps which worked for me:
Open the project in AfterEffects
Go to Text layer you wish to modify
Click arrow icon which shows a sub section with a stopwatch icon and the text "Source Text"
ALT + click the stopwatch icon, you will see another section underneath it with text "Expression Source Text"
Give its value as "thisLayer.name"
Click File > Save as > Save as xml
This will create you a aepx file.
Open aepx file in any text editor and search for the text you wish to modify. Confirm that it looks like in the attached sample aepx image. The following is the expression line "thisLayer.name" that we created through AfterEffects in above steps.
Now change the text "This is the text to be changed" to whatever you wish,
Render and check. If all ok then it must be changed.
Attached images:
After Effects steps to setup expression
Sample aepx glimpse.
Consider: Placeholder text has 16 characters (since also counting the space char).
Make sure your new input text is same length as Placeholder text length in total characters (you can use spaces to increase length, where needed for shorter text).
The easiest fix is to:
Make Placeholder text have max expected length, (example: 30 chars), so in AE you create a textfield and press space 30 times (or make 10 spaces then copy these 10 blank chars and re-paste them another 2 times).
Your PHP API should check the input text length and if below 30 chars, fill remainder with space " " maybe using a For loop. If input is above the 30 limit, then trim down to first 30 chars and ignore the rest.
The final string should be same length as the text-field you made in A.E. Your API can now safely place the final text into your AEPX file.

replace all ocurances in text that are not followed by a number

I have a textbox where a user writes basically anything. This text needs to be searched and replaced inside a txt file. But only those ocurances that are not followed by a number are suposed to be replaced. So for instance if the textbox contains "hello2" then every ocurrance of "hello2" in the txt file needs to be replaced with "customtext1" but if for example it finds "hello23" inside the txt file it is not suposed to replace it. Opening the file, making a search and replace etc. is not a problem. Problem is to check if the next char is a number. And it might also be a problem if hello2 is the last word of a row or the file, so it has no character following it. How can I do this the easy way?
Thanks
edit:
The word that gets replaced must have either a whitespace, or a symbol such as .,!?/-_ or be the beginning of a row.
[\n .,!?/-_]hello2[\n .,!?/-_]
I think this regex should work for what you described would be nice to have some sample text to test it

How to programmatically Paste CSV text into Excel and not just go into one cell? (C++)

I have a list/grid in an MFC (c++) application. I would like the user to be able to copy and paste the data into a spreadsheet.
I've placed the data in the clipboard and the text makes it to the clipboard ok and I can paste it to notepad or Word or Excel, but Excel does not interpret the comma separated value-ness of my clipboard content - so it just goes into one cell/one column - rather than doing what I had hoped.
I hope there is something simple I am missing.
Any suggestions to get this to work?
I am not quite ready to make this a drag/drop source (which is in the task list)
EDIT:
I have it working - commas can't be used - must be tab separators
But now there is a new problem:
The issue now is that if I paste to excel using '\n' as line separator it looks good in excel but not in notepad.
If I make it "\r\n" then notepad looks correct but excel then has blank lines.
Any suggestions on how to make both consistent?
I used this question and tabs seem to work - but csv still does not
How to paste CSV data to Windows Clipboard with C#
Well, here's my two cents..
It seems a tab character in an NSString, such as #"123\t456" would tell Numbers and OpenOffice spreadsheets, that 456 goes into the next cell of the same row.
Likewise, a newline character \n, or a carriage return \r, would put follow-up data on a new row, for example #"123\n456" or #"123\r456" would put 456 in the next row (starting with the first column from the left).
Indeed, TextEdit does not interpret the newline (\n) or carriage return (\r). (OpenOffice text documents do.)
However, providing the pasteboard with an array of strings (be it NSStringPBoardType, or NSRTFPBoardType, or whatever), puts the different strings on seperate rows, both in a spreadsheet and in TextEdit.
Also, a tab (\t) shows up as a tab in TextEdit, which you can then manipulate in the toolbar, to get a nice layout of your data.