«PDFsharp не может обработать эту функцию PDF, появившуюся в Acrobat 6», при открытии файла PDF

jQuery CROSS BROWSER CUSTOM PLUGIN - $ .footerBottom ()

Или используйте jQuery, как я, и установите высоту нижнего колонтитула auto или fix, что бы вы ни хотели, он будет работать так или иначе. этот плагин использует селектор jQuery, поэтому для его работы вам нужно будет включить библиотеку jQuery в ваш файл.

Вот как вы запускаете плагин. Импортируйте jQuery, скопируйте код этого настраиваемого плагина jQuery и импортируйте его после импорта jQuery! Это очень простой и простой, но важный.

Когда вы это сделаете, все, что вам нужно сделать, это запустить этот код:

$.footerBottom({target:"footer"}); //as html5 tag <footer>.
// You can change it to your preferred "div" with for example class "footer" 
// by setting target to {target:"div.footer"}

нет необходимости размещать его внутри события готовности документа. Он будет работать хорошо, как есть. Он пересчитает положение вашего нижнего колонтитула при загрузке страницы и при изменении размера окна.

Вот код плагина, который вам не нужно понимать. Просто знайте, как его реализовать. Это делает для вас работу. Однако, если вам нравится знать, как это работает, просто просмотрите код. Я оставлял комментарии для вас.

//import jQuery library before this script

// Import jQuery library before this script

// Our custom jQuery Plugin
(function($) {
  $.footerBottom = function(options) { // Or use "$.fn.footerBottom" or "$.footerBottom" to call it globally directly from $.footerBottom();
    var defaults = {
      target: "footer",
      container: "html",
      innercontainer: "body",
      css: {
        footer: {
          position: "absolute",
          left: 0,
          bottom: 0,
        },

        html: {
          position: "relative",
          minHeight: "100%"
        }
      }
    };

    options = $.extend(defaults, options);

    // JUST SET SOME CSS DEFINED IN THE DEFAULTS SETTINGS ABOVE
    $(options.target).css({
      "position": options.css.footer.position,
      "left": options.css.footer.left,
      "bottom": options.css.footer.bottom,
    });

    $(options.container).css({
      "position": options.css.html.position,
      "min-height": options.css.html.minHeight,
    });

    function logic() {
      var footerOuterHeight = $(options.target).outerHeight(); // Get outer footer height
      $(options.innercontainer).css('padding-bottom', footerOuterHeight + "px"); // Set padding equal to footer height on body element
      $(options.target).css('height', footerOuterHeight + "!important"); // Set outerHeight of footer element to ... footer
      console.log("jQ custom plugin footerBottom runs"); // Display text in console so ou can check that it works in your browser. Delete it if you like.
    };

    // DEFINE WHEN TO RUN FUNCTION
    $(window).on('load resize', function() { // Run on page loaded and on window resized
      logic();
    });

    // RETURN OBJECT FOR CHAINING IF NEEDED - IF NOT DELETE
    // return this.each(function() {
    //   this.checked = true;
    // });
    // return this;
  };
})(jQuery); // End of plugin


// USE EXAMPLE
$.footerBottom(); // Run our plugin with all default settings for HTML5
/* Set your footer CSS to what ever you like it will work anyway */
footer {
  box-sizing: border-box;
  height: auto;
  width: 100%;
  padding: 30px 0;
  background-color: black;
  color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!-- The structure doesn't matter much, you will always have html and body tag, so just make sure to point to your footer as needed if you use html5, as it should just do nothing run plugin with no settings it will work by default with the <footer> html5 tag -->
<body>
  <div class="content">
  <header>
    <nav>
      <ul>
        <li>link</li>
        <li>link</li>
        <li>link</li>
        <li>link</li>
        <li>link</li>
        <li>link</li>
      </ul>
    </nav>
  </header>

  <section>
      <p></p>
      <p>Lorem ipsum...</p>
    </section>
  </div>
  <footer>
    <p>Copyright 2009 Your name</p>
    <p>Copyright 2009 Your name</p>
    <p>Copyright 2009 Your name</p>
  </footer>

17
задан Vive la déraison 22 April 2016 в 13:30
поделиться

2 ответа

28
ответ дан Vive la déraison 22 April 2016 в 13:30
поделиться

Вы можете использовать iText5 или iText7 для удаления потоков iref.

Блок iText5 ниже взят из http://forum.pdfsharp.net/viewtopic.php?f=2&t=693

static public PdfDocument Open(MemoryStream sourceStream)
  {
     PdfDocument outDoc = null;
     sourceStream.Position = 0;

     try
     {
        outDoc = PdfReader.Open(sourceStream, PdfDocumentOpenMode.Import);
     }
     catch (PdfSharp.Pdf.IO.PdfReaderException)
     {
        //workaround if pdfsharp doesn't support this pdf
        sourceStream.Position = 0;
        MemoryStream outputStream = new MemoryStream();
        iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(sourceStream);
        iTextSharp.text.pdf.PdfStamper pdfStamper = new iTextSharp.text.pdf.PdfStamper(reader, outputStream);
        pdfStamper.FormFlattening = true;
        pdfStamper.Writer.SetPdfVersion(iTextSharp.text.pdf.PdfWriter.PDF_VERSION_1_4);
        pdfStamper.Writer.CloseStream = false;
        pdfStamper.Close();

        outDoc = PdfReader.Open(outputStream, PdfDocumentOpenMode.Import);
     }

     return outDoc;
  }

У меня был переписать его для iText7 (все еще используя старый PDFSharp):

static PdfDocument CompatibleOpen(MemoryStream inputStream, PdfDocumentOpenMode openMode)
{
 PdfDocument pdfDocument = null;
 inputStream.Position = 0;

 try
 {
    pdfDocument = PdfReader.Open(inputStream, openMode);
 }
 catch (PdfSharp.Pdf.IO.PdfReaderException)
 {
    inputStream.Position = 0;
    MemoryStream outputStream = new MemoryStream();

    iText.Kernel.Pdf.WriterProperties writerProperties = new iText.Kernel.Pdf.WriterProperties();
    writerProperties.SetPdfVersion(iText.Kernel.Pdf.PdfVersion.PDF_1_4);

    iText.Kernel.Pdf.PdfReader pdfReader = new iText.Kernel.Pdf.PdfReader(inputStream);

    iText.Kernel.Pdf.PdfDocument pdfStamper = new iText.Kernel.Pdf.PdfDocument(pdfReader, new iText.Kernel.Pdf.PdfWriter(outputStream, writerProperties)); 

    iText.Forms.PdfAcroForm pdfForm = iText.Forms.PdfAcroForm.GetAcroForm(pdfStamper, true);
    if (!pdfForm.IsNull())
    {
       pdfForm.FlattenFields();
    }
    writerProperties.SetFullCompressionMode(false);

    pdfStamper.GetWriter().SetCloseStream(false);           
    pdfStamper.Close();

    pdfDocument = PdfReader.Open(outputStream, openMode);
 }
 return pdfDocument;
}

Я надеюсь, что это поможет кому-то пережить ту же боль, с которой я был, и сэкономит им несколько дней !!!

3
ответ дан knitTheCode 22 April 2016 в 13:30
поделиться
Другие вопросы по тегам:

Похожие вопросы: