Aspose, append Pdf's without extra space - aspose

I've got list of Pdf objects (or Streams) and would like to append them that there wont be extra white space between them. Aspose 'PdfFileEditor.Concatenate' adds next Pdf starting from next page but I'd like to add it immediately after previous finishes.
Is it possible?

I don't know if that was possible (there wasn't much time) so had to refactor the code that only one stream was created with correct layout.

Related

Check if <fo:page-number> is even or not using XSLT 2.0

How to check the <fo:page-number> is even or odd using xslt 2.0 Is there any way to use <fo:page-number> inside <xsl:if test="fo:page-number mod 2 = 0">
The XSLT stage generates the XSL-FO that the formatter then makes into pages. So, no, you can't get the current page number when you are generating the XSL-FO.
What do you want to change if it is an even-numbered page?
With XSL-FO, you can set up different page masters for odd and even pages (and more besides). The different page masters can have different margins, and you can set things up so that the formatter will direct different content to headers and footers on even pages than is used on odd pages.
See the 'Page Region and Structure' PDF and FO files in the 'XSL-FO Samples Collection' at https://www.antennahouse.com/xsl-fo-samples#structure
What you ask for cannot be done with a true batch formatter in a single pass. It requires "human" intervention to mark only those places where the break needs to occur and not others.
Also, there is no guarantee that one XSL FO formatter might yield different results than another. Because of the complexities in the way some formatters handle "line tightness" (which is very small squeezing of spaces and characters together to fit text within a line) as well as some supporting kerning and others not as well as many other factors, it is not possible to "pre-predict" whether some paragraph will appear/start on a page or not.
Formatting text in true typography is not merely word-space-word-space ... there are many other factors involved that could change the number of lines in a paragraph between one formatter and another which can easily ripple to a known paragraph existing on an even page in one formatter, yet an odd page in a different formatter.
Then you also need other rules like what if your paragraph using your formatter of choice is the first one on your page in which you wish to break. Do you want a blank page? Maybe, who knows?
The only way to accomplish your task is through a multipass approach that could be implemented such that it is generic to any formatter. You would need to format a whole document (or if you are chunking that document with page masters) at least a chunk that starts and ends in page boundaries. Format it, test your condition on the first paragraph. If it passes (meaning if a break is needed), go back to original content (or modify the XSL FO) and mark some attribute that would result in break-before="page" on that structure. Then repeat the process until you reach the end of the document. Some formatters can provide you the area tree and markers you can put in that tree so that you could do this programmatically and not by eye).
If your document is long and in one page-sequence (say like 3000 pages when formatted) and your break condition is frequent, you may have to repeat the process 700+ times.
As stated, some formatters through their API may allow you to control this programmatically. You can examine the area tree, look for your marker and keep count of pages. You may even be able to start formatting again at the break condition and not start over, but you need to program such things.

How to on one page sequence decide begining of a new node to insert different header

EDIT AFTER GETTING CORRECT RESULT:
Ok, I managed to do that. Basically when I understand what really #Kevin wants me to do, I created empty marker on the begining of topic (with keep-with-next), and after title of topic is created I changed it to normal header. Now everything is ok.
EDIT:
I tried #Kevin-Brown suggestion, but probably I did something wrong. I will show minimal version, to give an general image of that what happened.
I got:
flow
block with normal header marker
block with keep-with-next always, and empty marker which actually doesnt matter in my case
block with content
and header looks like:
<fo:block>
<fo:retrieve-marker retrieve-class-name="body-header-marker" retrieve-position="first-including-carryover" retrieve-boundary="page"/>
</fo:block>
Problem is that header is no really carryover. Because right now, even if I remove empty marker, I will have header on the page with the topic, and I won't have anything on next pages of topic. Then again I will have one again on the begining of the topic. What I did wrong?
OLD QUESTION:
I am working with Formatting Objects, and I have some problems with finding good (actually any) solution in same cases. Is there any way to check if currently processing node actually taking 2 pages?
Maybe if I try to define the problem, you can suggest some better solution. I have multiple topics in xml, and during processing of topic, I adding header and footer to every page. I want to change it, to not add header, on page where title of new topic is located (topic starts from new page). So maybe there is better way to do what I want, than checking pages. Because I think that because of different approach to "variables" in functional programming, I might be not able use page as I wanted.
The general principle you want in pseudo markup is this:
block-container for topic
throw marker containing the header for the topic
... content of topic ...
end block-container for topic
block-container with empty marker keep-with-next as "always"
throw marker with nothing in it (basically clear the marker)
end block-container with empty marker
block-container for topic
throw marker containing the header for the topic
... content of topic ...
end block-container for topic
... and so on ...
So you pull the marker first-including-carryover into your header. This means the first marker whose parent container starts at the top or carry's over from the last page.
If your page starts perfectly with the start of a topic, the first marker on the page will be the empty one. This is because you are gluing the empty marker block-container to the start of every topic. There is no content in this structure, it will not corrupt your output. I did not show above putting the empty marker container above the first topic, but do that also if you want.
If your page breaks inside a topic, then the "carryover" marker would be pulled which would have the header of the topic from the previous page pulled. Normally this marker would include something like "- Continued" at the end.
You could put every topic in a separate fo:page-sequence and use an fo:page-sequence-master (http://www.w3.org/TR/xsl11/#fo_page-sequence-master) to select a different fo:simple-page-master just for the first page. You could make it so that page-master has a different header.
See, e.g., 'Switching the layout in facing pages automatically (page-sequence-master)' in http://www.antennahouse.com/antenna1/comprehensive-xsl-fo-tutorials-and-samples-collection/, although you would probably want to select on page-position="first" rather than odd-or-even.

Creating users for game(reading and parsing CSV file)

So I am working on a planets vs zombies type mock up game for class, and am using Qt Creator GUI with C++. One of the things that we are required to do is, on start-up, the game window will attempt to read two files: "pvz_levels.csv" and "pvz_players.csv" from a pre-specified home directory.
The levels file is of the form "level:sequence:rows:start:interval:decrement" and "sequence" itself is a comma separated list of the form (1,1,1,2,3,1,3,1,3,3) which is the sequence in which zombies appear. If this file does not exist in the directory, the program exits with an error.
The players file is of the form "timestamp:player:level"; the time of last play, name of player, and last attempted level, respectively. If this file does not exist, the program silently skips this operation and starts as a new player. If it does exist, the file must be read and parsed, and then used in the program for calculations and such.
So, I am having much trouble with reading and parsing these files. Furthermore, we are required to save the user data in these files, and on the next start-up the user should have the option to continue their game by selecting their respective user from a drop-down list. They should also be able to delete any users.
I am proficient enough with c++ basics but this is my first GUI experience and my prof did not go over it in much detail, so I require quite a bit of help with this project.
Thank you to anyone who is able to help!
Look up the code to an available "csv parser" which stands for "comma separated variable". You need is almost identical, except you use a semi-colon instead of a comma. It seems that by changing one character you parsing is done for you.
You may be able to find a csv parser that accepts the character to be used as the parsing character (I've seen them before).
If you wish I can find a suitable csv parser for your use, but now that you know what you're looking for "csv parser c++ code" it should be a quick Google away.
Also, most csv parsers expect strings to be enclosed to double quotes (") but that is easily modifable.
Some hints:
Just open the File using QFile. Set up a QTextStream and use QTextStream::readLine() to read all Lines into QStringList. Now use QString::split() on the QString saved in the list to get the single values stored in this line. From there you can easily use QString::to* functions to cast the values into your desired type.
For saving just reverse the procedure.
Set up a line using: QString("%1,%2,%3").arg(timestamp).arg(player).arg(level) and put it into your QTextStream. If the stream is connected to a file, this will be written into the file.
I've implemented successfully the CSV reading like this:
std::unique_ptr<QFile> csv_worker(new QFile(resource_path));
QTextStream input_csv(csv_worker.get());
QList<QStringList> data
while(!input_csv.atEnd())
{
//removes the carriage return symbol and splits the elements
QStringList line = input_csv.readLine().remove(QRegExp("\r")).split(","); //replace here with :
data << line;
}
csv_worker->close();
It reads the complete file, each line generates a QStringList.
For the second element in the QStringList, let's say (1,1,1,2,3,1,3,1,3,3}, you have to additionally split that in a sub-QStringList, removing then brackets with something like this:
QStringList sequence = data[i][1].remove(QRegExp("{")).remove(QRegExp("}")).split(",");

Is there anyway to rename the "Source" button to something like "HTML"?

Is there anyway to rename the "Source" button to something like "HTML", I ask this as users are confused at how to add html code using the editor?
Yes, inside of the "lang" folder you will see all of the various language files.
For my case, and probably yours, You will want to edit the file "en.js". The file is "compressed" to some degree so it may be difficult to read, but it's still not too difficult to change one string. If you do plan on changing multiple strings you will most likely want to use a service to format Javascript.
Search for the following segment of code. It was one of the very last lines in the file.
"sourcearea":{"toolbar":"Source"}
change it to
"sourcearea":{"toolbar":"HTML"}
Avoid This Method Unless Required
And as for a very unsuggested method, since you can't modify the language files for some reason, you can modify the ckeditor.js file and force a specific label.
Inside of "ckeditor.js" change the line below
a.ui.addButton("Source",{label:a.lang.sourcearea.toolbar,command:"source",toolbar:"mode,10"});
to the follow code
a.ui.addButton("Source",{label:"HTML",command:"source",toolbar:"mode,10"});
The only thing modified is the "label" value in the above line. We remove the reference to the a.language.sourcearea.toolbar and insert a string in it's place instead.

Winapi: edit control not expanding its buffer

According to MSDN:
When the system creates an edit control, it automatically creates a text buffer, sets its initial size, and increases the size as necessary.
Yeah, only it doesn't. I have an edit control in my app that shows various logs, and I keep adding text to it using EM_SETSEL message (to find the end of the text in control's buffer) and EM_REPLACESEL message (to append some text to it). I don't know if it's a best way, but it's been working well so far. Today, however, I found out that if I try to append some text when there are lots of logs in edit control already, my app fails to do so. Maximum lenght of text that's shown in it is equal to 30k characters and when I try to append any more logs, it just fails, nothing happens. At first I set it as read-ony edit control, but nothing changes if I make it editable. Just when I try to type more than 30k characters in it, it acts as if I wasn't typing anything.
And now: I know that you can handle buffer expanding by yourself, but that's not the case here. If it is written that it should be expanded automatically, why doesn't it occur? Maybe I accidentaly set something that stops the application from increasing the buffer's size? I don't know and I can't find any answer to that, so I was just wondering if there's any way to actually make my application to expand that buffer on its own.
You need to set a text limit with the EM_LIMITTEXT message. Otherwise:
Before EM_LIMITTEXT is called, the default limit for the amount of
text a user can enter in an edit control is 32,767 characters.