C# PDFsharp end of page detection - overflow

Is it possible to detect the end of page in creating PDF file with PDFsharp library? How? Or overflowing text on page? I am generating PDF file with list of users and if the list is too long, I need to add new page and continue on it. I don't want to write ugly code, I want it to be as automatic as possible.
I am aware of MigraDoc library, but I already have a lot of code written in PDFsharp, so if it's not necessary to use MigraDoc (which seems to be better), I would rather stay with PDFsharp. Thanks.

When using PDFsharp, you are responsible to detect the end of page and create a new page for the continuation.
We always say that PDFsharp is low level: no automatic page breaks, but anything can be drawn anywhere.
Still you can write clean code with PDFsharp that handles page breaks properly.
You always have a current page, a current gfx, and a current y position on the page. So when you have to start a new page, re-initialize those variables.

Related

How can I get a "break" after an image

Using iTextSharp (4.1.6) in a Xamarin.Forms app.
I have lines of data with CRLF at the end of each. I put these into paragraphs, which I add to the doc. At then end of many, I add to the doc one or more images (photos). Works great.
Now, I'd like to have a page break after the last image, so I get a fresh start.
But iText seems to be flowing the text around the image some, and sometimes I don't get that page break, at last not where I want it. The next paragraph follows immediately after the image.
I tried adding a small paragraph after the image, but this did not solve. I did find that adding a SECTION seems to cause a good break, but puts some text in that I don't want or need.
I don't seem to find anything like API documentation for this, I've been just working from examples.
It seems like this would be really easy. What am I doing wrong?
iText seems to be flowing the text around the image some
Indeed, if you add an image to your document which does not fit on the current page anymore (but there still is some place for text on that page), iText does not immediately start a new page but keeps the image in memory and waits for your next content additions. If you then add text, that text first fills the current page, and only if even text does not fit anymore (or if you add another image), a new page is started and the waiting image is added.
You can switch this off using for your PdfWriter writer using
writer.StrictImageSequence = true;

What is the best way to convert PDF pairs into single pages?

I need to take an existing PDF (created with Prawn), and combine pairs after page 1 (the cover) into single pages. I would also like to add a vertical line in the center of the joined pages. The pages are to be printed in books, and the goal is to make single PDF pages that are similar to the side by side view in Acrobat. I know I can convert them to images, do what I need to with ImageMagick, then put them back into a PDF format, but I am trying to minimize the number of conversions so I can save as much quality as possible.
I also realize I can do this from the start with Prawn, but I am trying to avoid that as it would require a very large change to our application.
It is possible to do this with Ghostscript and the pdfwrite device, but its by no means simple. You need to write some PostScript to do the job.
You would need to add BeginPage and EndPage procedures, the BeginPage would need to check the current page number (and you would need to track this yourself). If its page 1, process normally. If its an even page, throw away the current PageSize and replace it with one which covers a pair of pages. Process the even page. Do not transmit the content.
If the page is odd (and not 1) then translate the origin so that its offset to the right by the width of the page. Process the odd page. use moveto, lineto and stroke to draw the required line between the two pages. Transmit the page.
This assumes that all the pages are the same size and orientation, or least that the sizes of each page are known in advance. It would be possible to retrieve those programmatically as well, but more complex.
Its definitely non-trivial, but if you rummage through my answers in the PostScript tags and look for anything with the word 'imposition' you'll probably find program outlines to do the job.
I did a quick look and here's an answer I wrote some time back. It uses a different approach to that outlined above, it copies some of the guts of the PDF interpreter and repurposes them. It does a chunk of what you want though.

Display an image over the screen

I have a map that is 40x50 that shows when the visitor comes to the website, i would like the visitor to click the map which puts in topmost actual size 400x500 and everything beneath is blacked out, when they click off the pic it will simply vanish.
I have seem it happen in many galleries but can't seem to find one i can recode and don't even know what the actual process of doing this is called.
I believe the word you're looking for is lightbox.
See this: http://lokeshdhakar.com/projects/lightbox2/
By the way, tags are for tagging what languages you are using. Appropriate tags for this post would probably be html and javascript. The image tag is alright, but without context, it's difficult to figure out how your are trying to implement it.

PDF generation under ruby - block should not cut by page separator

My PDF consists of a number of blocks (actually, a list of quotations), they go one after another till the end of the document. If the text of a quotation
does not fit on the page, the whole quotation should start from the top of the next page, instead of being torn apart. How can I implement that on any library under ruby?
Try PrinceXML - this is a standalone executable that generates PDF out of HTML or XML. It supports a lot of special CSS properties that will even help you to control page breaks. Refer to http://www.princexml.com/doc/6.0/page-breaks/
This application is available for windows and linux. I was using it for generation of a pretty complicated PDF documents with headers and footers on every page except first one. And since you don't need to output a PDF with precise positioning of elements, it might be a perfect solution for you.
I haven't tried it, but in Prawn I would try using either the Document#text_box method or looking up the table methods and putting your text in cells with invisible borders. The documentation's unclear on how page break functionality fits in with the bounding box models, but it's worth a shot.
HTMLDoc which converts HTML to PDF has a page break facility.

Printing Reports and invoices with Ruby?

I just learn Ruby, and I wonder how to generate Reports and Invoices (with Logo, adressfield, footer, variable number of invoice-items (sometimes resulting in more than one page), carry over of the amount to pay from one page to the next, free-floating 2-column text (left-and-right-justified) below the resulting cash-informations).
Currently I get a canvas to print and draw on from the OperatingSystem (matching the printer specifications) and use some draw-, move-, line-, text- and formfeed-API-Functions and do some heavy calculations for textblock-moving (a bit TeX-like).
How will this be done in Ruby?
Building an .odt and throw it to OpenOffice or a .tex and throw it to LaTeX?
Or are there any free Libraries, thet do all this kind of things for me, so I only have to feed the relevant parts, and let Ruby do the Text-Formatting thing?
EDIT:
To be more specific: I want to put a corporation logo on the first page (DIN-A4-format, but may also be letter) on a specific position, also the footer on every page and the adress-box on the first page. all the rest should be free floating text blocks with left-right-justification, bold words in the middle of texts.
something like
pdf.column.blocktext("Hello Mr. P\nwe have [b]good news[/b] for you. bla bla bla and so on. Please keep this text together (no page break)...");
pdf.column.floatingblock("This is another block, that should be printed, and can be broken over more than one column...");
which should render the text in the corporate font on the paper, justified, and wrapping neatly to the next column/page if it reaches the bottom of the page.
Thinking about it, this is exactly, what LaTeX is for.
I suggest you consider PDF generation. In Rails, it's pretty simple with the Prawn library.
There is also a fresh new Railcast about that.
Official web site.
You could also check out HtmlDoc for generating PDFs, it just takes in HTML and generates a PDF from it. This approach is nice because it lets you very easily reuse a partial for an on-screen and hard copy invoice.
http://blog.adsdevshop.com/2007/11/20/easy-pdf-generation-with-ruby-rails-and-htmldoc/
The Ruport library (Ruby Reports) makes it pretty easy to spit report tables out in multiple formats, including PDF. There's also a ActiveRecord hook acts_as_reportable that gives your models a reporting interface.

Resources