Skip to content

Commit b2da8d1

Browse files
committed
Add another use case to the sample app
1 parent 73d992d commit b2da8d1

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

samples/WpfApp1/MainWindow.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@
114114
<Button
115115
Click="GenerateMigraDoc_Click"
116116
Content="Generate PDF, RTF, DOCX (via MigraDoc)" />
117+
<Button
118+
Click="Generate_iTextSharpLGPL_Click"
119+
Content="Generate PDF, HTML, RTF, DOCX (via iTextSharp.LGPL)" />
117120
<Button
118121
Click="GenerateXlsx_Click"
119-
Content="Generate spreadsheet + PDF (via ClosedXML)" />
122+
Content="Generate XLSX + PDF (via ClosedXML)" />
120123
</UniformGrid>
121124
</Grid>
122125
</ScrollViewer>

samples/WpfApp1/MainWindow.xaml.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,49 @@ private void GenerateMigraDoc_Click(object sender, RoutedEventArgs e)
976976
}
977977
}
978978

979+
private void Generate_iTextSharpLGPL_Click(object sender, RoutedEventArgs e)
980+
{
981+
var pdfFilePath = "iTextSharpLGPL.pdf";
982+
var rtfFilePath = "iTextSharpLGPL.rtf";
983+
var htmlFilePath = "iTextSharpLGPL.html";
984+
var docxFilePath = "iTextSharpLGPL.docx";
985+
986+
// Generate PDF, HTML and RTF document using iTextSharp.LGPLv2.Core
987+
var document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4);
988+
var pdfFileStream = new FileStream(pdfFilePath, FileMode.Create);
989+
var rtfFileStream = new FileStream(rtfFilePath, FileMode.Create);
990+
var htmlFileStream = new FileStream(htmlFilePath, FileMode.Create);
991+
var pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(document, pdfFileStream);
992+
var rtfWriter = iTextSharp.text.rtf.RtfWriter2.GetInstance(document, rtfFileStream);
993+
var htmlWriter = iTextSharp.text.html.HtmlWriter.GetInstance(document, htmlFileStream);
994+
document.AddAuthor(System.Environment.UserName);
995+
document.Open();
996+
var fontTitle = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 16, iTextSharp.text.Font.BOLD);
997+
var parTitle = new iTextSharp.text.Paragraph("This is a new document", fontTitle);
998+
var phrase = new iTextSharp.text.Phrase();
999+
var boldChunk = new iTextSharp.text.Chunk("Bold, ", iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 12, iTextSharp.text.Font.BOLD));
1000+
var italicChunk = new iTextSharp.text.Chunk("italic, ", iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 12, iTextSharp.text.Font.ITALIC));
1001+
var underlineChunk = new iTextSharp.text.Chunk("underlined, ", iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDERLINE));
1002+
var strikeChunk = new iTextSharp.text.Chunk("strikethrough ", iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 12, iTextSharp.text.Font.STRIKETHRU));
1003+
var regularChunk = new iTextSharp.text.Chunk("text", iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 12, iTextSharp.text.Font.NORMAL));
1004+
phrase.Add(boldChunk);
1005+
phrase.Add(italicChunk);
1006+
phrase.Add(underlineChunk);
1007+
phrase.Add(strikeChunk);
1008+
phrase.Add(regularChunk);
1009+
var parBody = new iTextSharp.text.Paragraph(phrase);
1010+
document.Add(parTitle);
1011+
document.Add(parBody);
1012+
document.Dispose();
1013+
pdfFileStream.Dispose();
1014+
rtfFileStream.Dispose();
1015+
htmlFileStream.Dispose();
1016+
1017+
// Convert RTF to DOCX
1018+
var converter = new RtfToDocxConverter();
1019+
converter.Convert(rtfFilePath, docxFilePath);
1020+
}
1021+
9791022
private void GenerateXlsx_Click(object sender, RoutedEventArgs e)
9801023
{
9811024
var sfd = new SaveFileDialog()

samples/WpfApp1/WpfApp1.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageReference Include="XlsxToHtmlConverter" Version="1.2.21" />
1515
<PackageReference Include="PDFsharp-MigraDoc" Version="6.2.3" />
1616
<PackageReference Include="ClosedXML" Version="0.105.0" />
17+
<PackageReference Include="iTextSharp.LGPLv2.Core" Version="3.7.12" />
1718
</ItemGroup>
1819

1920
<ItemGroup>

0 commit comments

Comments
 (0)