Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using foxit;
- using foxit.common;
- using foxit.common.fxcrt;
- using foxit.pdf;
- using foxit.pdf.annots;
- using foxit.addon;
- ...
- using (PDFDoc base_doc = new PDFDoc("input_base_file"))
- {
- error_code = base_doc.Load(null);
- if (error_code != ErrorCode.e_ErrSuccess)
- {
- Library.Release();
- return;
- }
- using (PDFDoc compared_doc = new PDFDoc("input_compared_file"))
- {
- error_code = compared_doc.Load(null);
- if (error_code != ErrorCode.e_ErrSuccess)
- {
- Library.Release();
- return;
- }
- using (Comparison comparison = new Comparison(base_doc, compared_doc))
- {
- // Start comparing.
- CompareResults result = comparison.DoCompare(0, 0, (int)Comparison.CompareType.e_CompareTypeText);
- CompareResultInfoArray oldInfo = result.results_base_doc;
- CompareResultInfoArray newInfo = result.results_compared_doc;
- uint oldInfoSize = oldInfo.GetSize();
- uint newInfoSize = newInfo.GetSize();
- using (PDFPage page = compared_doc.GetPage(0))
- {
- for (uint i = 0; i < newInfoSize; i++)
- {
- CompareResultInfo item = newInfo.GetAt(i);
- CompareResultInfo.CompareResultType type = item.type;
- if (type == CompareResultInfo.CompareResultType.e_CompareResultTypeDeleteText)
- {
- String res_string = String.Format(""{0}"", item.diff_contents);
- // Add stamp to mark the "delete" type differences between the two documents.
- CreateDeleteTextStamp(page, item.rect_array, 0xff0000, res_string, "Compare : Delete", "Text");
- }
- else if (type == CompareResultInfo.CompareResultType.e_CompareResultTypeInsertText)
- {
- String res_string = String.Format(""{0}"", item.diff_contents);
- // Highlight the "insert" type differences between the two documents.
- CreateHighlightRect(page, item.rect_array, 0x0000ff, res_string, "Compare : Insert", "Text");
- }
- else if (type == CompareResultInfo.CompareResultType.e_CompareResultTypeReplaceText)
- {
- String res_string = String.Format("[Old]: "{0}"rn[New]: "{1}"", oldInfo.GetAt(i).diff_contents, item.diff_contents);
- // Highlight the "replace" type differences between the two documents.
- CreateHighlightRect(page, item.rect_array, 0xe7651a, res_string, "Compare : Replace", "Text");
- }
- }
- }
- // Save the comparison result to a PDF file.
- compared_doc.SaveAs(output_path + "result.pdf", (int)PDFDoc.SaveFlags.e_SaveFlagNormal);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement