How to add bookmark using MigraDoc? - c#

I want to add Bookmark in my PDF using MigraDoc.
For example: two images on a single page.
1. Images1
2. Images2**
and the same name bookmark will generate.
If I click on image1 bookmark that image will be shown to me. Remember both images are on single page.

MigraDoc creates bookmarks automatically for headings.
To create bookmarks without visible text on the page, you can create headings with a font size of e.g. 0.0001 and white colour.
There is one drawback: up to PDFsharp 1.50 beta 1, these bookmarks jump to the correct page, but not the correct area on the page. So with two images on one page, the bookmarks will not work as intended by the OP.

Related

Continuous Labelling using iTextSharp PDF

I have working iTextsharp code for printing labels. Now the problem is, I have a requirement to print the labels in Continuous paper which i am not able to select in iTextsharp configuration (iTextSharp.text.PageSize.A4). Please advice how can i select the page size according to my current scenario.
Thanks
Your problem is related to PDF as a document format. In PDF, the content is distributed over different pages. You can define the size of such a page yourself. You mention iTextSharp.text.PageSize.A4, but you can define the page size as a Rectangle object yourself. See iTextsharp landscape document
If you want a long, narrow page, you could define the page size like this:
Document Doc = new Document(new Rectangle(595f, 14400f));
There are some implementation limits though. The maximum height or width of a page is 14,400 user units. See the blog post Help, I only see blank pages in my PDF!
However, I am pretty sure that you don't want to create a long narrow page. If you want to print labels on "continuous paper", you want to create a PDF document in which every page has the size of exactly one label. Your PDF will have as many pages as there are labels.
Suppose that the size of one label is 5 by 2 inch (width: 12.7cm; height: 5.08cm), then you should create a document like this:
Document Doc = new Document(new Rectangle(360, 144));
And you should make sure that all the content of a label fits on a single page. Your label printer should know that each page in the PDF should be printed on a separate label.
(Thank you #amedeeVanGasse for correcting my initial answer.)

MigraDoc : big table divided into 2 parts in one page

I am working on creating a report with MigraDoc that would be able to have table with 2 columns divided in the same page. It's possible with any settings of Table object?
Draft image
MigraDoc cannot do that on its own.
You can get a PDF with such a table if you create a MigraDoc document with just 50% page width (and the height of your page body) and then use PDFsharp to draw two pages from the MigraDoc document onto one page of the final PDF.
This sample draws 9 large pages as thumbnails on one page and cane be used to get started:
http://pdfsharp.net/wiki/MixMigraDocAndPdfSharp-sample.ashx

Alignment of images in MigraDoc

I want to create a PDF file that should contain a table and, under this table, three images; the images should have an horizontal layout (they should be on the same line).
How can I align the three images in MigraDoc?
If I add the images in this way
document.LastSection.AddImage("path1");
document.LastSection.AddImage("path2");
document.LastSection.AddImage("path2");
I obtain three images with a vertical layout under the table.
If I use
document.LastSection.LastParagraph.AddImage("...");
instead of
document.LastSection.AddImage("...")
I solve the problem but I introduce a new problem.
The table that I've added using
var table1 = new Table();
.....
document.LastSection.Add(table1);
appears under the three images.
What can I do to obtain the table and under the table the three images with horizontal layout?
How about var para=document.LastSection.AddParagraph(); and then calling para.AddImage(...); to add the three images to one paragraph?
MigraDoc is dynamic - and document.LastSection.LastParagraph obviously returns the last paragraph before the table. To cure this, just add a paragraph after the table and add the images to this paragraph.

Get text width from font migradoc / pdsharp for table columns

I want to create a table in a PDF document which would have variable width of columns depending on the width of its contents.
I am using PDFSharp, MigraDoc
Maybe getting the paragraph width from the individual cells will help. Is there a way to get text width depending on the font / styles?
Any clues?
Thanks.
Using PDFsharp functions, you can get the width of any text.
MigraDoc is not limited to PDF, it creates documents for PDF, RTF, print. No chance to determine the exact width (unless you restrict yourself to PDF and use PDFsharp to get the width).
MigraDoc will break text in columns to the next line when needed.
Create a dummy PdfDocument, create a page, get an XGraphics object (gfx) for that page, then use gfx.MeasureString() to find the width.

iTextSharp - Copying elements from one PDF to another

I want to copy certain elements from one PDF to another using iTextSharp.
I want to read one PDF, read text elements from that and correct them and create a new PDF using the updated text elements and all the images etc. from the first PDF.
Please help me how this can be achieved.
This task is very complex. I wrote a program to do this for a large greeting card maker.
First you have to locate the text and calculate the glyph bounding boxes. Next you have to modify the contents stream to remove the text. The text may be broken into many pieces depending on the PDF creator. You have to remove those operators from the contents stream and adjust the CTM because some operators use relative positioning. Finally, you have to insert the replacement text, matching the original text's style (font, size, color, orientation, etc.)
As for copying elements from one PDF to another, most of the steps above are required plus you have to copy resources, eg. fonts, colorspaces, patterns, etc, to the new PDF.

Categories

Resources