Exemple #1
0
        private void myWriteButton_Click(object sender, RoutedEventArgs e)
        {
            String fileName = SaveFileDialog();

            if (String.IsNullOrWhiteSpace(fileName))
            {
                return;
            }


            using (WaitDlg dlg = new WaitDlg())
            {
                Document document = new Document(PageSize.LETTER);

                //document.SetMargins(0, 0, 10, 0);
                // WORKING! document.SetMargins(document.LeftMargin, document.RightMargin, 25, 25);
                document.SetMargins(document.LeftMargin, document.RightMargin, 15, 10);


                PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));


                // step 3: we open the document
                document.Open();



                iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
                PdfPTable table = new pdf.PdfPTable(3);
                table.SpacingBefore = 0;
                table.SpacingAfter  = 10;
                table.TotalWidth    = 175.5f * 3.0f + 30f;
                table.LockedWidth   = true;


                List <Card> smallCards = GetSelectedCards(true, false);
                List <Card> bigCards   = GetSelectedCards(false, true);


                WriteCards(bigCards, table);
                WriteCards(smallCards, table);


                table.AddCell(new PdfPCell());
                table.AddCell(new PdfPCell());
                table.AddCell(new PdfPCell());

                document.Add(table);

                document.Close();
            }

            MessageBox.Show("PDF Generation Complete!");
        }
        private void myWriteButton_Click(object sender, RoutedEventArgs e)
        {
            String fileName = SaveFileDialog();

            if (String.IsNullOrWhiteSpace(fileName))
            {
                return;
            }


            System.Drawing.KnownColor backColorToUse = System.Drawing.KnownColor.White;

            int iCardNum = StartNumberingAt;

            foreach (var item in mySelectedVcards.Items)
            {
                (item as Card).CardNumber = iCardNum;

                if (BackgroundMatchesFirstCard)
                {
                    backColorToUse = (item as Card).BorderColor;
                }

                iCardNum++;
            }

            iTextSharp.text.BaseColor backColorToDraw = new iTextSharp.text.BaseColor(WhiteBorderConverter.GetCompatibleColor(backColorToUse)); //new iTextSharp.text.BaseColor(System.Drawing.Color.FromKnownColor(backColorToUse));
            PageEventHandler.PrintingBlackBorder = (backColorToUse == KnownColor.Black);
            PageEventHandler.BackColor           = backColorToDraw;
            PageEventHandler.UsingCubeFeatures   = (myCubeFeaturesCheckbox.IsChecked == true);

            using (WaitDlg dlg = new WaitDlg())
            {
                Document sizeDoc = new Document(PageSize.LETTER);
                iTextSharp.text.Rectangle backgroundRect = new iTextSharp.text.Rectangle(sizeDoc.PageSize);

                Document document;

                if (BackgroundMatchesFirstCard)
                {
                    backgroundRect.BackgroundColor = backColorToDraw;
                    document = new Document(backgroundRect);
                }
                else
                {
                    document = new Document(PageSize.LETTER);
                }


                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
                myEvents         = new PageEventHandler();
                writer.PageEvent = myEvents;



                //document.SetMargins(0, 0, 10, 0);
                // WORKING! document.SetMargins(document.LeftMargin, document.RightMargin, 25, 25);

                //document.SetMargins(0.0f, 0.0f, 0.0f, 0.0f);
                document.SetMargins(document.LeftMargin, document.RightMargin, 15, 10);

                // step 3: we open the document
                document.Open();

                //iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
                PdfPTable table = new pdf.PdfPTable(3);
                table.SpacingBefore = 0;
                table.SpacingAfter  = 10;
                //table.TotalWidth = 175.5f * 3.0f + 30f;
                table.TotalWidth        = 179.0f * 3.0f + 20f;
                table.LockedWidth       = true;
                table.AbsoluteWidths[0] = 179.0f + (float)HorizontalSpacing;
                table.AbsoluteWidths[1] = 179.0f + (float)HorizontalSpacing;
                table.AbsoluteWidths[2] = 179.0f + (float)HorizontalSpacing;


                List <Card> smallCards = GetSelectedCards(true, false);
                List <Card> bigCards   = GetSelectedCards(false, true);


                WriteCards(bigCards, table, document, backColorToUse);
                WriteCards(smallCards, table, document, backColorToUse);

                PdfPCell emptyCell = new PdfPCell();
                emptyCell.BackgroundColor = backColorToDraw;
                emptyCell.BorderColor     = backColorToDraw;

                table.AddCell(emptyCell);
                table.AddCell(emptyCell);
                table.AddCell(emptyCell);


                foreach (var row in table.Rows)
                {
                    //pdf.PdfPCell cell = row.GetCells()[0];
                    //float top = row.GetCells()[0].Bottom;

                    //iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(-30,top, 50, top+3);
                    //document.Add(rect);
                }

                document.Add(table);
                document.Close();
            }

            MessageBox.Show("PDF Generation Complete!");
        }