Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Oct 24, 2023 10:07 am

We currently have a problem with generated PDF files that are printed directly from SAP by our customers.

The PDF files can be opened in various viewers and also printed on the corresponding printer.

However, if the file is sent directly from SAP to the print spooler, it cannot be processed.

We have therefore carried out a simple test:
- The data as we process it (attached as files named 'InvoiceFromSihot')
- - this will lead into Screnshot from attached named 'InvoiceFromSihot_Error1' and an additional one 'InvoiceFromSihot_Error2'
--- we convert here a RTF to PDF
Code: Select all
 Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(Resources.license_elic));
 Spire.License.LicenseProvider.SetLicenseFileStream(stream);

 ExportOptions opts = ExportOptions.Parse(exportOptions);
 PdfDocument pdf = new PdfDocument(input);

 AddMetaData(ref pdf, opts);

 if (opts.HasEInvoice)
 {
     AddDigitalInvoice(ref pdf, opts);
 }

 MemoryStream pdfStream = new MemoryStream();

 pdf.SaveToStream(pdfStream, FileFormat.PDF);
 pdf.Dispose();

 if (opts.HasEInvoice)
 {
     var trimmedPdfStream = new MemoryStream(RemoveEOF(pdfStream));
     new PdfStandardsConverter(trimmedPdfStream).ToPdfA3A(pdfStream);
     return trimmedPdfStream.ToArray();
 }
 else
 {
     return RemoveEOF(pdfStream);
 }

Code: Select all
        public byte[] RemoveEOF(MemoryStream finalPdfStream)
        {
            byte[] pdfBytes = finalPdfStream.GetBuffer();

            int eofPos = -1;
            for (int i = pdfBytes.Length - 1; i >= 0; i--)
            {
                if (pdfBytes[i] != 0)
                {
                    eofPos = i;
                    break;
                }
            }

            byte[] adjustedPdf = new byte[eofPos + 1];
            Array.Copy(pdfBytes, adjustedPdf, eofPos + 1);

            return adjustedPdf;
        }


- A very simple PDF with text only created in Spire.PDF (attached as files named 'Spire.PDF')
-- works fine
--- used code for PDF
Code: Select all
                PdfDocument doc = new();
                // Meta data
                doc.DocumentInformation.Creator = "SIHOT";
                doc.DocumentInformation.Title = "SIHOT Test PDF";
                // Page settings, reset the default margins to 0
                doc.PageSettings.Size = PdfPageSize.A4;
                doc.PageSettings.Margins = new(0);

                //create a PdfMargins object, the parameters indicate the page margins you want to set
                PdfMargins margins = new(60, 0, 0, 60);

                // Create a templates with content and apply it to page template
                //doc.Template.Top = CreateHeaderTemplate(doc, margins);
                //doc.Template.Bottom = CreateFooterTemplate(doc, margins);

                // Apply blank templates to other parts of page template
                doc.Template.Left = new PdfPageTemplateElement(margins.Left, doc.PageSettings.Size.Height);
                doc.Template.Right = new PdfPageTemplateElement(margins.Right, doc.PageSettings.Size.Height);

                PdfPageBase page = doc.Pages.Add();

                PdfTrueTypeFont fontAssesmentName = new(@"C:\Windows\Fonts\Arial.ttf", 20f);
                page.Canvas.DrawString("Test PDF created by Spire.Pdf only", fontAssesmentName, PdfBrushes.Black, 50, page.Size.Height * 0.4f, new PdfStringFormat(PdfTextAlignment.Left));

                MemoryStream outstream = new();


                doc.SaveToStream(outstream, FileFormat.PDF);
                doc.Close();


Does anyone have an idea what we are doing wrong here or what we need to change so that SAP can also process the file directly?

T.Kohl_Gubse
 
Posts: 2
Joined: Tue Oct 24, 2023 7:31 am

Wed Oct 25, 2023 8:27 am

Hi,

Thank you for your inquiry.
I used the software Adobe Acrobat DC to open the file (InvoiceFromSihot. pdf) you provided and print it without any issues. Therefore, your issue may caused by SAP, I strongly advise that you can also try contacting SAP's ssupport team to inquire about the possible cause of this error and seek their help. In addition, our product Spire.PDF doesn't include the function to convert RTF to PDF. How do you achieve RTF to PDF conversion? Have you processed the PDF you generated again using the code you provided, and then printed it using SAP and threw an exception? If so, is there a issue of printing PDF converted from RTF directly using SAP? If there no issue exist, please provide us with the following information to assist us in further investigation. You can attach the information here or send it to us via email( support@e-iceblue.com) .Thank you in advance.
1) Your original RTF file.
2) Complete test code that can reproduce the problem.
3) Application type, such as console application NET Framework 4.8.

Sincerely
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Thu Oct 26, 2023 6:19 am

Thank you very much for the feedback.
We have spoken to the customer and people from SAP about this error and here we get the already announced error message, which is printed out.

We use Telerik to convert RTF to PDF, this was used before we started using Spire.PDF and SAP was able to use it without any problems.
With a software update and the support of e-billing, we decided to use Spire.PDF to meet the requirements for PDF files.
We convert the RTF to PDF using Telerik as before and then convert again using Spire.PDF.


It uses .net 4.6.1 and is included as a .dll in our main application.

RTF is available as an attachment. ('20001540_02.rtf')

More tests have now been prepared, we are still waiting for the results:

- RTF conversion using Telerik only (attached as files named 'InvoiceFromSihotOnlyTelerik')
-- here it should be works as before, without using Spire.PDF


- RTF to PDF converting using Spire.Doc (attached as files named 'InvoiceFromSihotOnlySpireDoc')
-- here we check if it is an issue coming from Telerik


- RTF to PDF converting using Spire.Doc and then using converting with Spire.PDF (attached as files named 'InvoiceFromSihotSpireDocAndSpirePDF')
-- here we check if the second convert is causing the issue


I will check and ask internally if there is a possibility to submit a test code that can be used on your site.

T.Kohl_Gubse
 
Posts: 2
Joined: Tue Oct 24, 2023 7:31 am

Thu Oct 26, 2023 9:24 am

Hi,

Thank you for your feedback.
When I open your RTF file (20001540_02. RTF) through the software Microsoft Office 365 for Word, I received an error as shown in the following figure:
1.png

In addition, our product follow Microsoft's specifications, so you can test the pdf documents generated in the following two ways:
1) - RTF to PDF converting using Microsoft Word.
2) - RTF to PDF converting using Microsoft Word and then using converting with Spire.PDF

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.PDF