Doxygen Wizard / MiKTeX C# Code Documentation Spacing & Table of Contents Issues - c#

I am working on creating a PDF document of C# code. I am using the Doxygen GUI frontend and using the wizard to create LaTex files. Then, I take the generated refman.tex file and put it into TeXworks (part of MiKTeX) and generate the single pdf output. I can edit the .tex file to get rid of completely blank pages, change the page numbers, and more, but I am having two formatting issues I can't figure out.
The first problem is that each section is a "chapter" and the "chapter" headings are really far down the page (like probably ~40% down the page). I can't seem to find the setting in the .tex file that changes this. (See the linked screenshot below.)
The second problem has to do with the table of contents. It lists all the function names and their inputs. I don't want the inputs listed there. How do I change that?? (See the second screenshot below.)
Here is a small sample of the code...
%===== C O N T E N T S =====
\begin{document}
% Titlepage & ToC
\hypersetup{pageanchor=false,
bookmarksnumbered=true,
pdfencoding=unicode
}
\begin{titlepage}
\vspace*{7cm}
\begin{center}%
{\Large A\+PI Test \#1 \\[1ex]\large beta v1 }\\
\vspace*{1cm}
{\large DOXYGEN GENERATED}\\
\end{center}
\end{titlepage}
\let\cleardoublepage\clearpage
\clearemptydoublepage
\tableofcontents
\clearemptydoublepage
\pagenumbering{arabic}
\hypersetup{pageanchor=true}
%--- Begin generated contents ---
\chapter{Namespace Index}
\input{namespaces}
\chapter{Hierarchical Index}
\input{hierarchy}
\chapter{Class Index}
\input{annotated}
\chapter{File Index}
\input{files}
\chapter{Namespace Documentation}

I had the exact same problem! Using the package titlesec helped a lot. As titlesec accepts vertical values in the format field for the \titleformat command, so I used \vspace{-0.5in} to force the chapters up. I added the following code to my header.tex. JKust mind that I added this before the \usepackage[titles]{tocloft} line.
\usepackage{titlesec,titletoc}
% Headings 1
\titleformat{\chapter} % command
[display] % shape
{\vspace{-0.5in}\huge\bfseries\filcenter} % format
{\LARGE\thechapter} % label
{0.4ex} % Spacing between label and title
{} % before code

Related

How to add blank pages in pdf based on odd and even pages

I want to create pdf file accordingly lastname alphabet order and then this PDF document will be used for double-sided printing.
When creating a pdf file, there should be page breaks on the first letter of last name and then a blank sheet before starting the next letter.
If 'A' letter finish printing on an even page, "B" letter can begin printing on the next odd page.
If 'A' letter finish printing on an odd page, the next even page should be blank. 'B" letter should begin on the next odd page.
Another way to say this is that every letter should begin printing on the next available odd page.
I have tried telerik report to generate pdf file but in telerik report I did not able to track page numbers when generate pdf file.
You can produce each file separately, then run cpdf -pad-multiple 2 in.pdf -o out.pdf on each, to add a blank page if needed. Then you can merge them all with cpdf 1.pdf 2.pdf 3.pdf ... -o final.pdf.
You could call the PDF tool kit pdftk as external process from your program:
With pdftk.exe yourfile.pdf dump_data, you can find the number of contained pages.
Example output:
c:\TEXTS>pdftk.exe example.pdf dump_data
InfoKey: Creator
InfoValue:
InfoKey: Title
InfoValue: Citations, mots célèbres 2
InfoKey: Producer
InfoValue: wkhtmltopdf
InfoKey: CreationDate
InfoValue: D:20130904112136+02'00'
NumberOfPages: 5
If NumberOfPages is odd, use a command like to following to append an empty page:
pdftk.exe A=yourfile.pdf B=empty_page.pdf cat A B output yourfile_even.pdf
Once you have evened all files, you can concatenate them:
pdftk.exe A=a.pdf B=b.pdf C=c.pdf cat A B C output result.pdf
A more recent alternative to pdftk is the open source tool qpdf.
Generally using qpdf or cpdf executables the extra page can be added as required, https://stackoverflow.com/a/73575464/10802527 however it seems from the tone of this question you wish to do that "inline" during PDF building, In that case it is best NOT to build A.pdf B.pdf and add single blanks before merge it is better to build the full A-Z.pdf then inject the blanks as needed.
This requires you build a personalized solution where you extract page numbers so lets say without your example
Chapter A = page 1
Chapter B = page 4
Chapter C = page 6
Chapter D = page 9
so you know you need inject blank before page 4 to move 4 to 5 and that will move 6 to 7 so now you don't need to shift page 6 however page 9 is now page 10 so WILL now need inject blank before page 10. So you need to keep track of the previous up lifts.
You can write that as a simple subroutine to call one of the libraries that reports the page content as number and ideally also includes a blank page insertion, method.
in pseudo code you need 2 trackers
if last inject was even next is odd and vice versa (flip flop)
page inject is current + previous blanks (incremental value)
NOTE the later answer by JohnWhitington from cpdf shows that this will be easiest in above case by use
cpdf -pad-before in.pdf 4,9 -o output.pdf
cpdf will do the 2nd shifting incremental part so 4 becomes 5 (& 6 becomes 7) and also old 9 will then move to 11 but you will still need to determine the flip flop state (odd or even) of which pages need a blank before them.
roughly you need to
set flag=EVEN
loop NEXT PAGE
if page is last page then exit from loop
is page a section heading ?
then if page odd and flag is ODD save page num and set flag as EVEN and go NEXT PAGE
if page odd and flag is EVEN go next page
if page even and flag is ODD go next page
if page even and flag is EVEN save page num and set flag as ODD and go NEXT PAGE
else page not section heading go NEXT PAGE
1 keeps flag as EVEN
2 & 3 is not section
4 is section, is even, flag is EVEN, save page num, set flag ODD
5 is not section
6 is section, is even, flag is ODD (skip save num)
7 & 8 is not section
9 is section, is odd, flag is ODD, save page num, set flag EVEN
... etc.

How to get line number on IClassifier.GetClassificationSpans?

I am developing a Visual Studio extension in C# and I want to add classifications on a file based on an analysis of this file that is already provided. I have got analysis results with a set of locations (file, line, column) for each defect.
Based on MS doc, I have seen that we should implement the IClassifier.GetClassificationSpans method. I can see that we are given a set of SnapshotSpan. It looks like these spans are mostly complete lines from the open file: the visible lines currently shown and the line currently being edited.
However, as said previouly, I already have a set of defects with their location. I would like to get the current span line number so I can check I have got a defect registered on that line. I have browsed the whole SnapshotSpan structure with the debugger and I couldn't find anything looking the line number.
How to get current SnapshotSpan line number?
What is the logic of the framework when I already have results given with their location and I want to place glyphs/classifications/tooltips/outlining regions/etc in the editor based on these locations?
I finally found out that I can get the line number the following way:
var lineNumber= span.Snapshot.GetLineNumberFromPosition(span.Start.Position) + 1;
+1 because internal values start at 0 while visible lines in the editor start at 1 (or because my file analysis gives me lines starting at 1).

How to find the location of the last item added to a PDF document

Simarly to this question I want to find the location of the last item in a PDF document and add content at that place, more specifically I would like to add an electronic signature at a position where one would normally put a regular handwritten signature on letters.
In the question above the user is making the PDF file but I am importing an existing PDF file that can have any structure as such. Therefore, as far as I can see, I can not use the same method as I do not know if the last object made was a paragraph or some other object.
I found the following function and property on the PdfWriter class that bode well but can not find any documentation that explains the output I get when I run the programme:
PdfWriter w = _document.GetWriter();
long currentPos = w.GetCurrentPos();
long pos = w.Position;
When I run this the output I get is something like the number 84178. What unit is that? Can I use this number to calculate how much vertical space there is left on the page and if it is too small then add a page and have the signature on the next page?

Paste data from clipboard to excel in right format

In performance analyzer I copy data from table in clipboard.
And then paste it in excel file.
The result is:
But when I paste it in text editor, I simple looks like:
Function Name Inclusive Samples Exclusive Samples Inclusive Samples
% Exclusive Samples %
[clr.dll] 26 26 39.39 39.39
Bee.Client.Common.BeeRight.CheckRightsForBeeUser() 10 0 15.15 0.00
Bee.Client.Common.BeeRight.get_Invoke() 6 0 9.09 0.00
Bee.Client.Common.BeeRight.Method(string,string) 13 0 19.70 0.00
Bee.Client.Common.Custom.FmCustom..ctor() 9 0 13.64 0.00
So can you tell me, how can I archive this effect?
Thanks!
Update
I'll try to explain.
I have DataGridView in my winform application. I wrote some function, which copy data from table into clipboard (the result looks like the text in my example). If I paste this text from clipboard to excel, the result will be excel file with data from clipboard, but there will be no formatting at all and this excel will be hard to read.
I wonder, how they prepare data from table (pic 1) such a way, that when I paste it to excel, it has formatting (pic 2), and when I paste it in text editor, we saw raw text..
The cause, why the direct work between your datagrid and Excel is good, is the implementation of the DataGridView component and its reaction to Copy operation, and the behavior of the application, you want to paste the content into. It can use some special codes, which are ignored by Notepad.
EDIT
So, now I understand your interest pretty well. I don't know how it works in C#, but in Java it looks so.
Every time you have any information in the clipboard there are a lot of variants, how other applications can use this content.
Suppose I want to get the content from the clipboard. I do it so:
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
but now I should determine how the information should look for my application, and here your question begins.
If I have a picture in the clipboard, I have only 1 possible representation of it:
[mimetype=image/x-java-image;representationclass=java.awt.Image]
If I have some text from Notepad, there are already 27 variants:
[mimetype=application/x-java-text-encoding;representationclass=[B]
[mimetype=application/x-java-serialized-object;representationclass=java.lang.String]
[mimetype=text/plain;representationclass=java.io.Reader]
[mimetype=text/plain;representationclass=java.lang.String]
[mimetype=text/plain;representationclass=java.nio.CharBuffer]
and so on...
If I have some cells from an Excel sheet, there are 56 variants:
[mimetype=application/x-java-text-encoding;representationclass=[B]
[mimetype=text/html;representationclass=java.io.Reader]
[mimetype=text/html;representationclass=java.lang.String]
[mimetype=text/html;representationclass=java.nio.CharBuffer]
[mimetype=text/html;representationclass=[C]
and so on...
there is even an Image-variant for Excel-cells!
[mimetype=image/x-java-image;representationclass=java.awt.Image]
That is why it is possible to copy some cells from Excel and paste them into Paint as bitmap! It is not possible for Notepad of course, because its developers did not want to work with this presentation.
Now we can see, the clipboard is not so primitive how it can seem to be. Each time an application can analyze the content and take the best variant of it.
Now you can try to find some infos for C# development. I'm sure, you'll get it!

Find the number of pages in a Word document Section using Interop

I'm trying to find the number of pages in a Section of a Word document using Interop in c#.
The main goal is really to find out if a header is visible or not. (E.g. a document is only 1 page, the DifferentFirstpageHeaderFooter is enabled, so the wdHeaderFooterPrimary exists but is technically not shown (because there's only 1 page and not 2 or more).) So if you can find a different way to figure out how to do this, I'm fine with that too.
Currently, WdInformation.wdActiveEndPageNumber works if there is only 1 section in the document, but if there is 2, and I'm doing the processing of the second section, wdActiveEndPageNumber gives me the total number of pages including section 1.
var section = headerFooter.Parent as Section;
int numOfPages = section.Range.Information[WdInformation.wdActiveEndPageNumber];
I don't have the C# for this, but using VBA syntax what you need for "section n" is
a. if n = 1 then you look at
theDocument.sections[1].Range.Information[WdInformation.wdActiveEndPageNumber]
b. if n > 1 then you establish that section n exists, then look at
theDocument.sections[n].Range.Information[WdInformation.wdActiveEndPageNumber]-
theDocument.sections[n-1].Range.Information[WdInformation.wdActiveEndPageNumber]
and notice that case (b) can return 0 if you have a continuous section break on the last page of section n. I don't know what that would mean in terms of the headers that you would have, but I'd hope it would mean you just had the first page header.

Categories