GithubHelp home page GithubHelp logo

Comments (17)

sagar-kalburgi-ripcord avatar sagar-kalburgi-ripcord commented on July 22, 2024 1

@sampila Sounds good. We can test against your PR and let you know if it works out for us. Thanks!

from unipdf.

sampila avatar sampila commented on July 22, 2024 1

Hi @sampila. I got access to your Org, however is it possible to add @rcosta-ripcord to your Org as well? he is actively testing these changes right now.

Regarding that, @rcosta-ripcord can fork from your forked repo, as currently we are giving the access to 1 member of organization only.

from unipdf.

rcosta-ripcord avatar rcosta-ripcord commented on July 22, 2024 1

Hi @sampila, @sagar-kalburgi-ripcord and I just tested your PR and it does fix our issue.
Please let us know once you merge and release it so we can update the dependency on our services!

Thank you for your help!

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @sagar-kalburgi-ripcord,

we tried to reproduce the issue, but when trying to merge the S19-1026-NLP-Tasks.pdf with this our sample pdf document-header-and-footer-simple, it's works fine.

Likely it's due your system doesn't have DejavuSans font installed.

Example Code

/*
 * Basic merging of PDF files.
 * Simply loads all pages for each file and writes to the output file.
 * See pdf_merge_advanced.go for a more advanced version which handles merging document forms (acro forms) also.
 *
 * Run as: go run pdf_merge.go output.pdf input1.pdf input2.pdf input3.pdf ...
 */

package main

import (
	"fmt"
	"os"

	"github.com/unidoc/unipdf/v3/common/license"
	"github.com/unidoc/unipdf/v3/model"
)

func init() {
	// Make sure to load your metered License API key prior to using the library.
	// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io
	err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
	if err != nil {
		panic(err)
	}
}

func main() {
	if len(os.Args) < 4 {
		fmt.Printf("Requires at least 3 arguments: output_path and 2 input paths\n")
		fmt.Printf("Usage: go run pdf_merge.go output.pdf input1.pdf input2.pdf input3.pdf ...\n")
		os.Exit(0)
	}

	outputPath := ""
	inputPaths := []string{}

	// Sanity check the input arguments.
	for i, arg := range os.Args {
		if i == 0 {
			continue
		} else if i == 1 {
			outputPath = arg
			continue
		}

		inputPaths = append(inputPaths, arg)
	}

	err := mergePdf(inputPaths, outputPath)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Complete, see output file: %s\n", outputPath)
}

func mergePdf(inputPaths []string, outputPath string) error {
	pdfWriter := model.NewPdfWriter()

	for _, inputPath := range inputPaths {
		pdfReader, f, err := model.NewPdfReaderFromFile(inputPath, nil)
		if err != nil {
			return err
		}
		defer f.Close()

		numPages, err := pdfReader.GetNumPages()
		if err != nil {
			return err
		}

		for i := 0; i < numPages; i++ {
			pageNum := i + 1

			page, err := pdfReader.GetPage(pageNum)
			if err != nil {
				return err
			}

			err = pdfWriter.AddPage(page)
			if err != nil {
				return err
			}
		}
	}

	fWrite, err := os.Create(outputPath)
	if err != nil {
		return err
	}

	defer fWrite.Close()

	err = pdfWriter.Write(fWrite)
	if err != nil {
		return err
	}

	return nil
}

Sample file

document-header-and-footer-simple.pdf

Command to run

go run main.go output.pdf document-header-and-footer-simple.pdf S19-1026-NLP-Tasks.pdf 

Output PDF

output.pdf

Could you try install the DejavuSans font and run the code?

from unipdf.

rcosta-ripcord avatar rcosta-ripcord commented on July 22, 2024

Hi @sampila,
First of all, thank you for providing suggestions and the sample code!

I've been working with @sagar-kalburgi-ripcord on this, and I tried installing the font, which didn't solve the issue on our service.

Using the code you provided, it does work, indeed.
However, we are trying to ensure PDF/A compatibility, and as such, I made a small change to your code. The same error persists after my changes, and I confirmed that the font was installed!

Given the above, I have a few questions:

  • Do you know if the PDF/A Profile has any limitations, or if there's any way to solve this issue?
  • Do you know if there are any other kind of requirements in terms of fonts that we need to ensure?
  • If DejavuSans in particular is the issue, can we specify or override the fallback fonts?

For reference, here's the code with the changes I mentioned:

/*
 * Basic merging of PDF files.
 * Simply loads all pages for each file and writes to the output file.
 * See pdf_merge_advanced.go for a more advanced version which handles merging document forms (acro forms) also.
 *
 * Run as: go run pdf_merge.go output.pdf input1.pdf input2.pdf input3.pdf ...
 */

package main

import (
	"fmt"
	"os"

	"github.com/unidoc/unipdf/v3/common/license"
	"github.com/unidoc/unipdf/v3/model"
	"github.com/unidoc/unipdf/v3/model/pdfa"
)

func init() {
	// Make sure to load your metered License API key prior to using the library.
	// If you need a key, you can sign up and create a free one at https://cloud.unidoc.io
	err := license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
	if err != nil {
		panic(err)
	}
}

func main() {
	if len(os.Args) < 4 {
		fmt.Printf("Requires at least 3 arguments: output_path and 2 input paths\n")
		fmt.Printf("Usage: go run pdf_merge.go output.pdf input1.pdf input2.pdf input3.pdf ...\n")
		os.Exit(0)
	}

	outputPath := ""
	inputPaths := []string{}

	// Sanity check the input arguments.
	for i, arg := range os.Args {
		if i == 0 {
			continue
		} else if i == 1 {
			outputPath = arg
			continue
		}

		inputPaths = append(inputPaths, arg)
	}

	err := mergePdf(inputPaths, outputPath)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Complete, see output file: %s\n", outputPath)
}

func mergePdf(inputPaths []string, outputPath string) error {
	pdfWriter := model.NewPdfWriter()
	
	// Apply PDF/A-1a Standard with default options
	pdfWriter.ApplyStandard(model.StandardApplier(pdfa.NewProfile1A(pdfa.DefaultProfile1Options())))

	for _, inputPath := range inputPaths {
		pdfReader, f, err := model.NewPdfReaderFromFile(inputPath, nil)
		if err != nil {
			return err
		}
		defer f.Close()

		numPages, err := pdfReader.GetNumPages()
		if err != nil {
			return err
		}

		for i := 0; i < numPages; i++ {
			pageNum := i + 1

			page, err := pdfReader.GetPage(pageNum)
			if err != nil {
				return err
			}

			err = pdfWriter.AddPage(page)
			if err != nil {
				return err
			}
		}
	}

	fWrite, err := os.Create(outputPath)
	if err != nil {
		return err
	}

	defer fWrite.Close()

	err = pdfWriter.Write(fWrite)
	if err != nil {
		return err
	}

	return nil
}

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @rcosta-ripcord thanks for providing more detail regarding this.

We investigate this issue.

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @rcosta-ripcord and @sagar-kalburgi-ripcord,

We are trying some experiment on PDF/A process, we tried to use standard font available when couldn't get the embedded font from PDF, here's the current results.

PDF Result

output1.pdf

What do you think, do the results acceptable and not affecting your current use case?

from unipdf.

rcosta-ripcord avatar rcosta-ripcord commented on July 22, 2024

Hi @sampila, would it be possible to show what the result would look like with the document @sagar-kalburgi-ripcord attached?
I'd also like to know if there's any PR available we can test with

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @sampila, would it be possible to show what the result would look like with the document @sagar-kalburgi-ripcord attached?
I'd also like to know if there's any PR available we can test with

Hi, the output1.pdf is from the S19-1026-NLP-Tasks.pdf

I will create PR for this specific issue.

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @sagar-kalburgi-ripcord and @rcosta-ripcord I created the PR and mentioned this issue on PR, could you check that?

from unipdf.

sagar-kalburgi-ripcord avatar sagar-kalburgi-ripcord commented on July 22, 2024

Hi @sampila we were unable to find any PR linked to this issue. Could you pls post a link to it here?

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @sampila we were unable to find any PR linked to this issue. Could you pls post a link to it here?

The PR can be accessed through ripcord account that has been added into unipdf source code repository, you can access the PR using that account.

from unipdf.

sagar-kalburgi-ripcord avatar sagar-kalburgi-ripcord commented on July 22, 2024

Hi @sampila, neither of us are able to find any PR although both of us are logged into our Ripcord account on Github

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @sagar-kalburgi-ripcord could you check again? you account should having access to the PR already.
You can fork that.

from unipdf.

sagar-kalburgi-ripcord avatar sagar-kalburgi-ripcord commented on July 22, 2024

Hi @sampila. I got access to your Org, however is it possible to add @rcosta-ripcord to your Org as well? he is actively testing these changes right now.

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @sampila, @sagar-kalburgi-ripcord and I just tested your PR and it does fix our issue. Please let us know once you merge and release it so we can update the dependency on our services!

Thank you for your help!

Hi @rcosta-ripcord, thanks for confirmation, we are adding this issue into our test cases and preparing new UniPDF release.
Will notify you after the release

from unipdf.

sampila avatar sampila commented on July 22, 2024

Hi @sagar-kalburgi-ripcord and @rcosta-ripcord,

We released new UniPDF version to fix this issue https://github.com/unidoc/unipdf/releases/tag/v3.56.0

We are closing this issue for now and you can re-open the issue if at latest version not resolve this issue.

Best regards,
Alip

from unipdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.