I am trying to create one PDF document, with only one page, however
there is no restriction on page height.
First of all: I cannot pre-calculate page height exactly, because some
of lines I add exceed page width and wrap to next line.
So I have to find a solution in PDF writing phase.
I can add lines through a table, however table splits to pages, is
there a way to dynamically adjust page height so that table fits only
one page? Or any other suggestions?
At first I interpreted your question as "there is no restriction
on page height". That's wrong, depending on the PDF version there
are restrictions: For PDF 1.3 or earlier, the minimum page size is
72 x 72 units (1 x 1 in); the maximum is 3,240 x 3,240 units (45 x 45
in). Later versions have a minimum size of 3 x 3 units (approximately
0.04 x 0.04 in) and a maximum of 14,400 x 14,400 units (200 x 200 in).
In these later versions you can also change the user unit, resulting
in a page of 15,000,000 by 15,000,000 inches (that's huge!)
> First of all: I cannot pre-calculate page height exactly, because some
> of lines I add exceed page width and wrap to next line.
Yes, you can. Use ColumnText in simulation mode to find out
how much space the content needs horizontally.
> So I have to find a solution in PDF writing phase.
> I can add lines through a table, however table splits to pages, is
> there a way to dynamically adjust page height so that table fits only
> one page? Or any other suggestions?
First create a temporary document with a huge page height.
Then add a ColumnText object and use the ColumnText to find
out the height. Then create the real document with the
necessary height. Create a new ColumnText object with the
same content and add it for real.
br,
Bruno
PdfContentByte cb = writer.DirectContent;
ColumnText ct = new ColumnText(cb);
ct.SetSimpleColumn(new Phrase("xxxxxxxx"), 170, 0, 170, 100000, 15,
Element.ALIGN_CENTER);
ct.Go();
After that I hope ct.YLine will give me necessary information but it
doesn't. I think I am missing a point?
Yes, you have written code that is meaningless.
You are defining a rectangle with lower left coordinate (170, 0)
and upper right coordinate (170, 100000). At least you think you
are defining a rectangle. In reality the shape you define is more
like a long, thin line. iText can't add any content in a shape
with width equal to 0.
Please read chapter 7 of the book before starting to write code
in the wild without understanding what every method does.
br,
Bruno
:) OK. I'll get the book.
By the way, I have tried a palliative solution. I have created a very
long document (say 10000), and after writing everything, I got
document.GetVerticalPosition value, and created a new document with
page size of (document height [i.e.10000]- GetVerticalPosition value).
I have tried some documents and saw it worked fine, however, as I said
there will be many variations in page height, so I have to be sure. Do
you think this is a correct way?
On 7 Nisan, 18:05, Bruno Lowagie <br...@nospam.lowagie.com> wrote:
> ist wrote:
> > Hi, thanks for your reply and information.
> > I have tried adding columntext, however did not get the exact value. I
> > am adding multiple tables to a 170x100000 sized document, and at last,
> > adding a columntext with:
>
> > PdfContentByte cb = writer.DirectContent;
> > ColumnText ct = new ColumnText(cb);
> > ct.SetSimpleColumn(new Phrase("xxxxxxxx"), 170, 0, 170, 100000, 15,
> > Element.ALIGN_CENTER);
> > ct.Go();
>
> > After that I hope ct.YLine will give me necessary information but it
> > doesn't. I think I am missing a point?
>
>
You could create that document in memory and then pass the
bytes to PdfReader and change the MediaBox. Write the file
to the desired OutputStream (a file, a response outputstream)
using PdfStamper. That would probably be the fasted way to
achieve your goal. Now that I think of it: it would be even
faster than the solution I initially proposed.
br,
Bruno
On 8 Nisan, 11:39, "news.ugent.be" <bruno.lowa...@nospam.ugent.be>
wrote: