I am using iTextSharp to generate PDF document. Currently, the HTML contents are converted successfully into PDF document. The default page orientation is Portrait.
However, my requirement is is create PDF document with some page in Portrait and some in Landscape.
The following line generates PDF document with Portrait orientation
document.SetPageSize(PageSize.A4);
And, if i change this line to than it creates whole document in Landscape.
document.SetPageSize(PageSize.A4.Rotate());
How i can generate PDF with mixed portrait and landscape orientation?
Kindly advise.
You already have everything you need. The method you are using is the correct one. You can use it more than once, just be aware of the fact that you need to change the page size before a new page is created:
Document document = new Document();
PdfWriter.GetInstance(document, new System.IO.FileStream(filename, System.IO.FileMode.Create));
document.SetPageSize(PageSize.A4);
document.Open();
document.Add(new Paragraph("Hi in portrait"));
document.SetPageSize(PageSize.A4.Rotate());
document.NewPage();
document.Add(new Paragraph("Hi in landscape"));
document.Close();
As you can see, we set the page size to A4 in portrait before we Open() the document. We add some content to this page, and then we decided to set the page size for the next page to A4 in landscape. This will only take effect after a new page starts. This can be triggered automatically by iText when you add content that doesn't fit the current page. Or you can trigger this yourself by invoking NewPage(). In the example, the second paragraph is added to a page in landscape.
See also iText create document with unequal page sizes for a Java example.
Related
Currently I'm working on a PDF export. I want to add an bottom margin to my pdf, but this results in a empty pdf page. The first PDF page has enough room for all of the content but it still produces a blank page. When I remove the bottom margin the blank page disappears but it can happen when I have more than 2 pdf pages it still produces an extra empty PDF between the 2 pages. I don't know why this is happening.
Anybody has any idea? :)
Thanks,
Mark
I use evaluation version of evopdf.
Actually, evopdf truncate contains in the render pdf document.
I think that evopdf only render the part of document visible in window browser.
Is your HTML content inside a scrolling area? In this case you have to either create a version of the HTML which displays the entire content inside the scrolling area or set a large custom viewer height in HtmToPdfConverter.HtmlViewerHeight .
For example:
// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
// Set HTML viewer height in pixels to convert the top part of a HTML page
// Leave it not set to convert the entire HTML
htmlToPdfConverter.HtmlViewerHeight = 2000;
You can also find the working example with C# source code at http://www.evopdf.com/demo/ where you can test online your HTML page.
I have a HTML page which contains a table which has many columns and they do not fit in screen, so one viewing the the table has to scroll left to right to see full content as width of the page is larger than screen.
When i'm converting this HTML page to PDF the content which are not visible without scrolling are not rendered in PDF document. Is there any way we can get the HTML page width and increase the PDF page width?
I am using itext to generate pdf files with images and with some description for that image.
I want to print one image and description of that image in one page.
For next image want to print in next page.By using itext how i can move to next page ?
Lot of way to do that. Simply what i understand from your question how to generate a new page in a Pdf Document. Algo will be like this
for each image{
/*manipulation logic for image and text goes here */
document.newPage();
}
Do a checking for last time loop is iterated otherwise it will create additional blank page.
I have PDF template with a large text-box. Based on the size of the content, the textbox comes-up with a vertical scroll bar. But issue comes up when I flatten the PDF using PDFStamper, the text box does not have the scroll bar and user see only half of the content.
Is there way to allow scroll bar in the text box after flatten the pdf?
Please note that while designing the textbox in the template we have enabled scroll bar option.
No. Flattening a PDF effectively disables interactivity. What your printer kicks out is what you see on screen. One work around is to drop the font size on the field for long items. Another option is to make the PDF read-only instead flattening it. See this post from the office iText mailing list for more.