Merge 2 PDF into 1 Asp.net MVC

Asked

Viewed 37 times

0

I have 2 pdfs files and want to join the 2 in one file only, my method is as follows:

public async Task<FileResult> Teste(int id)
        {
            var objRelatorioTecnicoData = RetornoTecnicoAssinanteDataById(id);

            var modelPdf = MapperService.MapAsync<IncluirRelatorioTecnicoPdf>(objRelatorioTecnicoData).Result;
            await PreencherUfsMunicipiosPdf(modelPdf);
            GerarUfsMunicipios(modelPdf);
            GerarTecnicoUser(modelPdf);
            modelPdf.TemAutoTermo = modelPdf.AutoTermos.Count > 0;
            modelPdf.DataPublicacao = objRelatorioTecnicoData.DataPublicacao.ToShortDateString();

            const string contentType = "application/pdf";
            byte[] fileBytes = GerarPdf(objRelatorioTecnicoData, modelPdf);
            var numRelatorio = string.Empty;
            var length = fileBytes.Length;
            Array.Resize(ref fileBytes, fileBytes.Length + objRelatorioTecnicoData.DoctArquivo.Length);
            for(int i = 0; i< objRelatorioTecnicoData.DoctArquivo.Length; i++)
            {
                var count = (length + i);
                fileBytes[count] = objRelatorioTecnicoData.DoctArquivo[i];
            }

            if (objRelatorioTecnicoData != null)
            {
                numRelatorio = objRelatorioTecnicoData.NumeroRelatorio;
            }
            return File(fileBytes, contentType, "Relatoriotecnico_" + numRelatorio + ".pdf");
        }

However he prints only the 2nd pdf, I’ve done it in several ways and I couldn’t put the 2 together, someone has some solution to help me?

Thanks in advance.

  • in this code has no information about combining two pdfs, explains better by kindness

  • has, the first is p fileBytes, the second is the objRelatorioTecnicoData.Doctarfile, the filebytes generates the first pdf correctly, the objRelatorioTecnicoData.Doctarfile generates the second pdf correctly, but I cannot join the 2.

  • already tried to start at last, I put filebytes,length, but error.

  • guy I guess you can’t just combine the bytes, try to see some lib like itextsharp

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.