小编Mas*_*ius的帖子

编辑iTextSharp PdfSmartCopy类的DirectContent

在我的工作中,有时我必须合并几个到几百个pdf文件.我一直在使用WriterImportedPages上课.但是当我将所有文件合并为一个文件时,文件大小变得庞大,所有合并文件大小的总和,因为字体附加到每个页面,而不是重复使用(字体嵌入到每个页面,而不是整个文档).

不久前我发现了PdfSmartCopy类,它重用了嵌入的字体和图像.在这里,问题就出现了.很多时候,在将文件合并到一起之前,我必须为它们添加额外的内容(图像,文本).为此我通常使用PdfContentByteWriter对象.

Document doc = new Document();    
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("C:\test.pdf", FileMode.Create));
PdfContentByte cb = writer.DirectContent;
cb.Rectangle(100, 100, 100, 100);
cb.SetColorStroke(BaseColor.RED);
cb.SetColorFill(BaseColor.RED);
cb.FillStroke();
Run Code Online (Sandbox Code Playgroud)

当我对PdfSmartCopy对象执行类似的操作时,会合并页面,但不会添加其他内容.我的测试的完整代码PdfSmartCopy:

using (Document doc = new Document())
        {
            using (PdfSmartCopy copy = new PdfSmartCopy(doc, new FileStream(Path.GetDirectoryName(pdfPath[0]) + "\\testas.pdf", FileMode.Create)))
            {
                doc.Open();
                PdfContentByte cb = copy.DirectContent;
                for (int i = 0; i < pdfPath.Length; i++)
                {
                    PdfReader reader = new PdfReader(pdfPath[i]);
                    for …
Run Code Online (Sandbox Code Playgroud)

c# java merge itext itextsharp

5
推荐指数
2
解决办法
8490
查看次数

自定义异常和基础构造函数

我一直在尝试编写自己的自定义构造函数,但是获取有关base()构造函数的错误.我一直在寻找如何解决这个错误,但没有发现任何内容,互联网上的所有示例都显示与我的几乎相同的代码.

Whole Exception.cs内容:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace RegisService
{
public class Exceptions : Exception
{        
}

  public class ProccessIsNotStarted : Exceptions
  {
      ProccessIsNotStarted()
          : base()
      {
          //var message = "Formavimo procesas nestartuotas";
          //base(message);
      }

      ProccessIsNotStarted(string message) 
          : base(message) {}

      ProccessIsNotStarted(string message, Exception e)
          : base(message, e) {}
  }
}
Run Code Online (Sandbox Code Playgroud)

第一次重载base()正在工作,没有抛出任何错误.第二次和第三次重载告诉我:

"RegisService.Exceptions不包含带有1(2)个参数的构造函数"

我试图解决错误的另一种方法:

ProccessIsNotStarted(string message)              
    {
        base(message);
    }

    ProccessIsNotStarted(string message, Exception e)
    {
        base(message, e);
    }
Run Code Online (Sandbox Code Playgroud)

这一次,VS告诉我:

"使用关键字'base'在此上下文中无效"

那么,问题出在哪里?看起来base()构造函数有一些奇怪的重载或我以不恰当的方式调用它?

c# exception base custom-exceptions

3
推荐指数
1
解决办法
8983
查看次数

标签 统计

c# ×2

base ×1

custom-exceptions ×1

exception ×1

itext ×1

itextsharp ×1

java ×1

merge ×1