本文整理汇总了C#中CompareTool类的典型用法代码示例。如果您正苦于以下问题:C# CompareTool类的具体用法?C# CompareTool怎么用?C# CompareTool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompareTool类属于命名空间,在下文中一共展示了CompareTool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextLeadingTest
public void TextLeadingTest() {
String file = "phrases.pdf";
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, File.Create(OUTPUT_FOLDER + file));
document.Open();
Phrase p1 = new Phrase("first, leading of 150");
p1.Leading = 150;
document.Add(p1);
document.Add(Chunk.NEWLINE);
Phrase p2 = new Phrase("second, leading of 500");
p2.Leading = 500;
document.Add(p2);
document.Add(Chunk.NEWLINE);
Phrase p3 = new Phrase();
p3.Add(new Chunk("third, leading of 20"));
p3.Leading = 20;
document.Add(p3);
document.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file, OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例2: Test
public void Test() {
String file = "tagged_pdf_page_events.pdf";
Document document = new Document();
PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.Create));
pdfWriter.SetTagged();
pdfWriter.PageEvent = new TaggedPdfPageEventsTest();
document.Open();
document.Add(new Paragraph("Hello"));
document.NewPage();
document.Add(new Paragraph("World"));
document.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file,
OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例3: TestFlattening
public virtual void TestFlattening()
{
const string INPUT_FOLDER = RESOURCES_FOLDER + "input/";
const string CMP_FOLDER = RESOURCES_FOLDER + "cmp/";
if (File.Exists(INPUT_FOLDER))
Assert.Fail("Input folder can't be found (" + INPUT_FOLDER + ")");
Directory.CreateDirectory(OUTPUT_FOLDER);
String[] files = Directory.GetFiles(INPUT_FOLDER, "*.pdf");
foreach (String file in files)
{
// flatten fields
PdfReader reader = new PdfReader(file);
PdfStamper stamper = new PdfStamper(reader, new FileStream(OUTPUT_FOLDER + Path.GetFileName(file), FileMode.Create));
stamper.FormFlattening = true;
stamper.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.Compare(OUTPUT_FOLDER + Path.GetFileName(file), CMP_FOLDER + Path.GetFileName(file), OUTPUT_FOLDER, "diff");
if (errorMessage != null)
{
Assert.Fail(errorMessage);
}
}
}
示例4: Test
public void Test() {
String file = "tagged_pdf_end_page.pdf";
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.Create));
writer.PdfVersion = PdfWriter.VERSION_1_7;
writer.SetTagged();
writer.CreateXmpMetadata();
document.SetMargins(10, 10, 60, 10);
PdfPTable headerTable = new PdfPTable(1);
PdfPageHeader header = new CustomPdfPageHeader(writer, 10, headerTable);
writer.PageEvent = header;
document.Open();
PdfPTable table = CreateContent();
document.Add(table);
document.Close();
// compare
CompareTool compareTool = new CompareTool().SetFloatRelativeError(1e-4f);
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file,
OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例5: PageEventTest01
public void PageEventTest01() {
String fileName = "pageEventTest01.pdf";
MemoryStream baos = new MemoryStream();
Document doc = new Document(PageSize.LETTER, 144, 144, 144, 144);
PdfWriter writer = PdfWriter.GetInstance(doc, baos);
writer.PageEvent = new MyEventHandler();
writer.SetTagged();
doc.Open();
Chunk c = new Chunk("This is page 1");
doc.Add(c);
doc.Close();
File.WriteAllBytes(OUTPUT_FOLDER + fileName, baos.ToArray());
baos.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + fileName, TEST_RESOURCES_PATH + fileName, OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例6: TextWithSymbolEncoding
public virtual void TextWithSymbolEncoding() {
BaseFont f = BaseFont.CreateFont(BaseFont.SYMBOL, BaseFont.SYMBOL, false);
FileStream fs = new FileStream("fonts/SymbolFontTest/textWithSymbolEncoding.pdf", FileMode.Create);
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
Paragraph p;
writer.CompressionLevel = 0;
doc.Open();
String origText = "ΑΒΓΗ€\u2022\u2663\u22c5";
p = new Paragraph(new Chunk(origText, new Font(f, 16)));
doc.Add(p);
doc.Close();
PdfReader reader = new PdfReader("fonts/SymbolFontTest/textWithSymbolEncoding.pdf");
String text = PdfTextExtractor.GetTextFromPage(reader, 1, new SimpleTextExtractionStrategy());
reader.Close();
Assert.AreEqual(origText, text);
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent("fonts/SymbolFontTest/textWithSymbolEncoding.pdf", TEST_RESOURCES_PATH + "cmp_textWithSymbolEncoding.pdf", "fonts/SymbolFontTest/", "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例7: VerticalPositionTest0
public void VerticalPositionTest0() {
String file = "vertical_position.pdf";
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, File.Create(OUTPUT_FOLDER + file));
document.Open();
writer.PageEvent = new CustomPageEvent();
PdfPTable table = new PdfPTable(2);
for (int i = 0; i < 100; i++) {
table.AddCell("Hello " + i);
table.AddCell("World " + i);
}
document.Add(table);
document.NewPage();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; i++) {
sb.Append("some more text ");
}
document.Add(new Paragraph(sb.ToString()));
document.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file,
OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例8: Rowspan_Test
public virtual void Rowspan_Test() {
String file = "rowspantest.pdf";
string fileE = CMP_FOLDER + file;
Console.Write(File.Exists(fileE));
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.Create));
document.Open();
PdfContentByte contentByte = writer.DirectContent;
Rectangle rect = document.PageSize;
PdfPTable table = new PdfPTable(4);
table.TotalWidth = rect.Right - rect.Left + 1;
table.LockedWidth = true;
float[] widths = new float[] {
0.1f, 0.54f, 0.12f, 0.25f
};
table.SetWidths(widths);
PdfPCell cell_1_1 = new PdfPCell(new Phrase("1-1"));
cell_1_1.Colspan = 4;
table.AddCell(cell_1_1);
PdfPCell cell_2_1 = new PdfPCell(new Phrase("2-1"));
cell_2_1.Rowspan = 2;
table.AddCell(cell_2_1);
PdfPCell cell_2_2 = new PdfPCell(new Phrase("2-2"));
cell_2_2.Colspan = 2;
table.AddCell(cell_2_2);
PdfPCell cell_2_4 = new PdfPCell(new Phrase("2-4"));
cell_2_4.Rowspan = 3;
table.AddCell(cell_2_4);
PdfPCell cell_3_2 = new PdfPCell(new Phrase("3-2"));
table.AddCell(cell_3_2);
PdfPCell cell_3_3 = new PdfPCell(new Phrase("3-3"));
table.AddCell(cell_3_3);
PdfPCell cell_4_1 = new PdfPCell(new Phrase("4-1"));
cell_4_1.Colspan = 3;
table.AddCell(cell_4_1);
table.WriteSelectedRows(0, -1, rect.Left, rect.Top, contentByte);
document.Close();
// compare
CompareTool compareTool = new CompareTool(OUTPUT_FOLDER + file, CMP_FOLDER + file);
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例9: CompareDocuments
private void CompareDocuments(String @out, String cmp, bool visuallyOnly) {
CompareTool compareTool = new CompareTool();
String errorMessage;
if (visuallyOnly) {
errorMessage = compareTool.Compare(outFolder + @out, cmpFolder + cmp, outFolder, "diff");
} else {
errorMessage = compareTool.CompareByContent(outFolder + @out, cmpFolder + cmp, outFolder, "diff");
}
if (errorMessage != null)
Assert.Fail(errorMessage);
}
示例10: CompareToolErrorReportTest02
public void CompareToolErrorReportTest02() {
CompareTool compareTool = new CompareTool();
compareTool.SetCompareByContentErrorsLimit(10);
compareTool.SetGenerateCompareByContentXmlReport(true);
compareTool.SetXmlReportName("report02");
String outPdf = TEST_RESOURCES_PATH + "tagged_pdf.pdf";
String cmpPdf = TEST_RESOURCES_PATH + "cmp_tagged_pdf.pdf";
String result = compareTool.CompareByContent(outPdf, cmpPdf, OUT_FOLDER, "difference");
Assert.NotNull("CompareTool must return differences found between the files",result);
Assert.IsTrue(CompareXmls(TEST_RESOURCES_PATH + "cmp_report02.xml", OUT_FOLDER + "report02.xml"), "CompareTool report differs from the reference one");
Console.WriteLine(result);
}
示例11: Test2
public void Test2() {
CompareTool compareTool = new CompareTool();
compareTool.SetCompareByContentErrorsLimit(10);
compareTool.SetGenerateCompareByContentXmlReport(true);
String outPdf = TEST_RESOURCES_PATH + "tagged_pdf.pdf";
String cmpPdf = TEST_RESOURCES_PATH + "cmp_tagged_pdf.pdf";
String result = compareTool.CompareByContent(outPdf, cmpPdf, OUT_FOLDER, "difference");
Assert.NotNull(result);
Console.WriteLine(result);
}
示例12: VisibleTopChoiceHelper
private void VisibleTopChoiceHelper(int topVisible, int expected, String file) {
Document document = new Document();
FileStream fos = new FileStream(OUTPUT_FOLDER + file, FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(document, fos);
document.Open();
TextField textField = new TextField(writer, new Rectangle(380, 560, 500, 610), "testListBox");
textField.Visibility = BaseField.VISIBLE;
textField.Rotation = 0;
textField.FontSize = 14f;
textField.TextColor = BaseColor.MAGENTA;
textField.BorderColor = BaseColor.BLACK;
textField.BorderStyle = PdfBorderDictionary.STYLE_SOLID;
textField.Font = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
textField.BorderWidth = BaseField.BORDER_WIDTH_THIN;
writer.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
textField.Choices = new String[] {"one", "two", "three"};
textField.ChoiceExports = new String[] {"1", "2", "3"};
//choose the second item
textField.ChoiceSelection = 1;
//set the first item as the visible one
textField.VisibleTopChoice = topVisible;
Assert.AreEqual(expected, textField.VisibleTopChoice);
PdfFormField field = textField.GetListField();
writer.AddAnnotation(field);
document.Close();
// compare
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, CMP_FOLDER + file, OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例13: AddNavigationTest
public void AddNavigationTest() {
String src = srcFolder + "primes.pdf";
String dest = outFolder + "primes_links.pdf";
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
PdfDestination d = new PdfDestination(PdfDestination.FIT);
Rectangle rect = new Rectangle(0, 806, 595, 842);
PdfAnnotation a10 = PdfAnnotation.CreateLink(stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_INVERT, 2, d);
stamper.AddAnnotation(a10, 1);
PdfAnnotation a1 = PdfAnnotation.CreateLink(stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_PUSH, 1, d);
stamper.AddAnnotation(a1, 2);
stamper.Close();
CompareTool compareTool = new CompareTool();
String errorMessage = compareTool.CompareByContent(dest, srcFolder + "cmp_primes_links.pdf", outFolder, "diff_");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例14: ImageTaggingExpansionTest
public void ImageTaggingExpansionTest() {
String filename = "TextExpansionTest.pdf";
Document doc = new Document(PageSize.LETTER, 72, 72, 72, 72);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(DEST_FOLDER + filename, FileMode.Create));
writer.SetTagged();
doc.Open();
Chunk c1 = new Chunk("ABC");
c1.SetTextExpansion("the alphabet");
Paragraph p1 = new Paragraph();
p1.Add(c1);
doc.Add(p1);
PdfTemplate t = writer.DirectContent.CreateTemplate(6, 6);
t.SetLineWidth(1f);
t.Circle(3f, 3f, 1.5f);
t.SetGrayFill(0);
t.FillStroke();
Image i = Image.GetInstance(t);
Chunk c2 = new Chunk(i, 100, -100);
doc.Add(c2);
Chunk c3 = new Chunk("foobar");
c3.SetTextExpansion("bar bar bar");
Paragraph p3 = new Paragraph();
p3.Add(c3);
doc.Add(p3);
doc.Close();
CompareTool compareTool = new CompareTool();
String error = compareTool.CompareByContent(DEST_FOLDER + filename, SOURCE_FOLDER + "cmp_" + filename, DEST_FOLDER, "diff_");
if (error != null) {
Assert.Fail(error);
}
}
示例15: SetPageContentTest02
public void SetPageContentTest02() {
String outPdf = DestFolder + "out2.pdf";
PdfReader reader = new PdfReader(TestResourceUtils.GetResourceAsStream(TestResourcesPath, "in.pdf"));
PdfStamper stamper = new PdfStamper(reader, new FileStream(outPdf, FileMode.Create));
int total = reader.NumberOfPages + 1;
for (int i = 1; i < total; i++) {
byte[] bb = reader.GetPageContent(i);
reader.SetPageContent(i, bb);
}
reader.RemoveUnusedObjects();
stamper.Close();
String s = new CompareTool().CompareByContent(outPdf, TestResourceUtils.GetResourceAsTempFile(TestResourcesPath, "cmp_out2.pdf"), DestFolder, "diff_");
Assert.Null(s);
}