Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README needs reorganization/transference to doco repository #11

Open
dwarring opened this issue Jan 22, 2021 · 9 comments
Open

README needs reorganization/transference to doco repository #11

dwarring opened this issue Jan 22, 2021 · 9 comments
Assignees

Comments

@dwarring
Copy link
Contributor

This was created before https://github.com/pdf-raku/pdf-raku.github.io can into existence and has continued to grow and become a defacto documentation point for the rest of the tool-chain.

Initial problem is that it's in the wrong place. At some point the bulk of it should be moved to the doco repository and the README slimmed down to refer to it.

@dwarring dwarring self-assigned this Jan 22, 2021
@hectormonacci
Copy link

hectormonacci commented Jul 24, 2022

The code example just after https://github.com/pdf-raku/PDF-API6/blob/master/README.md#to-xobject is intended to show how to copy and transform pages from $old to $pdf, but it fails to use $old after opening it.

I tried changing my PDF::XObject $xo = $pdf.page(2).to-xobject; to my PDF::XObject $xo = $old.page(2).to-xobject; but after this change the example won't run under rakudo v2022.06.

@dwarring
Copy link
Contributor Author

@hectormonacci I fixed the to-xobject example as above. I was able to run it on 2020.06. What issues are you having?

@hectormonacci
Copy link

Thank you. Here's more info:

raku -v:
Welcome to Rakudo™ v2022.06.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2022.06.

raku sample.raku (contains the example with minimal adaptations, and is applied to a valid v1.5 PDF input file):

indirect reference without associated reader: 3 0 R
in method deref at /usr/lib/raku/site/sources/3BAE5B323236C0357B33115CDCDF3E54C11BBF2F (PDF::COS::Tie) line 252
in method AT-KEY at /usr/lib/raku/site/sources/4643BF545A394ED914BE56449B35DE1B11718B4C (PDF::COS::Tie::Hash) line 73
in method AT-KEY at /usr/lib/raku/site/sources/4643BF545A394ED914BE56449B35DE1B11718B4C (PDF::COS::Tie::Hash) line 71
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 20
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 20
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 20
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 20
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 20
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 27
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 20
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 20
in method ref-count at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 20
in method body at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 67
in method ast at /usr/lib/raku/site/sources/C3530A88CEE9B5F532C720CDF215667E67FE53CA (PDF::IO::Serializer) line 259
in method ast at /usr/lib/raku/site/sources/7418831955D69E9D1DF9DB769436C4CEFCD8A0C7 (PDF) line 191
in method ast-writer at /usr/lib/raku/site/sources/7418831955D69E9D1DF9DB769436C4CEFCD8A0C7 (PDF) line 196
in method save-as at /usr/lib/raku/site/sources/7418831955D69E9D1DF9DB769436C4CEFCD8A0C7 (PDF) line 232
in method save-as at /usr/lib/raku/site/sources/F51B91A5DBC668E9092938CAB20E1AD2D8E61375 (PDF::Class) line 57
in block <unit> at sample.raku line 45

@dwarring
Copy link
Contributor Author

That's on line 45, but my code sample only has 19 lines. Can you please show the actual code? It would also be helpful to attach a sample PDF, if you are able.

@hectormonacci
Copy link

Sure thing!

1. My code:

#!/usr/bin/env raku

# use PDF::API6;
# use PDF::Page;
# use PDF::XObject;
# use PDF::Content;
# use PDF::Content::Page :PageSizes;

# my PDF::API6 $old .= open('1842-gogol-capote.pdf');
# my PDF::API6 $pdf .= new;
# my PDF::Page $page = $pdf.add-page();
# my PDF::Content $gfx = $page.gfx;

# # Import Page 2 from the old PDF
# my PDF::XObject $xo = $pdf.page(1).to-xobject;

# # Add it to the new PDF's first page at 1/2 scale
# my $width = $xo.width / 2;
# my $bottom = 5;
# my $left = 10;
# $gfx.do($xo, :position[$bottom, $left], :$width);

# $pdf.media-box = A4;
# $pdf.save-as('1842-gogol-capote-raku.pdf');


use PDF::API6;
use PDF::Page;
use PDF::XObject;
use PDF::Content;
my PDF::API6 $old .= open('1842-gogol-capote.pdf');
my PDF::API6 $pdf .= new;
my PDF::Page $page = $pdf.add-page;
my PDF::Content $gfx = $page.gfx;

# Import first page from the old PDF
my PDF::XObject $xo = $old.page(1).to-xobject;

# Add it to the new PDF's first page at 1/2 scale
my $width = $xo.width / 2;
my $bottom = 5;
my $left = 10;
$gfx.do($xo, :position[$bottom, $left], :$width);

$pdf.save-as('new.pdf');

2. The PDF file to be used as source:

1842-gogol-capote.pdf

@dwarring
Copy link
Contributor Author

Thanks, I can replicate the issue.

That is very close to the example, apologies.

I'm thinking it must be somehow PDF-specific. Will investigate.

@dwarring
Copy link
Contributor Author

I fixed a bug in PDF::Content::Page which implements the to-xobject method, which wasn't building the xobjects's resources correctly.

@hectormonacci could you please upgrade to PDF::Content 0.6.6 and try again.

@hectormonacci
Copy link

Great job @dwarring ! I upgraded to PDF::Content 0.6.6 and now it works. Thanks a lot!

@hectormonacci
Copy link

By the way, I think another change would be needed on the same example.

:position[$bottom, $left]

should be changed to:

:position[$left, $bottom]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants