PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Copy and resize document and fit it into box
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3821
Page 1 of 1

Author:  boba21 [ Tue Aug 07, 2018 1:36 am ]
Post subject:  Copy and resize document and fit it into box

Hi, I'm using PDFSharp to create PDF.
Now I trying to copy other document/image (PDF format with A3 size) and paste it in the box (x,y) in the new document (A4 size).
In the new document, there will be have image details box and image box.
So, how do I copy the image from other PDF into the image box in the new document?

I also attach the sample I need to create using PDFSharp.

Thanks.

Attachments:
Capture.PNG
Capture.PNG [ 123.91 KiB | Viewed 13862 times ]

Author:  TH-Soft [ Tue Aug 07, 2018 5:38 am ]
Post subject:  Re: Copy and resize document and fit it into box

Hi!

You can draw pages from other PDF files like you draw images - draw them anywhere at any angle and any size.
You may have to do some calculations to maintain the aspect ratio.

See the Two Pages on One sample:
http://pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx
Lines 40 and 54 draw PDF pages. Check the lines above for prerequisites.

Author:  boba21 [ Tue Aug 07, 2018 8:34 am ]
Post subject:  Re: Copy and resize document and fit it into box

TH-Soft wrote:
Hi!

You can draw pages from other PDF files like you draw images - draw them anywhere at any angle and any size.
You may have to do some calculations to maintain the aspect ratio.

See the Two Pages on One sample:
http://pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx
Lines 40 and 54 draw PDF pages. Check the lines above for prerequisites.


Thanks for reply.

Now I'm stuck at Line 21
Code:
XPdfForm form = XPdfForm.FromFile(filename);


I got below error.
Code:
ArgumentException: The specified file has no valid PDF file header.
Parameter name: path


I already check the pdf, it not set as read-only files. Even I follow straight away, copy the file and remove Read-Only attr, but still got the error.
It should be okay to read the files. :?:

Here below is my code:
Code:
var filename = "sample.pdf";
var file = Path.Combine(Directory.GetCurrentDirectory(), filename);
File.Copy(Path.Combine("../MyPDFSourceFolder/", filename), file, true);

File.SetAttributes(file, File.GetAttributes(file) & ~FileAttributes.ReadOnly);

var form = XPdfForm.FromFile(file);

Author:  Thomas Hoevel [ Tue Aug 07, 2018 8:44 am ]
Post subject:  Re: Copy and resize document and fit it into box

Hi!

PDF files start with a header like "%PDF-1.4%". These should be the first bytes in the file. It seems your file does not have this header.

Author:  boba21 [ Tue Aug 07, 2018 8:57 am ]
Post subject:  Re: Copy and resize document and fit it into box

Thomas Hoevel wrote:
Hi!

PDF files start with a header like "%PDF-1.4%". These should be the first bytes in the file. It seems your file does not have this header.


Is it related to pdf version? I already check my pdf, it got %PDF-1.3.% but got those error.

Even I try other pdf got from ADOBE site, still got this error - %PDF-1.4.%.
https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf

Author:  boba21 [ Wed Aug 08, 2018 2:40 am ]
Post subject:  Error when open the external document as XPdfForm object

Hi, I trying to follow below example to draw pdf to new pdf.
http://pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

But got this error:
Code:
ArgumentException: The specified file has no valid PDF file header.
Parameter name: path


At line 21 when call below code
Code:
XPdfForm form = XPdfForm.FromFile(filename);


I already check, my pdf is valid. Got %PDF-1.3.% in the header.
Even I try other pdf with %PDF-1.4.% header from Adobe (https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf)
but still got those error. Can anyone help me. Thanks

Author:  TH-Soft [ Wed Aug 08, 2018 5:32 am ]
Post subject:  Re: Error when open the external document as XPdfForm object

Hi!

If you think there is a bug with PDFsharp, please use the IssueSubmissionTemplate to make it replicable.
See also:
viewtopic.php?f=2&t=832

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/